From b84a02077d88e54500753c7f3d5ebb9d4cd5da65 Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Mon, 17 Jul 2023 18:16:38 +0200 Subject: [PATCH] test isort template --- .gitlab-ci.yml | 13 ++++++++++++ templates/python/code_quality/black/black.yml | 2 +- .../python/code_quality/flake8/flake8.yml | 2 +- templates/python/code_quality/isort/isort.yml | 20 +++++++++++-------- tests/black_project/pyproject.toml | 5 ----- tests/flake8_project/pyproject.toml | 5 ----- tests/isort_project/pyproject.toml | 11 ++++++++++ .../src/isort_project/__init__.py | 5 +++++ .../src/isort_project/a_module.py | 2 ++ tests/isort_project/src/isort_project/main.py | 11 ++++++++++ .../src/isort_project/z_module.py | 2 ++ 11 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 tests/isort_project/pyproject.toml create mode 100644 tests/isort_project/src/isort_project/__init__.py create mode 100644 tests/isort_project/src/isort_project/a_module.py create mode 100644 tests/isort_project/src/isort_project/main.py create mode 100644 tests/isort_project/src/isort_project/z_module.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8956968..7752cda 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 ad1625d..f8bec5c 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 f60bda1..6cf80e1 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 9da0609..e409237 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 968905a..beec19a 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 7618928..eb3a841 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 0000000..241a663 --- /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 0000000..428b5a7 --- /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 0000000..be76b8a --- /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 0000000..250de77 --- /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 0000000..651a328 --- /dev/null +++ b/tests/isort_project/src/isort_project/z_module.py @@ -0,0 +1,2 @@ +def barfoo(): + ... \ No newline at end of file -- GitLab