# python-template
[![pipeline status](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/badges/main/pipeline.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/commits/main)
[![coverage report](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/badges/main/coverage.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/commits/main)
[![Latest Release](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/badges/release.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/releases)
This is a template for a project with the following features:
- Setuptools for Python project
- Sphinx documentation
- Pytest unit tests with coverage
- Pylint code quality checks
- Type checking with mypy
- Black code formatting
- Gitlab CI/CD
## Documentation 📖
Auto generated documentation can be found _[here](http://python-template-babu-5d849e1f859ea5533ef4f19b88fd2c5db39a37f7ed.pages.fraunhofer.de/)_. :point_left:
## Setup Sphinx
Sphinx is a documentation generator that can be used to generate documentation from docstrings in the code.
**All commands are to be run from the project directory.**
<details>
<summary>Setup Sphinx for a New Project</summary>
1. Delete the existing `docs` directory if it exists.
```bash
rm -rf docs
```
1. Create Sphinx Project
We will use the `sphinx-quickstart` command to create a new Sphinx project.
The files will be created in the `docs` directory.
```bash
sphinx-quickstart docs
```
1. Edit `conf.py`
Edit the `docs/conf.py` file to add the following lines to the top of the file:
```python
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
```
Add the following lines to the `extensions` list:
```python
extensions = [
"sphinx.ext.autodoc", # for autodoc
"sphinx.ext.autosummary", # for autosummary
"sphinx.ext.viewcode", # for source code
"sphinx.ext.napoleon", # for google style docstrings
"sphinx_autodoc_typehints", # for type hints
"sphinx_copybutton", # for copy button
"sphinx-prompt", # for prompt
"recommonmark", # for markdown
]
```
Change the theme to `sphinx_rtd_theme` or another theme of your choice if you prefer:
```python
html_theme = "sphinx_rtd_theme"
```
Add the following lines to the end of the file:
```python
# generate autosummary even if no references
autosummary_generate = True
autosummary_imported_members = True
```
1. Generate Documentation
Run the following command to generate the documentation:
```bash
sphinx-apidoc -f -e -M -o docs/ sample_project_ivi/
```
The above command will generate the documentation for the `sample_project_ivi` package. There will be a `modules.rst` file in the output directory. This file will be used to generate the table of contents for the documentation.
1. Edit `index.rst`
Add modules to the table of contents by adding the following lines to the `docs/index.rst` file:
```rst
.. toctree::
:maxdepth: 2
:caption: Contents:
modules
```
1. Build Documentation
Run the following command to build the documentation:
```bash
# for html documentation
sphinx-build -b html docs docs/_build
# for pdf documentation (requires latex to be configured)
sphinx-build -M latexpdf docs docs/_build
```
The documentation will be generated in the `docs/_build` directory.
</details>
## Setuptools
<details>
<summary>Setup Setuptools for a New Project</summary>
- Use **setuptools** to package your code.
- Setuptools lets you easily download, build, install, upgrade, and uninstall Python packages.
- Setuptools can be configured using the following files:
- `setup.py`
- `setup.cfg`
- Setuptools lets you install your code using pip.
```bash
pip install git+REPO_URL
# or
pip install .
# or in editable mode
pip install -e .
```
- You can also save configurations for your project in the `setup.cfg` file.
- Sample `setup.py` file:
```python
from setuptools import setup, find_packages
setup(
name="project_name",
version="0.1.0",
description="Project description",
author="Author name",
author_email="Author email",
url="Project url",
license="License name",
# find_packages() finds all the packages in the src directory
# package_dir={"": "src"} can be used to specify the source directory
packages=find_packages(),
# package_data={"": ["data/*.txt"]} can be used to include data files
# the following command will include all txt files in the data directory
# hence hardcoded paths in the code can be avoided and the code can be made more portable
package_data={"src": ["data/*.txt"]},
# install_requires can be used to specify the dependencies of the project
# will be installed automatically when the project is installed
install_requires=[
"package1",
"package2",
],
# extras_require can be used to specify the dependencies of the project
# will not be installed automatically when the project is installed
extras_require={
"dev": [
"package3",
"package4",
],
},
# entry_points can be used to specify the command line scripts
entry_points={
"console_scripts": [
"script_name=package.module:main",
],
},
)
```
- Check the [Setuptools documentation](https://setuptools.pypa.io/) for more information.
</details>
## Unit testing with Pytest
<details>
<summary>Setup Pytest for a New Project</summary>
- Use **pytest** to write and run tests.
- Unittesting makes sure that your code works as expected.
- Pytest can automatically find and run tests in files named `test_*.py` or `*_test.py`.
- Pytest can be run using the following command:
```bash
pytest test_file.py
# or
python -m pytest test_file.py
# or to run all tests in a directory 'tests'
pytest tests/
```
- Here is a sample test file:
```python
import pytest
def test_function():
assert 1 == 1
```
- Some sample tests can be found in the [tests](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/tree/main/tests).
- Check the [Pytest documentation](https://docs.pytest.org/) for more information.
- Use **coverage** to check the test coverage of your code.
- Coverage identifies which parts of your code are executed during testing and reports can be generated that show which parts of your code are missed by the tests.
- Coverage can be run using the following command:
```bash
coverage run -m pytest file.py
coverage report
```
- Check the [Coverage documentation](https://coverage.readthedocs.io/) for more information.
- **tox** can be used to run all the above tools in one command.
- Tox creates a virtual environment for each Python version you want to test.
- Tox can be run using the following command:
```bash
tox
```
- Configuration for tox can be specified in the following files:
- `tox.ini`
- `pyproject.toml`
- `setup.cfg`
- A sample tox configuration file:
```ini
[tox]
envlist = py{38,311} # specify the python versions to test
[testenv]
deps =
pytest
coverage
commands =
pytest
coverage run -m pytest
coverage report
```
- Check the [Tox documentation](https://tox.readthedocs.io/) for more information.
- Sample tox configuration files can be found in the [tox](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/blob/main/tox.ini) directory.
</details>
## Code Quality Checks
<details>
<summary>Setup Code Quality Checks for a New Project</summary>
### Pylint
- Use **linters** to check your code for errors and style.
- Pylint is one of the tools that can be used to lint your code.
- [flake8](https://flake8.pycqa.org/) is another popular tool that can be used to lint your code.
- Code can be linted using the following command:
```bash
# recommended (pylint and flake8)
pylint file.py
# or
flake8 file.py
```
- Pylint can provide you with a score for your code. This score can be used to track the quality of your code and also be used to enforce a minimum score. In the template repository, the minimum score is set to 9.0. If the score is below 9.0, the CI pipeline will fail. This is done with the following command:
```bash
pylint --fail-under=9 uam
```
- It can be used to enforce a coding style, find bugs and unused code.
- Check the [Pylint documentation](https://pylint.pycqa.org/en/stable/index.html) for more information.
- [ruff](https://github.com/charliermarsh/ruff) can also be used to lint your code. ruff is based on rust is much faster than pylint and flake8.
- Example with pylint:
```python
# Example code test.py
def calculate_average(numbers):
total = sum(numbers)
number_of_items = len(numbers)
average = total / len(numbers)
print("The average is:", average)
numbers = [1, 2, 3, 4, 5]
calculate_average(numbers)
```
```bash
pylint test.py
# Output
************* Module example
test.py:10:0: C0304: Final newline missing (missing-final-newline)
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:2:0: C0116: Missing function or method docstring (missing-function-docstring)
test.py:2:22: W0621: Redefining name 'numbers' from outer scope (line 9) (redefined-outer-name)
test.py:4:4: W0612: Unused variable 'number_of_items' (unused-variable)
------------------------------------------------------------------
Your code has been rated at 2.86/10 (previous run: 4.29/10, -1.43)
```
The same suggestions can be seen in VSCode as well once the extensions are installed.
### Mypy
- Use **type hints** to specify the type of variables and arguments.
- Type hints are optional in Python, but they are recommended.
- Type hints can be very useful for documentation and debugging.
- Type hints are specified using the following syntax:
```python
variable: type
def function(argument: type) -> type:
pass
class Class:
def method(self, argument: type) -> type:
pass
```
- Check the [PEP 484](https://www.python.org/dev/peps/pep-0484/) for more information.
- Tools like [mypy](http://mypy-lang.org/) can be used to check your code for type errors.
```bash
mypy file.py
mypy src/
```
- It is a static type checker that can identify type errors in your code.
```python
def function(argument: int) -> int:
return argument + "1"
```
```bash
mypy file.py
error: Unsupported operand types for + ("int" and "str")
```
- Check the [Mypy documentation](http://mypy-lang.org/) for more information.
- Example 1
```python
# Example code test_1.py
def add_numbers(a: int, b: int) -> int:
return a + b
result = add_numbers(5, "10") # Type mismatch: 'str' cannot be added to 'int'
print(result)
```
```bash
mypy test_1.py
# Output
test.py:5: error: Argument 2 to "add_numbers" has incompatible type "str"; expected "int" [arg-type]
Found 1 error in 1 file (checked 1 source file)
```
- Example 2
```python
# Example code test_2.py
import numpy as np
def calculate_mean(data: np.ndarray) -> float:
return np.mean(data)
numbers = [1, 2, 3, 4, 5] # Incorrect type: List[int] instead of np.ndarray
mean = calculate_mean(numbers)
print(mean)
```
```bash
mypy test_2.py
# Output
test.py:8: error: Argument 1 to "calculate_mean" has incompatible type "List[int]"; expected "ndarray[Any, Any]" [arg-type]
Found 1 error in 1 file (checked 1 source file)
```
- **You need to provide type hints for your code to be checked by mypy. Else it will not be able to check the type of the variables.**
- Mypy will also check for type errors in third-party libraries.
### Black
- Use **black** to format your code.
- Black lets you format your code in a consistent way.
- Black can be run using the following command:
```bash
black --check --diff file.py # will show the changes that will be made without making them
# or
black file.py # will format the file in place
```
- It can be integrated with your editor to format your code on save.
- Check the [Black documentation](https://black.readthedocs.io/) for more information.
- Example:
```python
# before
def my_function():
x=1
y = 2
z=3
if x>y:
print("x is greater than y")
else:
print("y is greater than or equal to x")
```
<div align="center">
<font size="5">↓</font>
</div>
```python
# after
def my_function():
x = 1
y = 2
z = 3
if x > y:
print("x is greater than y")
else:
print("y is greater than or equal to x")
```
- Use **isort** to sort your imports.
- Isort does sort import in the following order:
- standard library imports
- related third party imports
- local application/library specific imports
- Isort can be run using the following command:
```bash
isort --check-only --diff file.py # will show the changes that will be made without making them
# or
isort file.py # will format the file in place
```
- It can also be integrated with your editor to sort your imports on save.
- Here is an example of how isort sorts imports:
```python
# before
import os
import sys
import django
import requests
import uam
```
<div align="center">
<font size="5">↓</font>
</div>
```python
# after
import os
import sys
import django
import requests
import uam
```
- Check the [Isort documentation](https://pycqa.github.io/isort/) for more information.
</details>
Raw data
{
"_id": null,
"home_page": "https://gitlab.cc-asp.fraunhofer.de/babu/python-template/",
"name": "sample-project-ivi",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "python",
"author": "Harisankar Babu",
"author_email": "harisankar.babu@ivi.fraunhofer.de",
"download_url": "https://files.pythonhosted.org/packages/82/e5/61b44e1ac8216fdeb27e87dc403e03a183e0677aa86ce4fb8bfcf498e67d/sample_project_ivi-0.0.3.tar.gz",
"platform": "any",
"description": "# python-template\n\n[![pipeline status](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/badges/main/pipeline.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/commits/main)\n[![coverage report](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/badges/main/coverage.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/commits/main)\n[![Latest Release](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/badges/release.svg)](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/releases)\n\nThis is a template for a project with the following features:\n\n- Setuptools for Python project\n- Sphinx documentation\n- Pytest unit tests with coverage\n- Pylint code quality checks\n- Type checking with mypy\n- Black code formatting\n- Gitlab CI/CD\n\n## Documentation \ud83d\udcd6\n\nAuto generated documentation can be found _[here](http://python-template-babu-5d849e1f859ea5533ef4f19b88fd2c5db39a37f7ed.pages.fraunhofer.de/)_. :point_left:\n\n## Setup Sphinx\n\nSphinx is a documentation generator that can be used to generate documentation from docstrings in the code.\n\n**All commands are to be run from the project directory.**\n\n<details>\n\n<summary>Setup Sphinx for a New Project</summary>\n\n1. Delete the existing `docs` directory if it exists.\n\n ```bash\n rm -rf docs\n ```\n\n1. Create Sphinx Project\n\n We will use the `sphinx-quickstart` command to create a new Sphinx project.\n The files will be created in the `docs` directory.\n\n ```bash\n sphinx-quickstart docs\n ```\n\n1. Edit `conf.py`\n\n Edit the `docs/conf.py` file to add the following lines to the top of the file:\n\n ```python\n import os\n import sys\n sys.path.insert(0, os.path.abspath('..'))\n ```\n\n Add the following lines to the `extensions` list:\n\n ```python\n extensions = [\n \"sphinx.ext.autodoc\", # for autodoc\n \"sphinx.ext.autosummary\", # for autosummary\n \"sphinx.ext.viewcode\", # for source code\n \"sphinx.ext.napoleon\", # for google style docstrings\n \"sphinx_autodoc_typehints\", # for type hints\n \"sphinx_copybutton\", # for copy button\n \"sphinx-prompt\", # for prompt\n \"recommonmark\", # for markdown\n ]\n ```\n\n Change the theme to `sphinx_rtd_theme` or another theme of your choice if you prefer:\n\n ```python\n html_theme = \"sphinx_rtd_theme\"\n ```\n\n Add the following lines to the end of the file:\n\n ```python\n # generate autosummary even if no references\n autosummary_generate = True\n autosummary_imported_members = True\n ```\n\n1. Generate Documentation\n\n Run the following command to generate the documentation:\n\n ```bash\n sphinx-apidoc -f -e -M -o docs/ sample_project_ivi/\n ```\n\n The above command will generate the documentation for the `sample_project_ivi` package. There will be a `modules.rst` file in the output directory. This file will be used to generate the table of contents for the documentation.\n\n1. Edit `index.rst`\n\n Add modules to the table of contents by adding the following lines to the `docs/index.rst` file:\n\n ```rst\n .. toctree::\n :maxdepth: 2\n :caption: Contents:\n\n modules\n ```\n\n1. Build Documentation\n\n Run the following command to build the documentation:\n\n ```bash\n # for html documentation\n sphinx-build -b html docs docs/_build\n\n # for pdf documentation (requires latex to be configured)\n sphinx-build -M latexpdf docs docs/_build\n ```\n\n The documentation will be generated in the `docs/_build` directory.\n\n</details>\n\n## Setuptools\n\n<details>\n\n<summary>Setup Setuptools for a New Project</summary>\n\n- Use **setuptools** to package your code.\n- Setuptools lets you easily download, build, install, upgrade, and uninstall Python packages.\n- Setuptools can be configured using the following files:\n - `setup.py`\n - `setup.cfg`\n- Setuptools lets you install your code using pip.\n\n ```bash\n pip install git+REPO_URL\n # or\n pip install .\n # or in editable mode\n pip install -e .\n ```\n\n- You can also save configurations for your project in the `setup.cfg` file.\n- Sample `setup.py` file:\n\n ```python\n from setuptools import setup, find_packages\n\n setup(\n name=\"project_name\",\n version=\"0.1.0\",\n description=\"Project description\",\n author=\"Author name\",\n author_email=\"Author email\",\n url=\"Project url\",\n license=\"License name\",\n # find_packages() finds all the packages in the src directory\n # package_dir={\"\": \"src\"} can be used to specify the source directory\n packages=find_packages(),\n # package_data={\"\": [\"data/*.txt\"]} can be used to include data files\n # the following command will include all txt files in the data directory\n # hence hardcoded paths in the code can be avoided and the code can be made more portable\n package_data={\"src\": [\"data/*.txt\"]},\n # install_requires can be used to specify the dependencies of the project\n # will be installed automatically when the project is installed \n install_requires=[\n \"package1\",\n \"package2\",\n ],\n # extras_require can be used to specify the dependencies of the project\n # will not be installed automatically when the project is installed\n extras_require={\n \"dev\": [\n \"package3\",\n \"package4\",\n ],\n },\n # entry_points can be used to specify the command line scripts\n entry_points={\n \"console_scripts\": [\n \"script_name=package.module:main\",\n ],\n },\n )\n ```\n\n- Check the [Setuptools documentation](https://setuptools.pypa.io/) for more information.\n\n</details>\n\n## Unit testing with Pytest\n\n<details>\n\n<summary>Setup Pytest for a New Project</summary>\n\n- Use **pytest** to write and run tests.\n- Unittesting makes sure that your code works as expected.\n- Pytest can automatically find and run tests in files named `test_*.py` or `*_test.py`.\n- Pytest can be run using the following command:\n\n ```bash\n pytest test_file.py\n # or\n python -m pytest test_file.py\n # or to run all tests in a directory 'tests'\n pytest tests/\n ```\n\n- Here is a sample test file:\n\n ```python\n import pytest\n\n def test_function():\n assert 1 == 1\n ```\n\n- Some sample tests can be found in the [tests](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/tree/main/tests).\n\n- Check the [Pytest documentation](https://docs.pytest.org/) for more information.\n\n- Use **coverage** to check the test coverage of your code.\n- Coverage identifies which parts of your code are executed during testing and reports can be generated that show which parts of your code are missed by the tests.\n- Coverage can be run using the following command:\n\n ```bash\n coverage run -m pytest file.py\n coverage report\n ```\n\n- Check the [Coverage documentation](https://coverage.readthedocs.io/) for more information.\n\n- **tox** can be used to run all the above tools in one command.\n- Tox creates a virtual environment for each Python version you want to test.\n- Tox can be run using the following command:\n\n ```bash\n tox\n ```\n\n- Configuration for tox can be specified in the following files:\n - `tox.ini`\n - `pyproject.toml`\n - `setup.cfg`\n\n- A sample tox configuration file:\n\n ```ini\n [tox]\n envlist = py{38,311} # specify the python versions to test\n\n [testenv]\n deps =\n pytest\n coverage\n commands =\n pytest\n coverage run -m pytest\n coverage report\n ```\n\n- Check the [Tox documentation](https://tox.readthedocs.io/) for more information.\n- Sample tox configuration files can be found in the [tox](https://gitlab.cc-asp.fraunhofer.de/babu/python-template/-/blob/main/tox.ini) directory.\n\n</details>\n\n## Code Quality Checks\n\n<details>\n\n<summary>Setup Code Quality Checks for a New Project</summary>\n\n### Pylint\n\n- Use **linters** to check your code for errors and style.\n- Pylint is one of the tools that can be used to lint your code.\n- [flake8](https://flake8.pycqa.org/) is another popular tool that can be used to lint your code.\n- Code can be linted using the following command:\n\n ```bash\n # recommended (pylint and flake8)\n pylint file.py\n # or\n flake8 file.py\n ```\n\n- Pylint can provide you with a score for your code. This score can be used to track the quality of your code and also be used to enforce a minimum score. In the template repository, the minimum score is set to 9.0. If the score is below 9.0, the CI pipeline will fail. This is done with the following command:\n\n ```bash\n pylint --fail-under=9 uam\n ```\n\n- It can be used to enforce a coding style, find bugs and unused code.\n- Check the [Pylint documentation](https://pylint.pycqa.org/en/stable/index.html) for more information.\n\n- [ruff](https://github.com/charliermarsh/ruff) can also be used to lint your code. ruff is based on rust is much faster than pylint and flake8.\n\n- Example with pylint:\n\n ```python\n # Example code test.py\n def calculate_average(numbers):\n total = sum(numbers)\n number_of_items = len(numbers)\n average = total / len(numbers)\n print(\"The average is:\", average)\n\n\n numbers = [1, 2, 3, 4, 5]\n calculate_average(numbers)\n ```\n\n ```bash\n pylint test.py\n # Output\n ************* Module example\n test.py:10:0: C0304: Final newline missing (missing-final-newline)\n test.py:1:0: C0114: Missing module docstring (missing-module-docstring)\n test.py:2:0: C0116: Missing function or method docstring (missing-function-docstring)\n test.py:2:22: W0621: Redefining name 'numbers' from outer scope (line 9) (redefined-outer-name)\n test.py:4:4: W0612: Unused variable 'number_of_items' (unused-variable)\n\n ------------------------------------------------------------------\n Your code has been rated at 2.86/10 (previous run: 4.29/10, -1.43)\n ```\n\n The same suggestions can be seen in VSCode as well once the extensions are installed.\n\n### Mypy\n\n- Use **type hints** to specify the type of variables and arguments.\n- Type hints are optional in Python, but they are recommended.\n- Type hints can be very useful for documentation and debugging.\n- Type hints are specified using the following syntax:\n\n ```python\n variable: type\n\n def function(argument: type) -> type:\n pass\n\n class Class:\n def method(self, argument: type) -> type:\n pass\n ```\n\n- Check the [PEP 484](https://www.python.org/dev/peps/pep-0484/) for more information.\n\n- Tools like [mypy](http://mypy-lang.org/) can be used to check your code for type errors.\n\n ```bash\n mypy file.py\n mypy src/\n ```\n\n- It is a static type checker that can identify type errors in your code.\n\n ```python\n def function(argument: int) -> int:\n return argument + \"1\"\n ```\n\n ```bash\n mypy file.py\n error: Unsupported operand types for + (\"int\" and \"str\")\n ```\n\n- Check the [Mypy documentation](http://mypy-lang.org/) for more information.\n\n- Example 1\n\n ```python\n # Example code test_1.py\n def add_numbers(a: int, b: int) -> int:\n return a + b\n\n result = add_numbers(5, \"10\") # Type mismatch: 'str' cannot be added to 'int'\n print(result)\n ```\n\n ```bash\n mypy test_1.py\n # Output\n test.py:5: error: Argument 2 to \"add_numbers\" has incompatible type \"str\"; expected \"int\" [arg-type]\n Found 1 error in 1 file (checked 1 source file)\n ```\n\n- Example 2\n\n ```python\n # Example code test_2.py\n import numpy as np\n\n def calculate_mean(data: np.ndarray) -> float:\n return np.mean(data)\n\n numbers = [1, 2, 3, 4, 5] # Incorrect type: List[int] instead of np.ndarray\n mean = calculate_mean(numbers)\n print(mean)\n ```\n\n ```bash\n mypy test_2.py\n # Output\n test.py:8: error: Argument 1 to \"calculate_mean\" has incompatible type \"List[int]\"; expected \"ndarray[Any, Any]\" [arg-type]\n Found 1 error in 1 file (checked 1 source file)\n ```\n\n- **You need to provide type hints for your code to be checked by mypy. Else it will not be able to check the type of the variables.**\n- Mypy will also check for type errors in third-party libraries.\n\n### Black\n\n- Use **black** to format your code.\n- Black lets you format your code in a consistent way.\n- Black can be run using the following command:\n\n ```bash\n black --check --diff file.py # will show the changes that will be made without making them\n # or\n black file.py # will format the file in place\n ```\n\n- It can be integrated with your editor to format your code on save.\n\n- Check the [Black documentation](https://black.readthedocs.io/) for more information.\n\n- Example:\n\n ```python\n # before\n def my_function():\n x=1\n y = 2\n z=3\n if x>y:\n print(\"x is greater than y\")\n else:\n print(\"y is greater than or equal to x\")\n ```\n\n <div align=\"center\">\n <font size=\"5\">\u2193</font>\n </div>\n\n ```python\n # after\n def my_function():\n x = 1\n y = 2\n z = 3\n if x > y:\n print(\"x is greater than y\")\n else:\n print(\"y is greater than or equal to x\")\n ```\n\n- Use **isort** to sort your imports.\n- Isort does sort import in the following order:\n - standard library imports\n - related third party imports\n - local application/library specific imports\n- Isort can be run using the following command:\n\n ```bash\n isort --check-only --diff file.py # will show the changes that will be made without making them\n # or\n isort file.py # will format the file in place\n ```\n\n- It can also be integrated with your editor to sort your imports on save.\n- Here is an example of how isort sorts imports:\n\n ```python\n # before\n import os\n import sys\n import django\n import requests\n import uam\n ```\n\n <div align=\"center\">\n <font size=\"5\">\u2193</font>\n </div>\n\n ```python\n # after\n import os\n import sys\n\n import django\n import requests\n\n import uam\n ```\n\n - Check the [Isort documentation](https://pycqa.github.io/isort/) for more information.\n\n</details>\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A sample project to demonstrate packaging and testing.",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://gitlab.cc-asp.fraunhofer.de/babu/python-template/"
},
"split_keywords": [
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8f6f2d6186b5c31e2131315a807044a1b8e62de90294202e7bbfc051d44ac0d7",
"md5": "b5603ca260b4869d75695fee862c4441",
"sha256": "60d542ef266141659a452afd0c54711aa05b07ca73ce030cb2b8cf43a05161e8"
},
"downloads": -1,
"filename": "sample_project_ivi-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b5603ca260b4869d75695fee862c4441",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7821,
"upload_time": "2024-03-15T15:24:41",
"upload_time_iso_8601": "2024-03-15T15:24:41.514667Z",
"url": "https://files.pythonhosted.org/packages/8f/6f/2d6186b5c31e2131315a807044a1b8e62de90294202e7bbfc051d44ac0d7/sample_project_ivi-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82e561b44e1ac8216fdeb27e87dc403e03a183e0677aa86ce4fb8bfcf498e67d",
"md5": "6302a740dbb64ffb3ba13784a58ca5e2",
"sha256": "936d453a722123307f48c22dad781721bde2e56d2581d132bff99a1906332d85"
},
"downloads": -1,
"filename": "sample_project_ivi-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "6302a740dbb64ffb3ba13784a58ca5e2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11208,
"upload_time": "2024-03-15T15:24:44",
"upload_time_iso_8601": "2024-03-15T15:24:44.413226Z",
"url": "https://files.pythonhosted.org/packages/82/e5/61b44e1ac8216fdeb27e87dc403e03a183e0677aa86ce4fb8bfcf498e67d/sample_project_ivi-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-15 15:24:44",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sample-project-ivi"
}