From c08be41136b8103800da0dc9994c26ce5e24bcfb Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 10:34:35 +0200 Subject: [PATCH 1/8] fix pre-commit config files regex --- .pre-commit-config.yaml | 42 ++++++++++++++++---------- aiida/backends/tests/verdi_commands.py | 24 ++++++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ddef5dcc3..9e9ea451bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,13 +4,17 @@ hooks: - id: yapf language: system + types: [file, python] files: >- - ^(aiida/control/) - |(aiida/cmdline/tests) - |(docs/update_req_for_rtd.py) - |(.travis_data/test_setup.py) - |(aiida/backends/tests/verdi_commands.py) - |(aiida/utils/.*fixtures.py) + (?x)^( + aiida/control/| + aiida/cmdline/tests| + docs/update_req_for_rtd.py| + .travis_data/test_setup.py| + .travis_data/test_plugin_testcase.py| + aiida/backends/tests/verdi_commands.py| + aiida/utils/.*fixtures.py + ) # prospector: collection of linters - repo: git://github.com/guykisel/prospector-mirror @@ -18,14 +22,18 @@ hooks: - id: prospector language: system - exclude: '^(tests/)|(examples/)' + exclude: ^(tests/|examples/) + types: [file, python] files: >- - ^(aiida/control/) - |(aiida/cmdline/tests) - |(docs/update_req_for_rtd.py) - |(.travis_data/test_setup.py) - |(aiida/backends/tests/verdi_commands.py) - |(aiida/utils/.*fixtures.py) + (?x)^( + aiida/control/.*| + aiida/cmdline/tests.*| + docs/update_req_for_rtd.py| + .travis_data/test_setup.py| + .travis_data/test_plugin_testcase.py| + aiida/backends/tests/verdi_commands.py| + aiida/utils/.*fixtures.py| + ) - repo: local hooks: @@ -34,9 +42,11 @@ entry: python ./docs/update_req_for_rtd.py --pre-commit language: system files: >- - ^(setup_requirements.py) - |(docs/requirements_for_rtd.txt) - |(docs/update_req_for_rtd.py) + (?x)^( + setup_requirements.py| + docs/requirements_for_rtd.txt| + docs/update_req_for_rtd.py| + )$ pass_filenames: false - repo: git://github.com/pre-commit/pre-commit-hooks diff --git a/aiida/backends/tests/verdi_commands.py b/aiida/backends/tests/verdi_commands.py index 3b8c920193..e4a8994415 100644 --- a/aiida/backends/tests/verdi_commands.py +++ b/aiida/backends/tests/verdi_commands.py @@ -93,24 +93,18 @@ def setUpClass(cls, *args, **kwargs): # Create some calculation calc1 = JobCalculation( computer=cls.computer, - resources={ - 'num_machines': 1, - 'num_mpiprocs_per_machine': 1 - }).store() + resources={'num_machines': 1, + 'num_mpiprocs_per_machine': 1}).store() calc1._set_state(calc_states.TOSUBMIT) calc2 = JobCalculation( computer=cls.computer.name, - resources={ - 'num_machines': 1, - 'num_mpiprocs_per_machine': 1 - }).store() + resources={'num_machines': 1, + 'num_mpiprocs_per_machine': 1}).store() calc2._set_state(calc_states.COMPUTED) calc3 = JobCalculation( computer=cls.computer.id, - resources={ - 'num_machines': 1, - 'num_mpiprocs_per_machine': 1 - }).store() + resources={'num_machines': 1, + 'num_mpiprocs_per_machine': 1}).store() calc3._set_state(calc_states.FINISHED) def test_calculation_list(self): @@ -136,7 +130,7 @@ def test_calculation_list(self): "simple calculation list.") with Capturing() as output: - calc_cmd.calculation_list(*['-a']) + calc_cmd.calculation_list(* ['-a']) out_str = ''.join(output) self.assertTrue(calc_states.FINISHED in out_str, @@ -207,7 +201,7 @@ def test_code_list(self): # Run a verdi code list -a, capture the output and check if the result # is the same as the previous one with Capturing() as output: - code_cmd.code_list(*['-a']) + code_cmd.code_list(* ['-a']) out_str_2 = ''.join(output) self.assertEqual(out_str_1, out_str_2, "verdi code list & verdi code list -a should provide " @@ -215,7 +209,7 @@ def test_code_list(self): # Run a verdi code list -c, capture the output and check the result with Capturing() as output: - code_cmd.code_list(*['-c', computer_name_1]) + code_cmd.code_list(* ['-c', computer_name_1]) out_str = ''.join(output) self.assertTrue(computer_name_1 in out_str, "The computer 1 name should be included into " From ec3c2d3a839a0ebb086c64a6e291dc774040955d Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 10:46:27 +0200 Subject: [PATCH 2/8] add missing docstring --- .pre-commit-config.yaml | 4 ++-- .travis-data/test_plugin_testcase.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e9ea451bb..760c8f95ec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,12 +8,12 @@ files: >- (?x)^( aiida/control/| - aiida/cmdline/tests| + aiida/cmdline/tests/| docs/update_req_for_rtd.py| .travis_data/test_setup.py| .travis_data/test_plugin_testcase.py| aiida/backends/tests/verdi_commands.py| - aiida/utils/.*fixtures.py + aiida/utils/.*fixtures.py| ) # prospector: collection of linters diff --git a/.travis-data/test_plugin_testcase.py b/.travis-data/test_plugin_testcase.py index c63c424a1c..ca2f6368d2 100644 --- a/.travis-data/test_plugin_testcase.py +++ b/.travis-data/test_plugin_testcase.py @@ -14,10 +14,12 @@ def determine_backend(): return BACKEND_DJANGO if os.environ.get( - 'TEST_AIIDA_BACKEND', BACKEND_DJANGO) == BACKEND_DJANGO else BACKEND_SQLA + 'TEST_AIIDA_BACKEND', + BACKEND_DJANGO) == BACKEND_DJANGO else BACKEND_SQLA class PluginTestcaseTestCase(PluginTestCase): + """Test the PluginTestcase from utils.fixtures""" BACKEND = determine_backend() def setUp(self): From 14e91cb9d997289cc461a6ad3837bacf59a37555 Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 11:41:35 +0200 Subject: [PATCH 3/8] fix pre-commit file regex to match exactly what we want --- .pre-commit-config.yaml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 760c8f95ec..f8e523a12e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,17 +4,16 @@ hooks: - id: yapf language: system - types: [file, python] - files: >- - (?x)^( - aiida/control/| - aiida/cmdline/tests/| - docs/update_req_for_rtd.py| + files: >- # begin multiline string + (?x)^( # (?x) -> multiline regex, ^ -> beginning of file path + aiida/control/.*.py| # must match the whole path, therefore + aiida/cmdline/tests/.*.py| # the .*.py (.* matches everything) + docs/update_req_for_rtd.py| # a|b -> match a OR b .travis_data/test_setup.py| - .travis_data/test_plugin_testcase.py| + .travis-data/test_plugin_testcase.py| aiida/backends/tests/verdi_commands.py| - aiida/utils/.*fixtures.py| - ) + aiida/utils/fixtures.py + )$ # $ -> end of file path, to add a directory, give full/path/.* # prospector: collection of linters - repo: git://github.com/guykisel/prospector-mirror @@ -26,14 +25,14 @@ types: [file, python] files: >- (?x)^( - aiida/control/.*| - aiida/cmdline/tests.*| + aiida/control/.*.py| + aiida/cmdline/tests/.*.py| docs/update_req_for_rtd.py| .travis_data/test_setup.py| - .travis_data/test_plugin_testcase.py| + .travis-data/test_plugin_testcase.py| aiida/backends/tests/verdi_commands.py| - aiida/utils/.*fixtures.py| - ) + aiida/utils/fixtures.py + )$ - repo: local hooks: From bf40ed6126cf2c468b8b4676904f16935ad29594 Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 11:53:23 +0200 Subject: [PATCH 4/8] update pre-commit hooks --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8e523a12e..3c264ae12f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ # yet another python formatter - repo: git://github.com/pre-commit/mirrors-yapf - sha: v0.17.0 + sha: v0.19.0 hooks: - id: yapf language: system @@ -49,7 +49,7 @@ pass_filenames: false - repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.9.4 + sha: v1.1.1 hooks: - id: check-yaml From e209f2f500e104663b52d1a723af1d6530d9ea1e Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 12:30:19 +0200 Subject: [PATCH 5/8] add git status call if pre-commit fails to show the files --- .travis-data/test_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis-data/test_script.sh b/.travis-data/test_script.sh index c9c8bfc4db..666c6cbf12 100755 --- a/.travis-data/test_script.sh +++ b/.travis-data/test_script.sh @@ -21,6 +21,6 @@ case "$TEST_TYPE" in verdi -p $TEST_AIIDA_BACKEND run ${TRAVIS_BUILD_DIR}/.travis-data/test_daemon.py ;; pre-commit) - pre-commit run --all-files + pre-commit run --all-files || git status --short ;; esac From 629365e789c1d8171b028b1d3dbace587773956e Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 12:35:26 +0200 Subject: [PATCH 6/8] add git diff call to see what yapf changed --- .travis-data/test_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis-data/test_script.sh b/.travis-data/test_script.sh index 666c6cbf12..d4ba9da13a 100755 --- a/.travis-data/test_script.sh +++ b/.travis-data/test_script.sh @@ -21,6 +21,6 @@ case "$TEST_TYPE" in verdi -p $TEST_AIIDA_BACKEND run ${TRAVIS_BUILD_DIR}/.travis-data/test_daemon.py ;; pre-commit) - pre-commit run --all-files || git status --short + pre-commit run --all-files || git status --short && git diff ;; esac From 6e82427fc181a15cb27e423b4db4d4644d3f62ef Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 12:46:09 +0200 Subject: [PATCH 7/8] format with up to date yapf --- .pre-commit-config.yaml | 2 +- aiida/backends/tests/verdi_commands.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c264ae12f..8aee37cc9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,10 +8,10 @@ (?x)^( # (?x) -> multiline regex, ^ -> beginning of file path aiida/control/.*.py| # must match the whole path, therefore aiida/cmdline/tests/.*.py| # the .*.py (.* matches everything) + aiida/backends/tests/verdi_commands.py| docs/update_req_for_rtd.py| # a|b -> match a OR b .travis_data/test_setup.py| .travis-data/test_plugin_testcase.py| - aiida/backends/tests/verdi_commands.py| aiida/utils/fixtures.py )$ # $ -> end of file path, to add a directory, give full/path/.* diff --git a/aiida/backends/tests/verdi_commands.py b/aiida/backends/tests/verdi_commands.py index e4a8994415..3b8c920193 100644 --- a/aiida/backends/tests/verdi_commands.py +++ b/aiida/backends/tests/verdi_commands.py @@ -93,18 +93,24 @@ def setUpClass(cls, *args, **kwargs): # Create some calculation calc1 = JobCalculation( computer=cls.computer, - resources={'num_machines': 1, - 'num_mpiprocs_per_machine': 1}).store() + resources={ + 'num_machines': 1, + 'num_mpiprocs_per_machine': 1 + }).store() calc1._set_state(calc_states.TOSUBMIT) calc2 = JobCalculation( computer=cls.computer.name, - resources={'num_machines': 1, - 'num_mpiprocs_per_machine': 1}).store() + resources={ + 'num_machines': 1, + 'num_mpiprocs_per_machine': 1 + }).store() calc2._set_state(calc_states.COMPUTED) calc3 = JobCalculation( computer=cls.computer.id, - resources={'num_machines': 1, - 'num_mpiprocs_per_machine': 1}).store() + resources={ + 'num_machines': 1, + 'num_mpiprocs_per_machine': 1 + }).store() calc3._set_state(calc_states.FINISHED) def test_calculation_list(self): @@ -130,7 +136,7 @@ def test_calculation_list(self): "simple calculation list.") with Capturing() as output: - calc_cmd.calculation_list(* ['-a']) + calc_cmd.calculation_list(*['-a']) out_str = ''.join(output) self.assertTrue(calc_states.FINISHED in out_str, @@ -201,7 +207,7 @@ def test_code_list(self): # Run a verdi code list -a, capture the output and check if the result # is the same as the previous one with Capturing() as output: - code_cmd.code_list(* ['-a']) + code_cmd.code_list(*['-a']) out_str_2 = ''.join(output) self.assertEqual(out_str_1, out_str_2, "verdi code list & verdi code list -a should provide " @@ -209,7 +215,7 @@ def test_code_list(self): # Run a verdi code list -c, capture the output and check the result with Capturing() as output: - code_cmd.code_list(* ['-c', computer_name_1]) + code_cmd.code_list(*['-c', computer_name_1]) out_str = ''.join(output) self.assertTrue(computer_name_1 in out_str, "The computer 1 name should be included into " From 2e83f96053d4769931713f75e25df7ecd9d8c000 Mon Sep 17 00:00:00 2001 From: DropD Date: Fri, 27 Oct 2017 12:47:23 +0200 Subject: [PATCH 8/8] revert unneccessary formatting change --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8aee37cc9c..3c264ae12f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,10 +8,10 @@ (?x)^( # (?x) -> multiline regex, ^ -> beginning of file path aiida/control/.*.py| # must match the whole path, therefore aiida/cmdline/tests/.*.py| # the .*.py (.* matches everything) - aiida/backends/tests/verdi_commands.py| docs/update_req_for_rtd.py| # a|b -> match a OR b .travis_data/test_setup.py| .travis-data/test_plugin_testcase.py| + aiida/backends/tests/verdi_commands.py| aiida/utils/fixtures.py )$ # $ -> end of file path, to add a directory, give full/path/.*