From fa29d42112dff291d88ba8c2dd1d79419de76bfc Mon Sep 17 00:00:00 2001 From: Preocts Date: Fri, 22 Mar 2024 21:23:47 -0400 Subject: [PATCH] Pin dev requirements, drop makefile Pinning just means it's more likely to work on your machine --- Makefile | 41 --------- README.md | 136 +++++++++++++++-------------- pyproject.toml | 24 ++--- requirements/requirements-dev.in | 15 ++++ requirements/requirements-dev.txt | 59 +++++++++++++ requirements/requirements-test.in | 14 +++ requirements/requirements-test.txt | 36 ++++++++ requirements/requirements.in | 6 ++ requirements/requirements.txt | 6 ++ 9 files changed, 216 insertions(+), 121 deletions(-) delete mode 100644 Makefile create mode 100644 requirements/requirements-dev.in create mode 100644 requirements/requirements-dev.txt create mode 100644 requirements/requirements-test.in create mode 100644 requirements/requirements-test.txt create mode 100644 requirements/requirements.in create mode 100644 requirements/requirements.txt diff --git a/Makefile b/Makefile deleted file mode 100644 index 109e9cc..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -.PHONY: init -init: - python -m pip install --upgrade pip - -.PHONY: install -install: - python -m pip install --upgrade . - -.PHONY: install-dev -install-dev: - python -m pip install --editable .[dev,test] - pre-commit install - -# Optional: use requirements.in to manage requirements -# Use optional dynamic field in pyproject.toml -# .PHONY: upgrade-dev -# upgrade-dev: -# python -m pip install pip-tools -# pip-compile --upgrade -# python -m pip install --upgrade --editable .[dev,test] - -.PHONY: build-dist -build-dist: - python -m pip install --upgrade build - python -m build - -.PHONY: clean -clean: - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '__pycache__' -exec rm -rf {} + - find . -name '.mypy_cache' -exec rm -rf {} + - rm -rf .tox - rm -f coverage.xml - rm -f coverage.json - rm -rf htmlcov - rm -rf .coverage - rm -rf .coverage.* - find . -name '.pytest_cache' -exec rm -rf {} + - rm -rf dist - rm -rf build diff --git a/README.md b/README.md index ff4061d..982beae 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,24 @@ closing=0 # Local developer installation -It is **strongly** recommended to use a virtual environment -([`venv`](https://docs.python.org/3/library/venv.html)) when working with python -projects. Leveraging a `venv` will ensure the installed dependency files will -not impact other python projects or any system dependencies. +The following steps outline how to install this repo for local development. -The following steps outline how to install this repo for local development. See -the [CONTRIBUTING.md](CONTRIBUTING.md) file in the repo root for information on -contributing to the repo. +## Prerequisites + +### Clone repo + +```console +git clone https://github.com/Precots/commented-configparser + +cd commented-configparser +``` + +### Virtual Environment + +Use a ([`venv`](https://docs.python.org/3/library/venv.html)), or equivalent, +when working with python projects. Leveraging a `venv` will ensure the installed +dependency files will not impact other python projects or any system +dependencies. **Windows users**: Depending on your python install you will use `py` in place of `python` to create the `venv`. @@ -129,94 +139,105 @@ the desired version while creating the `venv`. (e.g. `python3` or `python3.8`) `python` for command line instructions. This will ensure you are using the `venv`'s python and not the system level python. ---- - -## Installation steps - -Clone this repo and enter root directory of repo: +### Create the `venv`: ```console -$ git clone https://github.com/Preocts/commented-configparser -$ cd commented-configparser -``` - -Create the `venv`: - -```console -$ python -m venv venv +python -m venv venv ``` Activate the `venv`: ```console # Linux/Mac -$ . venv/bin/activate +. venv/bin/activate # Windows -$ venv\Scripts\activate +venv\Scripts\activate ``` The command prompt should now have a `(venv)` prefix on it. `python` will now call the version of the interpreter used to create the `venv` -Install editable library and development requirements: +To deactivate (exit) the `venv`: + +```console +deactivate +``` + +--- + +## Developer Installation Steps + +### Install editable library and development requirements ```console -# Update pip and tools -$ python -m pip install --upgrade pip +python -m pip install --editable .[dev,test] +``` + +### Install pre-commit [(see below for details)](#pre-commit) -# Install editable version of library -$ python -m pip install --editable .[dev] +```console +pre-commit install ``` -Install pre-commit [(see below for details)](#pre-commit): +### Install with nox + +If you have `nox` installed with `pipx` or in the current venv you can use the +following session. This is an alternative to the two steps above. ```console -$ pre-commit install +nox -s install ``` --- -## Misc Steps +## Pre-commit and nox tools -Run pre-commit on all files: +### Run pre-commit on all files ```console -$ pre-commit run --all-files +pre-commit run --all-files ``` -Run tests: +### Run tests with coverage (quick) ```console -$ tox [-r] [-e py3x] +nox -e coverage ``` -Build dist: +### Run tests (slow) ```console -$ python -m pip install --upgrade build - -$ python -m build +nox ``` -To deactivate (exit) the `venv`: +### Build dist ```console -$ deactivate +nox -e build ``` + --- -## Note on flake8: +## Updating dependencies -`flake8` is included in the `requirements-dev.txt` of the project. However it -disagrees with `black`, the formatter of choice, on max-line-length and two -general linting errors. `.pre-commit-config.yaml` is already configured to -ignore these. `flake8` doesn't support `pyproject.toml` so be sure to add the -following to the editor of choice as needed. +New dependencys can be added to the `requirements-*.in` file. It is recommended +to only use pins when specific versions or upgrades beyond a certain version are +to be avoided. Otherwise, allow `pip-compile` to manage the pins in the +generated `requirements-*.txt` files. -```ini ---ignore=W503,E203 ---max-line-length=88 +Once updated following the steps below, the package can be installed if needed. + +### Update the generated files with changes + +```console +nox -e update +``` + +### Upgrade all generated dependencies + +```console +nox -e upgrade ``` --- @@ -227,22 +248,9 @@ following to the editor of choice as needed. This repo is setup with a `.pre-commit-config.yaml` with the expectation that any code submitted for review already passes all selected pre-commit checks. -`pre-commit` is installed with the development requirements and runs seemlessly -with `git` hooks. --- -## Makefile - -This repo has a Makefile with some quality of life scripts if the system -supports `make`. Please note there are no checks for an active `venv` in the -Makefile. +## Error: File "setup.py" not found -| PHONY | Description | -| ------------- | -------------------------------------------------------------------------- | -| `init` | Update pip to newest version | -| `install` | install the project | -| `install-dev` | install development/test requirements and project as editable install | -| `upgrade-dev` | update all dependencies, regenerate requirements.txt (disabled by default) | -| `build-dist` | Build source distribution and wheel distribution | -| `clean` | Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts | +Update `pip` to at least version 22.3.1 diff --git a/pyproject.toml b/pyproject.toml index afbf960..af4893a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,23 +21,15 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython" ] -dependencies = [] +# Dynamic dependencies are loaded from requirements*.txt files +dynamic = ["dependencies", "optional-dependencies"] -[project.optional-dependencies] -dev = [ - "pre-commit", - "black", - "mypy", - "flake8", - "flake8-builtins", - "flake8-pep585", -] -test = [ - "pytest", - "pytest-randomly", - "coverage", - "nox" -] +[tool.setuptools.dynamic.dependencies] +file = ["requirements/requirements.txt"] + +[tool.setuptools.dynamic.optional-dependencies] +dev = { file = ["requirements/requirements-dev.txt"] } +test = { file = ["requirements/requirements-test.txt"] } [project.urls] homepage = "https://github.com/Preocts/commented-configparser" diff --git a/requirements/requirements-dev.in b/requirements/requirements-dev.in new file mode 100644 index 0000000..e59aac0 --- /dev/null +++ b/requirements/requirements-dev.in @@ -0,0 +1,15 @@ +# Development Requirements - linting, formatting, etc. +# Ensure to set PIP_INDEX_URL to the correct value for your environment +# This is the URL to the Artifactory instance that hosts the Python packages (default: pypi.org) +# This will not be emitted to the requirements*.txt files and must be set in the environment +# before running pip install + +# Constrain versions installed to be compatible with core dependencies +--constraint requirements.txt + +pre-commit +black +mypy +flake8 +flake8-builtins +flake8-pep585 diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt new file mode 100644 index 0000000..4716e51 --- /dev/null +++ b/requirements/requirements-dev.txt @@ -0,0 +1,59 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --no-emit-index-url requirements/requirements-dev.in +# +black==24.3.0 + # via -r requirements/requirements-dev.in +cfgv==3.4.0 + # via pre-commit +click==8.1.7 + # via black +distlib==0.3.8 + # via virtualenv +filelock==3.13.1 + # via virtualenv +flake8==7.0.0 + # via + # -r requirements/requirements-dev.in + # flake8-builtins +flake8-builtins==2.2.0 + # via -r requirements/requirements-dev.in +flake8-pep585==0.1.7 + # via -r requirements/requirements-dev.in +identify==2.5.35 + # via pre-commit +mccabe==0.7.0 + # via flake8 +mypy==1.9.0 + # via -r requirements/requirements-dev.in +mypy-extensions==1.0.0 + # via + # black + # mypy +nodeenv==1.8.0 + # via pre-commit +packaging==24.0 + # via black +pathspec==0.12.1 + # via black +platformdirs==4.2.0 + # via + # black + # virtualenv +pre-commit==3.6.2 + # via -r requirements/requirements-dev.in +pycodestyle==2.11.1 + # via flake8 +pyflakes==3.2.0 + # via flake8 +pyyaml==6.0.1 + # via pre-commit +typing-extensions==4.10.0 + # via mypy +virtualenv==20.25.1 + # via pre-commit + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/requirements/requirements-test.in b/requirements/requirements-test.in new file mode 100644 index 0000000..bb87f28 --- /dev/null +++ b/requirements/requirements-test.in @@ -0,0 +1,14 @@ +# Testing Requirements +# ---------------------------------------- +# Ensure to set PIP_INDEX_URL to the correct value for your environment +# This is the URL to the Artifactory instance that hosts the Python packages (default: pypi.org) +# This will not be emitted to the requirements*.txt files and must be set in the environment +# before running pip install + +# Constrain versions installed to be compatible with core dependencies +--constraint requirements.txt + +pytest +pytest-randomly +coverage +nox diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt new file mode 100644 index 0000000..a18fdce --- /dev/null +++ b/requirements/requirements-test.txt @@ -0,0 +1,36 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --no-emit-index-url requirements/requirements-test.in +# +argcomplete==3.2.3 + # via nox +colorlog==6.8.2 + # via nox +coverage==7.4.4 + # via -r requirements/requirements-test.in +distlib==0.3.8 + # via virtualenv +filelock==3.13.1 + # via virtualenv +iniconfig==2.0.0 + # via pytest +nox==2024.3.2 + # via -r requirements/requirements-test.in +packaging==24.0 + # via + # nox + # pytest +platformdirs==4.2.0 + # via virtualenv +pluggy==1.4.0 + # via pytest +pytest==8.1.1 + # via + # -r requirements/requirements-test.in + # pytest-randomly +pytest-randomly==3.15.0 + # via -r requirements/requirements-test.in +virtualenv==20.25.1 + # via nox diff --git a/requirements/requirements.in b/requirements/requirements.in new file mode 100644 index 0000000..e17206f --- /dev/null +++ b/requirements/requirements.in @@ -0,0 +1,6 @@ +# Core Dependencies +# ----------------- +# Ensure to set PIP_INDEX_URL to the correct value for your environment +# This is the URL to the Artifactory instance that hosts the Python packages (default: pypi.org) +# This will not be emitted to the requirements*.txt files and must be set in the environment +# before running pip install diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..110ef67 --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1,6 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --no-emit-index-url requirements/requirements.in +#