From 213795675c726d3717c79355d126084105450cbf Mon Sep 17 00:00:00 2001 From: Pablo Hernandez-Cerdan Date: Wed, 25 Oct 2023 11:21:01 +0200 Subject: [PATCH] Init repo using copier From https://github.com/innolitics/python_project_template --- .github/dependabot.yml | 12 ++++++ .github/workflows/black.yml | 10 +++++ .github/workflows/ruff.yml | 8 ++++ .pre-commit-config.yaml | 55 +++++++++++++++++++++++++ CONTRIBUTING.md | 33 +++++++++++++++ README.md | 8 ++++ mdai_utils/__init__.py | 0 mdai_utils/delme.py | 6 +++ pyproject.toml | 81 +++++++++++++++++++++++++++++++++++++ requirements-dev.in | 8 ++++ requirements-dev.txt | 69 +++++++++++++++++++++++++++++++ requirements.in | 0 requirements.txt | 6 +++ tests/delme_test.py | 15 +++++++ 14 files changed, 311 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/black.yml create mode 100644 .github/workflows/ruff.yml create mode 100644 .pre-commit-config.yaml create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 mdai_utils/__init__.py create mode 100644 mdai_utils/delme.py create mode 100644 pyproject.toml create mode 100644 requirements-dev.in create mode 100644 requirements-dev.txt create mode 100644 requirements.in create mode 100644 requirements.txt create mode 100644 tests/delme_test.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..199b1c4 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" # Location of requirements.txt + schedule: + interval: "weekly" + day: "sunday" + # Disable version updates, only allow security updates + open-pull-requests-limit: 0 diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..9065b5e --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,10 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: psf/black@stable diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..563b87d --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,8 @@ +name: Ruff +on: [push, pull_request] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: chartboost/ruff-action@v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a2f3414 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,55 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: check-case-conflict + - id: debug-statements + - id: detect-private-key + - id: check-added-large-files + args: ["--maxkb=1000"] + - id: end-of-file-fixer + - id: trailing-whitespace + + # ruff-pre-commit should be placed after black, isort. + # In case of enabling auto fix, it should be placed before other formatting tools. + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.0.289 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + args: [--target-version=py310] + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0 + hooks: + - id: prettier + types: [yaml] + + - repo: https://github.com/jazzband/pip-tools + rev: 7.3.0 + hooks: + - id: pip-compile + name: pip-compile requirements.in + args: [requirements.in] + files: ^requirements\.(in|txt)$ + - id: pip-compile + name: pip-compile requirements-dev.in + args: [requirements-dev.in] + files: ^requirements-dev\.(in|txt)$ + + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.327 + hooks: + - id: pyright diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d2409e0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Setting up the development environment + +1. Create a new virtual environment and activate it: + ```bash + python -m venv .venv + source .venv/bin/activate + ``` +2. Install development packages (linters, etc.): + ```bash + pip install -r requirements-dev.txt + ``` +3. Install pre-commit hooks: + ```bash + pre-commit install + ``` + +# Dependency management + +[pip-tools](https://pypi.org/project/pip-tools/) is used to keep requirements +pinned properly. + +Define requirements as usual in the `requirements-*.in` files and +`pip-compile` will generate the corresponding txt file. E.g., +`pip-compile requirements-dev.in` will generate requirements-dev.txt. + +Both `.in` and `.txt` files will be tracked by git, and +they are synced with a pre-commit hook (i.e., `pip-compile` is run +automatically during each commit). + +To install the dependencies, use `pip-sync`, e.g., +```bash +pip-sync requirements-dev.txt` +``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9d5e37 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# mdai-utils + +Utility functions for MD.ai + +# Development + +For information about building, running, and contributing to this code base, +please read the [CONTRIBUTING](CONTRIBUTING.md) page. diff --git a/mdai_utils/__init__.py b/mdai_utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mdai_utils/delme.py b/mdai_utils/delme.py new file mode 100644 index 0000000..97a6f68 --- /dev/null +++ b/mdai_utils/delme.py @@ -0,0 +1,6 @@ +def main(): + print("This file is here to test linters and formatters.") + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9a6cbde --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,81 @@ +[project] +name = "mdai-utils" +description = "Utility functions for MD.ai" +requires-python = ">= 3.10" +version = "0.0.1" +dynamic = ["dependencies", "optional-dependencies"] + +authors = [ + { name = "Pablo Hernandez-Cerdan", email = "pablo.hernandez.cerdan@outlook.com" }, +] + + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.in"]} +optional-dependencies = {dev = { file = ["requirements-dev.in"] }} + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[tool.isort] +profile = "black" + +[tool.ruff] +# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E", "F"] +ignore = [] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] +per-file-ignores = {} + +# Same as Black. +line-length = 88 + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Assume Python 3.10. +target-version = "py310" + +[tool.pyright] +# For pre-commit to work. See contributing.md#pre-commit +venvPath = "." +venv = ".venv" + +exclude = ["**/node_modules", + "**/__pycache__", +] +defineConstant = { DEBUG = true } + +pythonVersion = "3.10" +strict = true diff --git a/requirements-dev.in b/requirements-dev.in new file mode 100644 index 0000000..4259070 --- /dev/null +++ b/requirements-dev.in @@ -0,0 +1,8 @@ +black>=23.7.0 +isort>=5.12.0 +pre-commit>=3.4 +pip-tools>=7.3.0 +build>=1.0.3 +pyright>=1.1.327 +ruff>=0.0.289 +pytest>=7.4 diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..6b1984e --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,69 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile requirements-dev.in +# +black==23.9.1 + # via -r requirements-dev.in +build==1.0.3 + # via + # -r requirements-dev.in + # pip-tools +cfgv==3.4.0 + # via pre-commit +click==8.1.7 + # via + # black + # pip-tools +distlib==0.3.7 + # via virtualenv +filelock==3.12.4 + # via virtualenv +identify==2.5.28 + # via pre-commit +iniconfig==2.0.0 + # via pytest +isort==5.12.0 + # via -r requirements-dev.in +mypy-extensions==1.0.0 + # via black +nodeenv==1.8.0 + # via + # pre-commit + # pyright +packaging==23.1 + # via + # black + # build + # pytest +pathspec==0.11.2 + # via black +pip-tools==7.3.0 + # via -r requirements-dev.in +platformdirs==3.10.0 + # via + # black + # virtualenv +pluggy==1.3.0 + # via pytest +pre-commit==3.4.0 + # via -r requirements-dev.in +pyproject-hooks==1.0.0 + # via build +pyright==1.1.327 + # via -r requirements-dev.in +pytest==7.4.2 + # via -r requirements-dev.in +pyyaml==6.0.1 + # via pre-commit +ruff==0.0.289 + # via -r requirements-dev.in +virtualenv==20.24.5 + # via pre-commit +wheel==0.41.2 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..985906d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile requirements.in +# diff --git a/tests/delme_test.py b/tests/delme_test.py new file mode 100644 index 0000000..b3bff50 --- /dev/null +++ b/tests/delme_test.py @@ -0,0 +1,15 @@ +import pytest + +from mdai_utils.delme import main + + +@pytest.fixture +def setup(): + print("setup") + yield + print("teardown") + + +def test_delme(setup): + main() + assert True