Message ID | 20201027223815.159802-2-jsnow@redhat.com |
---|---|
State | New |
Headers | show |
Series | python: add linters to gitlab CI | expand |
On 27/10/2020 23.38, John Snow wrote: > Try using pytest to manage our various tests; even though right now > they're only invoking binaries and not really running any python-native > code. > > Create tests/, and add test_lint.py which calls out to mypy, flake8, > pylint and isort to enforce the standards in this directory. > > Add pytest to the setup.cfg development dependencies; add a pytest > configuration section as well; run it in verbose mode. > > Finally, add pytest to the Pipfile environment and lock the new > dependencies. (Note, this also updates an unrelated dependency; but the > only way to avoid this is to pin that dependency at a lower version -- > which there is no reason to do at present.) > > Provided you have the right development dependencies (mypy, flake8, > isort, pylint, and now pytest) You should be able to run "pytest" from > the python folder to run all of these linters with the correct > arguments. > > Signed-off-by: John Snow <jsnow@redhat.com> > --- > python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- > python/setup.cfg | 5 +++ > python/tests/test_lint.py | 28 +++++++++++++++ > 3 files changed, 99 insertions(+), 5 deletions(-) > create mode 100644 python/tests/test_lint.py > > diff --git a/python/Pipfile.lock b/python/Pipfile.lock > index 05077475d750..105ffbc09a8e 100644 > --- a/python/Pipfile.lock > +++ b/python/Pipfile.lock > @@ -30,6 +30,14 @@ > "markers": "python_version >= '3.5'", > "version": "==2.4.2" > }, > + "attrs": { > + "hashes": [ > + "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", > + "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" > + ], > + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", Can't you simply use "python_version >= '3.6'" instead? Thomas
On 10/28/20 2:19 AM, Thomas Huth wrote: > On 27/10/2020 23.38, John Snow wrote: >> Try using pytest to manage our various tests; even though right now >> they're only invoking binaries and not really running any python-native >> code. >> >> Create tests/, and add test_lint.py which calls out to mypy, flake8, >> pylint and isort to enforce the standards in this directory. >> >> Add pytest to the setup.cfg development dependencies; add a pytest >> configuration section as well; run it in verbose mode. >> >> Finally, add pytest to the Pipfile environment and lock the new >> dependencies. (Note, this also updates an unrelated dependency; but the >> only way to avoid this is to pin that dependency at a lower version -- >> which there is no reason to do at present.) >> >> Provided you have the right development dependencies (mypy, flake8, >> isort, pylint, and now pytest) You should be able to run "pytest" from >> the python folder to run all of these linters with the correct >> arguments. >> >> Signed-off-by: John Snow <jsnow@redhat.com> >> --- >> python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- >> python/setup.cfg | 5 +++ >> python/tests/test_lint.py | 28 +++++++++++++++ >> 3 files changed, 99 insertions(+), 5 deletions(-) >> create mode 100644 python/tests/test_lint.py >> >> diff --git a/python/Pipfile.lock b/python/Pipfile.lock >> index 05077475d750..105ffbc09a8e 100644 >> --- a/python/Pipfile.lock >> +++ b/python/Pipfile.lock >> @@ -30,6 +30,14 @@ >> "markers": "python_version >= '3.5'", >> "version": "==2.4.2" >> }, >> + "attrs": { >> + "hashes": [ >> + "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", >> + "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" >> + ], >> + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", > > Can't you simply use "python_version >= '3.6'" instead? > > Thomas > This file is generated; I don't really actually know what these markers mean or to whom. I can't edit it because it's checksummed. --js
On 10/28/20 2:23 PM, John Snow wrote: > On 10/28/20 2:19 AM, Thomas Huth wrote: >> On 27/10/2020 23.38, John Snow wrote: >>> Try using pytest to manage our various tests; even though right now >>> they're only invoking binaries and not really running any python-native >>> code. >>> >>> Create tests/, and add test_lint.py which calls out to mypy, flake8, >>> pylint and isort to enforce the standards in this directory. >>> >>> Add pytest to the setup.cfg development dependencies; add a pytest >>> configuration section as well; run it in verbose mode. >>> >>> Finally, add pytest to the Pipfile environment and lock the new >>> dependencies. (Note, this also updates an unrelated dependency; but the >>> only way to avoid this is to pin that dependency at a lower version -- >>> which there is no reason to do at present.) >>> >>> Provided you have the right development dependencies (mypy, flake8, >>> isort, pylint, and now pytest) You should be able to run "pytest" from >>> the python folder to run all of these linters with the correct >>> arguments. >>> >>> Signed-off-by: John Snow <jsnow@redhat.com> >>> --- >>> python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- >>> python/setup.cfg | 5 +++ >>> python/tests/test_lint.py | 28 +++++++++++++++ >>> 3 files changed, 99 insertions(+), 5 deletions(-) >>> create mode 100644 python/tests/test_lint.py >>> >>> diff --git a/python/Pipfile.lock b/python/Pipfile.lock >>> index 05077475d750..105ffbc09a8e 100644 >>> --- a/python/Pipfile.lock >>> +++ b/python/Pipfile.lock >>> @@ -30,6 +30,14 @@ >>> "markers": "python_version >= '3.5'", >>> "version": "==2.4.2" >>> }, >>> + "attrs": { >>> + "hashes": [ >>> + >>> "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", >>> >>> + >>> "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" >>> >>> + ], >>> + "markers": "python_version >= '2.7' and python_version >>> not in '3.0, 3.1, 3.2, 3.3'", >> >> Can't you simply use "python_version >= '3.6'" instead? >> >> Thomas >> > > This file is generated; I don't really actually know what these markers > mean or to whom. I can't edit it because it's checksummed. We should remember to add a line such "The Pipfile.lock content is generated" in the commit message each time it is modified after a change in setup.cfg :) Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
On 28/10/2020 14.23, John Snow wrote: > On 10/28/20 2:19 AM, Thomas Huth wrote: >> On 27/10/2020 23.38, John Snow wrote: >>> Try using pytest to manage our various tests; even though right now >>> they're only invoking binaries and not really running any python-native >>> code. >>> >>> Create tests/, and add test_lint.py which calls out to mypy, flake8, >>> pylint and isort to enforce the standards in this directory. >>> >>> Add pytest to the setup.cfg development dependencies; add a pytest >>> configuration section as well; run it in verbose mode. >>> >>> Finally, add pytest to the Pipfile environment and lock the new >>> dependencies. (Note, this also updates an unrelated dependency; but the >>> only way to avoid this is to pin that dependency at a lower version -- >>> which there is no reason to do at present.) >>> >>> Provided you have the right development dependencies (mypy, flake8, >>> isort, pylint, and now pytest) You should be able to run "pytest" from >>> the python folder to run all of these linters with the correct >>> arguments. >>> >>> Signed-off-by: John Snow <jsnow@redhat.com> >>> --- >>> python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- >>> python/setup.cfg | 5 +++ >>> python/tests/test_lint.py | 28 +++++++++++++++ >>> 3 files changed, 99 insertions(+), 5 deletions(-) >>> create mode 100644 python/tests/test_lint.py >>> >>> diff --git a/python/Pipfile.lock b/python/Pipfile.lock >>> index 05077475d750..105ffbc09a8e 100644 >>> --- a/python/Pipfile.lock >>> +++ b/python/Pipfile.lock >>> @@ -30,6 +30,14 @@ >>> "markers": "python_version >= '3.5'", >>> "version": "==2.4.2" >>> }, >>> + "attrs": { >>> + "hashes": [ >>> + >>> "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", >>> + >>> "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" >>> + ], >>> + "markers": "python_version >= '2.7' and python_version not >>> in '3.0, 3.1, 3.2, 3.3'", >> >> Can't you simply use "python_version >= '3.6'" instead? >> >> Thomas >> > > This file is generated; I don't really actually know what these markers mean > or to whom. I can't edit it because it's checksummed. If the file is only generated, why do we need that in the repository? ... that only calls for trouble if other people try to apply changes here... Thomas
On 10/28/20 10:54 AM, Thomas Huth wrote: > On 28/10/2020 14.23, John Snow wrote: >> On 10/28/20 2:19 AM, Thomas Huth wrote: >>> On 27/10/2020 23.38, John Snow wrote: >>>> Try using pytest to manage our various tests; even though right now >>>> they're only invoking binaries and not really running any python-native >>>> code. >>>> >>>> Create tests/, and add test_lint.py which calls out to mypy, flake8, >>>> pylint and isort to enforce the standards in this directory. >>>> >>>> Add pytest to the setup.cfg development dependencies; add a pytest >>>> configuration section as well; run it in verbose mode. >>>> >>>> Finally, add pytest to the Pipfile environment and lock the new >>>> dependencies. (Note, this also updates an unrelated dependency; but the >>>> only way to avoid this is to pin that dependency at a lower version -- >>>> which there is no reason to do at present.) >>>> >>>> Provided you have the right development dependencies (mypy, flake8, >>>> isort, pylint, and now pytest) You should be able to run "pytest" from >>>> the python folder to run all of these linters with the correct >>>> arguments. >>>> >>>> Signed-off-by: John Snow <jsnow@redhat.com> >>>> --- >>>> python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- >>>> python/setup.cfg | 5 +++ >>>> python/tests/test_lint.py | 28 +++++++++++++++ >>>> 3 files changed, 99 insertions(+), 5 deletions(-) >>>> create mode 100644 python/tests/test_lint.py >>>> >>>> diff --git a/python/Pipfile.lock b/python/Pipfile.lock >>>> index 05077475d750..105ffbc09a8e 100644 >>>> --- a/python/Pipfile.lock >>>> +++ b/python/Pipfile.lock >>>> @@ -30,6 +30,14 @@ >>>> "markers": "python_version >= '3.5'", >>>> "version": "==2.4.2" >>>> }, >>>> + "attrs": { >>>> + "hashes": [ >>>> + >>>> "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", >>>> + >>>> "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" >>>> + ], >>>> + "markers": "python_version >= '2.7' and python_version not >>>> in '3.0, 3.1, 3.2, 3.3'", >>> >>> Can't you simply use "python_version >= '3.6'" instead? >>> >>> Thomas >>> >> >> This file is generated; I don't really actually know what these markers mean >> or to whom. I can't edit it because it's checksummed. > > If the file is only generated, why do we need that in the repository? ... > that only calls for trouble if other people try to apply changes here... Because it is generated with respect to a given point in time; this specifies the exact loadout of packages that will be used to run the linter. If you remove it, every time you run "pipenv lock" again, it will use newer and newer packages each time ... which defeats the purpose of having a lockfile to begin wtih. The intention is that this lockfile only gets updated as an intentional action; using newer dependencies and so on for the test environment is a conscious action. You are free to use the latest and greatest packages yourself if you choose; just skip the venv step -- but then you're on your own for making sure that environment works. *this* environment receives my full-throated support. The tests will and must pass on *this* environment. --js
diff --git a/python/Pipfile.lock b/python/Pipfile.lock index 05077475d750..105ffbc09a8e 100644 --- a/python/Pipfile.lock +++ b/python/Pipfile.lock @@ -30,6 +30,14 @@ "markers": "python_version >= '3.5'", "version": "==2.4.2" }, + "attrs": { + "hashes": [ + "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594", + "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==20.2.0" + }, "flake8": { "hashes": [ "sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839", @@ -46,6 +54,13 @@ "markers": "python_version < '3.8'", "version": "==2.0.0" }, + "iniconfig": { + "hashes": [ + "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", + "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32" + ], + "version": "==1.1.1" + }, "isort": { "hashes": [ "sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7", @@ -115,6 +130,30 @@ ], "version": "==0.4.3" }, + "packaging": { + "hashes": [ + "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8", + "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==20.4" + }, + "pluggy": { + "hashes": [ + "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0", + "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.13.1" + }, + "py": { + "hashes": [ + "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2", + "sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.9.0" + }, "pycodestyle": { "hashes": [ "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367", @@ -139,6 +178,22 @@ "markers": "python_version >= '3.5'", "version": "==2.6.0" }, + "pyparsing": { + "hashes": [ + "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1", + "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.4.7" + }, + "pytest": { + "hashes": [ + "sha256:7a8190790c17d79a11f847fba0b004ee9a8122582ebff4729a082c109e81a4c9", + "sha256:8f593023c1a0f916110285b6efd7f99db07d59546e3d8c36fc60e2ab05d3be92" + ], + "markers": "python_version >= '3.5'", + "version": "==6.1.1" + }, "qemu": { "editable": true, "path": "." @@ -148,7 +203,7 @@ "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.15.0" }, "toml": { @@ -162,9 +217,11 @@ "hashes": [ "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355", "sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919", + "sha256:0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d", "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa", "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652", "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75", + "sha256:3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c", "sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01", "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d", "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1", @@ -173,16 +230,20 @@ "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3", "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b", "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614", + "sha256:92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c", "sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb", + "sha256:b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395", "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b", "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41", "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6", "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34", "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe", + "sha256:d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072", + "sha256:fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91", "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4", "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7" ], - "markers": "implementation_name == 'cpython' and python_version < '3.8'", + "markers": "python_version < '3.8' and implementation_name == 'cpython'", "version": "==1.4.1" }, "typing-extensions": { @@ -201,11 +262,11 @@ }, "zipp": { "hashes": [ - "sha256:16522f69653f0d67be90e8baa4a46d66389145b734345d68a257da53df670903", - "sha256:c1532a8030c32fd52ff6a288d855fe7adef5823ba1d26a29a68fd6314aa72baa" + "sha256:102c24ef8f171fd729d46599845e95c7ab894a4cf45f5de11a44cc7444fb1108", + "sha256:ed5eee1974372595f9e416cc7bbeeb12335201d8081ca8a0743c954d4446e5cb" ], "markers": "python_version >= '3.6'", - "version": "==3.3.1" + "version": "==3.4.0" } } } diff --git a/python/setup.cfg b/python/setup.cfg index 503384f0c920..cb696291ba38 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -25,6 +25,7 @@ devel = isort >= 5.0.5 mypy >= 0.770 pylint >= 2.6.0 + pytest >= 3.0.0 [flake8] @@ -72,3 +73,7 @@ include_trailing_comma=True line_length=72 lines_after_imports=2 multi_line_output=3 + +[tool:pytest] +addopts = -v +console_output_style = count diff --git a/python/tests/test_lint.py b/python/tests/test_lint.py new file mode 100644 index 000000000000..38fefa01c667 --- /dev/null +++ b/python/tests/test_lint.py @@ -0,0 +1,28 @@ +import subprocess + + +def _external_test(command_line: str) -> None: + args = command_line.split(' ') + try: + subprocess.run(args, check=True) + except subprocess.CalledProcessError as err: + # Re-contextualize to avoid pytest showing error context inside + # the subprocess module itself + raise Exception("'{:s}' returned {:d}".format( + ' '.join(args), err.returncode)) from None + + +def test_isort() -> None: + _external_test('isort -c qemu') + + +def test_flake8() -> None: + _external_test('flake8') + + +def test_pylint() -> None: + _external_test('pylint qemu') + + +def test_mypy() -> None: + _external_test('mypy -p qemu')
Try using pytest to manage our various tests; even though right now they're only invoking binaries and not really running any python-native code. Create tests/, and add test_lint.py which calls out to mypy, flake8, pylint and isort to enforce the standards in this directory. Add pytest to the setup.cfg development dependencies; add a pytest configuration section as well; run it in verbose mode. Finally, add pytest to the Pipfile environment and lock the new dependencies. (Note, this also updates an unrelated dependency; but the only way to avoid this is to pin that dependency at a lower version -- which there is no reason to do at present.) Provided you have the right development dependencies (mypy, flake8, isort, pylint, and now pytest) You should be able to run "pytest" from the python folder to run all of these linters with the correct arguments. Signed-off-by: John Snow <jsnow@redhat.com> --- python/Pipfile.lock | 71 ++++++++++++++++++++++++++++++++++++--- python/setup.cfg | 5 +++ python/tests/test_lint.py | 28 +++++++++++++++ 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 python/tests/test_lint.py