diff --git a/isort.r2.yml b/isort.r2.yml new file mode 100644 index 0000000000000000000000000000000000000000..2d59d756066625f5063c10d789e87cf7625106fe --- /dev/null +++ b/isort.r2.yml @@ -0,0 +1,14 @@ +files: + template: ./python/code_quality/isort/isort.yml + documentation: ./python/code_quality/isort/README.md +data: + description: "Run isort on your repository" + icon: 💎 + public: true + labels: + - Lint + - Utilities + - Code Quality + - Python + license: MIT + deprecated: false diff --git a/python/code_quality/isort/README.md b/python/code_quality/isort/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f386fb2e9c239b4bb6571a063fc50f04d476672a --- /dev/null +++ b/python/code_quality/isort/README.md @@ -0,0 +1,49 @@ +## Objective + +Run [isort](https://pycqa.github.io/isort/) on your Python code to automatically sort and organize +your imports. isort separates imports into sections and by type. It's a helpful tool to ensure that +your code remains clean and readable. + +### Global Configuration of isort + +To add configuration to `isort` shared with any other usage of isort (such as manual run, +pre-commit, etc), you can use `pyproject.toml` configuration file or a dedicated `.isort.cfg`. Learn +more about [isort configuration](https://pycqa.github.io/isort/docs/configuration/config_files.html) +files. + +Here's an example configuration for `pyproject.toml`: + +```toml +[tool.isort] +profile = "black" +line_length = 100 +``` + +And for `.isort.cfg`: + +```cfg +[settings] +profile=hug +line_length=100 +``` + +These examples set the line length to 100 characters and use the "black" profile, which is designed +to work well with the `black` auto-formatter. + +## How to use it + +1. Configure the `pyproject.toml` or `.isort.cfg` file in your repository's root directory with your + desired rules. +2. Include the isort template in your CI/CD configuration (see quick use above). +3. If you need to customize the job, check + the [jobs customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization). + +## Add an <a href="https://pycqa.github.io/isort/"><img alt="Imports: isort" src="https://img.shields.io/badge/Imports-isort-yellow"></a> Badge to your project README.md + +To display the use of isort in your project, you can add the following badge to your README.md: + +```markdown +<a href="https://pycqa.github.io/isort/"> + <img alt="Imports: isort" src="https://img.shields.io/badge/Imports-isort-yellow"> +</a> +``` diff --git a/python/code_quality/isort/isort.yml b/python/code_quality/isort/isort.yml new file mode 100644 index 0000000000000000000000000000000000000000..9da0609aff110be565afff69f248f820f669cb39 --- /dev/null +++ b/python/code_quality/isort/isort.yml @@ -0,0 +1,14 @@ +isort: + image: python:latest + stage: code_quality + 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 + only: + changes: + - ./**/*.py + - .gitlab-ci.yml + - pyproject.toml