osbuild: setup isort autochecking

The `test-src` makefile target now also runs isort against all source
files and reports errors.
This commit is contained in:
Simon de Vlieger 2022-08-17 11:23:19 +02:00
parent a5be1cc4d2
commit 98daf1a87d
3 changed files with 31 additions and 0 deletions

1
.git-blame-ignore-revs Normal file
View file

@ -0,0 +1 @@
1be3f1bfb671fa6d59dcd2203f23e1625194574b

View file

@ -68,6 +68,19 @@ def test_mypy():
pytest.fail("mypy issues detected")
@pytest.mark.skipif(not test.TestBase.have_isort(), reason="isort not available")
def test_isort(source_files):
#
# Run `isort` on all python sources. We simply use `find` to locate
# all `*.py` files, and then manually select the reverse-domain named
# modules we have.
#
r = subprocess.run(["isort", "-c"] + source_files, check=False)
if r.returncode != 0:
pytest.fail("isort issues detected")
@pytest.mark.skipif(not test.TestBase.have_autopep8(), reason="autopep8 not available")
def test_autopep8(source_files):
r = subprocess.run(["autopep8-3", "--diff", "--exit-code"] + source_files, check=False)

View file

@ -203,6 +203,23 @@ class TestBase(unittest.TestCase):
return r.returncode == 0 and "mypy" in r.stdout
def have_isort() -> bool:
"""Check isort Availability
This checks whether `isort` is available in the current path and
can be called by this process.
"""
try:
r = subprocess.run(
["isort", "--version"],
encoding="utf-8", stdout=subprocess.PIPE, check=False
)
except FileNotFoundError:
return False
return r.returncode == 0 and "isort" in r.stdout
@staticmethod
def have_rpm_ostree() -> bool:
"""Check rpm-ostree Availability