Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 6cb1d6b5 authored by Dorian Turba's avatar Dorian Turba
Browse files

add isort

parent 47a53420
No related branches found
No related tags found
No related merge requests found
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
## 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>
```
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment