diff --git a/README.md b/README.md index 84215fb..277640a 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Python template with some awesome tools to quickstart a Python project with the industry best practices. It includes automatic generation of API documentation, tests using PyTest, code coverage, -ruff linting to enforce standardized Python coding and formatting, virtual environments using UV, workflow automation using Taskipy and a space optimized Dockerfile to kickstart your project and run tests using the power of Docker containers. +ruff linting to enforce standardized Python coding and formatting, virtual environments using uv, workflow automation using Taskipy and a space optimized Dockerfile to kickstart your project and run tests using the power of Docker containers. You only need to install [Cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/usage.html)! @@ -90,12 +90,13 @@ This Project depends on the following projects. cookiecutter https://github.com/nullhack/python-project-template # move into your newly created project folder ``` -2. Install UV and Taskipy +2. Install uv and Taskipy ```sh - pip install --user --upgrade uv taskipy + pip install --user --upgrade uv ``` 3. Let Taskipy do it's magic ```sh + uv venv uv pip install .[dev] uv task test uv task run @@ -162,6 +163,7 @@ This project was heavily based on some great references. * [5 Pytest Best Practices for Writing Great Python Tests](https://www.nerdwallet.com/blog/engineering/5-pytest-best-practices/) * [Best-README-Template](https://github.com/othneildrew/Best-README-Template) * [Beyond Hypermodern: Python is easy now (2024)](https://rdrn.me/postmodern-python/) +* [Pytest Best Practices](https://pytest-with-eric.com/)

(back to top)

diff --git a/{{cookiecutter.project_slug}}/.dockerignore b/{{cookiecutter.project_slug}}/.dockerignore new file mode 100644 index 0000000..8751745 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.dockerignore @@ -0,0 +1,174 @@ +.github + +DS_Store +.coverage +.vscode/\n.idea/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Remove html generated by documentation + +docs/html + +# Remove tests and coverage reports +docs/cov-report +docs/pytest_report.html + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index cd993e7..36bfc4f 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -113,7 +113,8 @@ Some useful examples of how this project can be used: * Install requirements ```sh - uv run task '.[dev]' + uv venv + uv pip install '.[dev]' ``` * Run tests @@ -123,7 +124,7 @@ Some useful examples of how this project can be used: * Run the project ```sh - uv run main.py + uv run task run ``` * Generate API documentation diff --git a/{{cookiecutter.project_slug}}/docs/mkdocs.yaml b/{{cookiecutter.project_slug}}/docs/mkdocs.yaml index d86b542..f96048c 100644 --- a/{{cookiecutter.project_slug}}/docs/mkdocs.yaml +++ b/{{cookiecutter.project_slug}}/docs/mkdocs.yaml @@ -27,8 +27,18 @@ theme: palette: - media: '(prefers-color-scheme: light)' scheme: default - primary: blue + primary: indigo accent: amber + toggle: + icon: material/toggle-switch-off-outline + name: Switch to dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + primary: indigo + accent: amber + toggle: + icon: material/toggle-switch + name: Switch to light mode atures: - search.suggest - search.highlight diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 5af9d23..d36a6a2 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -76,17 +76,23 @@ pydocstyle.convention = "google" [tool.pytest.ini_options] minversion = "6.0" +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", + "unit", + "integration", + "system", + "acceptance", + "regression", + "smoke", + "sanity", + "performance", + "security", + "performance", +] addopts = """ --maxfail=1 \ --color=yes \ ---cov={{cookiecutter.package_name}} \ ---html=docs/pytest_report.html \ ---self-contained-html \ ---cov-fail-under={{cookiecutter.minimum_coverage}} \ ---cov-report term-missing \ ---cov-report html:docs/cov-report \ ---doctest-modules \ ---cov-config=pyproject.toml""" +""" testpaths = [ "tests", "{{cookiecutter.package_name}}" @@ -110,7 +116,22 @@ exclude_lines = [ [tool.taskipy.tasks] run = "python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}" -test = "pytest" +test-report = """\ +pytest \ + --cov-config=pyproject.toml \ + --doctest-modules \ + --cov-fail-under=90 \ + --cov-report=term-missing \ + --cov-report=html:docs/cov-report \ + --html=docs/pytest_report.html \ + --self-contained-html\ +""" +test = """\ +python -c "import subprocess, sys; print('Running Smoke Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'smoke']).returncode in (0,5) else 1)" && \ +python -c "import subprocess, sys; print('Running Unit Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'unit']).returncode in (0,5) else 1)" && \ +python -c "print('Running Tests...');" && \ +task test-report\ +""" ruff-check = "ruff check **/*.py --fix" ruff-format = "ruff format **/*.py" lint = "task ruff-check && task ruff-format"