diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8956968ce89b95981f3f2c07d255e6d0bab11f2a..7752cdad8a1eb623e58dd4f182fb97bea9f4e2af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,7 @@ include: - local: 'templates/python/testing/pytest/pytest.yml' - local: 'templates/python/code_quality/flake8/flake8.yml' - local: 'templates/python/code_quality/black/black.yml' + - local: 'templates/python/code_quality/isort/isort.yml' pytest: stage: templates @@ -38,3 +39,15 @@ black: - pyproject.toml - templates/python/code_quality/black/**/* - tests/black_project/**/* + + +isort: + stage: templates + variables: + PROJECT_PATH: "tests/isort_project" + only: + changes: + - .gitlab-ci.yml + - pyproject.toml + - templates/python/code_quality/isort/**/* + - tests/isort_project/**/* diff --git a/templates/python/code_quality/black/black.yml b/templates/python/code_quality/black/black.yml index ad1625d4f9c8207d1087d0f5d48c2947b53b9126..f8bec5c38639aa6d521a9f7ec3815485ce3bf810 100644 --- a/templates/python/code_quality/black/black.yml +++ b/templates/python/code_quality/black/black.yml @@ -7,7 +7,7 @@ black: variables: IMAGE_TAG: !reference [.python_install, variables, IMAGE_TAG] PROJECT_PATH: "." - PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]" + PYTHON_SETUP: "pip install black" script: - !reference [.python_install, script] - black ${PROJECT_PATH} --check --diff --quiet diff --git a/templates/python/code_quality/flake8/flake8.yml b/templates/python/code_quality/flake8/flake8.yml index f60bda1f178e542a55961c7888a928ade2dad6ce..6cf80e1dcbf9fe1056a77511c39d41193bad98ff 100644 --- a/templates/python/code_quality/flake8/flake8.yml +++ b/templates/python/code_quality/flake8/flake8.yml @@ -7,7 +7,7 @@ flake8: variables: IMAGE_TAG: !reference [.python_install, variables, IMAGE_TAG] PROJECT_PATH: "." - PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]" + PYTHON_SETUP: "pip install flake8" script: - !reference [.python_install, script] - flake8 ${PROJECT_PATH} -v diff --git a/templates/python/code_quality/isort/isort.yml b/templates/python/code_quality/isort/isort.yml index 9da0609aff110be565afff69f248f820f669cb39..e40923768dc77576172d9b16b6b1e3800929a0df 100644 --- a/templates/python/code_quality/isort/isort.yml +++ b/templates/python/code_quality/isort/isort.yml @@ -1,14 +1,18 @@ +include: + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/python_install@latest.yaml' + isort: - image: python:latest + image: python:${IMAGE_TAG} stage: code_quality + variables: + IMAGE_TAG: !reference [.python_install, variables, IMAGE_TAG] + PROJECT_PATH: "." + PYTHON_SETUP: "pip install isort" script: - - python --version # Debug - - python -m venv venv --upgrade-deps || python -m venv venv # upgrade-deps is not supported before 3.9 - - source venv/bin/activate - - pip install isort - - isort . --diff + - !reference [.python_install, script] + - isort . --check-only --verbose only: changes: - - ./**/*.py + - ${PROJECT_PATH}/**/*.py - .gitlab-ci.yml - - pyproject.toml + - ${PROJECT_PATH}/pyproject.toml diff --git a/tests/black_project/pyproject.toml b/tests/black_project/pyproject.toml index 968905af53ca2ad397e0d034aec5f10bae96c416..beec19a046b7baad20feebc9629b45159b6782ea 100644 --- a/tests/black_project/pyproject.toml +++ b/tests/black_project/pyproject.toml @@ -9,8 +9,3 @@ authors = [ { name = "Author Name", email = "author.name@example.com" }, ] description = "A description of what the package is for." - -[project.optional-dependencies] -QUALITY = [ - "black", -] diff --git a/tests/flake8_project/pyproject.toml b/tests/flake8_project/pyproject.toml index 76189285166a49407fc30e0251ba7974e02789b9..eb3a8418db02a20c20f9be1933c768c7576c65b0 100644 --- a/tests/flake8_project/pyproject.toml +++ b/tests/flake8_project/pyproject.toml @@ -9,8 +9,3 @@ authors = [ { name = "Author Name", email = "author.name@example.com" }, ] description = "A description of what the package is for." - -[project.optional-dependencies] -QUALITY = [ - "flake8", -] diff --git a/tests/isort_project/pyproject.toml b/tests/isort_project/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..241a663f7e2bd821f68b25d169bfbaa58bf0148e --- /dev/null +++ b/tests/isort_project/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "isort_project" +version = "0.1.0" +authors = [ + { name = "Author Name", email = "author.name@example.com" }, +] +description = "A description of what the package is for." diff --git a/tests/isort_project/src/isort_project/__init__.py b/tests/isort_project/src/isort_project/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..428b5a7037655f68350b58bc1c3cd8fe1f3ac480 --- /dev/null +++ b/tests/isort_project/src/isort_project/__init__.py @@ -0,0 +1,5 @@ +from isort_project.a_module import foobar +from isort_project.main import main +from isort_project.z_module import barfoo + +__all__ = ["main", "foobar", "barfoo"] diff --git a/tests/isort_project/src/isort_project/a_module.py b/tests/isort_project/src/isort_project/a_module.py new file mode 100644 index 0000000000000000000000000000000000000000..be76b8a3c3fd7311673a27407de24b89dce55dc3 --- /dev/null +++ b/tests/isort_project/src/isort_project/a_module.py @@ -0,0 +1,2 @@ +def foobar(): + ... diff --git a/tests/isort_project/src/isort_project/main.py b/tests/isort_project/src/isort_project/main.py new file mode 100644 index 0000000000000000000000000000000000000000..250de775d1c9fcfd14cf1b50313c5e872521be9f --- /dev/null +++ b/tests/isort_project/src/isort_project/main.py @@ -0,0 +1,11 @@ +"""Sample main module.""" + + +def main() -> bool: + """Sample main function.""" + print("Hello, world!") + return True + + +if __name__ == "__main__": + main() diff --git a/tests/isort_project/src/isort_project/z_module.py b/tests/isort_project/src/isort_project/z_module.py new file mode 100644 index 0000000000000000000000000000000000000000..651a32811b82c11d6e60c6021cddb6ff34008867 --- /dev/null +++ b/tests/isort_project/src/isort_project/z_module.py @@ -0,0 +1,2 @@ +def barfoo(): + ... \ No newline at end of file