From 2d4c3bf79db425294c50b0110915d1e7789613dc Mon Sep 17 00:00:00 2001 From: Oliver Mannion <125105+tekumara@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:58:25 +1000 Subject: [PATCH] Revert "feat: make setuptools_scm optional and non-default" This reverts commit b8be71b9237751ab2d7ae62fa719742db82e2fe2. --- .pre-commit-config.yaml | 9 +- README.md | 1 - cookiecutter.json | 3 +- snapshots/default.yaml | 1 - snapshots/default/pyproject.toml | 8 +- snapshots/setuptools-scm.yaml | 6 -- snapshots/setuptools-scm/.gitignore | 18 ---- .../setuptools-scm/.pre-commit-config.yaml | 36 -------- snapshots/setuptools-scm/.python-version | 1 - snapshots/setuptools-scm/CONTRIBUTING.md | 23 ----- snapshots/setuptools-scm/Makefile | 3 - snapshots/setuptools-scm/Makefile-common.mk | 70 --------------- snapshots/setuptools-scm/README.md | 9 -- .../setuptools-scm/mypackage/__init__.py | 0 snapshots/setuptools-scm/mypackage/main.py | 9 -- snapshots/setuptools-scm/mypackage/py.typed | 1 - snapshots/setuptools-scm/package.json | 5 -- snapshots/setuptools-scm/pyproject.toml | 87 ------------------- snapshots/setuptools-scm/tests/__init__.py | 0 .../setuptools-scm/tests/test_example.py | 2 - {{cookiecutter.repo_name}}/pyproject.toml | 13 +-- 21 files changed, 14 insertions(+), 291 deletions(-) delete mode 100644 snapshots/setuptools-scm.yaml delete mode 100644 snapshots/setuptools-scm/.gitignore delete mode 100644 snapshots/setuptools-scm/.pre-commit-config.yaml delete mode 100644 snapshots/setuptools-scm/.python-version delete mode 100644 snapshots/setuptools-scm/CONTRIBUTING.md delete mode 100644 snapshots/setuptools-scm/Makefile delete mode 100644 snapshots/setuptools-scm/Makefile-common.mk delete mode 100644 snapshots/setuptools-scm/README.md delete mode 100644 snapshots/setuptools-scm/mypackage/__init__.py delete mode 100644 snapshots/setuptools-scm/mypackage/main.py delete mode 100644 snapshots/setuptools-scm/mypackage/py.typed delete mode 100644 snapshots/setuptools-scm/package.json delete mode 100644 snapshots/setuptools-scm/pyproject.toml delete mode 100644 snapshots/setuptools-scm/tests/__init__.py delete mode 100644 snapshots/setuptools-scm/tests/test_example.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ca557d..19fddbc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,10 @@ # unless otherwise specified, hooks run on push only default_stages: [push] repos: - # disabled because {{cookiecutter.repo_name}}/pyproject.toml is jinja not valid toml - # - repo: https://github.com/crate-ci/typos - # rev: v1.23.2 - # hooks: - # - id: typos + - repo: https://github.com/crate-ci/typos + rev: v1.23.2 + hooks: + - id: typos # formatters and linters are available in the virtualenv so they can be run from the makefile & vscode - repo: local hooks: diff --git a/README.md b/README.md index cafdb36..c5a561a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ The template will ask for the following: - `package_name`: The name of your main python package. A python package is a group of modules, ie: a directory with _\_\_init\_\_.py_ file. Choose a short all-lowercase name without hyphens. The use of underscores is discouraged (see [PEP8](https://www.python.org/dev/peps/pep-0008/#package-and-module-names)). - [`project_name`](https://www.python.org/dev/peps/pep-0508/#names): The name of the artifact when your project is built as a wheel or source distribution (aka sdist). Project names are lowered kebab-case. In most cases the package name and project name will be the same. This is used in _pyproject.toml_ and needed even if you aren't building a wheel or sdist. - `description`: a one line description of your project. -- `setuptools_scm`: use setuptools_scm to derive the version from git tags. Versions are calculated from the git repo state as per [Default versioning scheme](https://github.com/pypa/setuptools_scm/blob/main/docs/usage.md#default-versioning-scheme). ## Getting started diff --git a/cookiecutter.json b/cookiecutter.json index f581ed2..9fa318a 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -2,6 +2,5 @@ "repo_name": "repo-name", "package_name": "{{ cookiecutter.repo_name|replace('-', '') }}", "project_name": "{{ cookiecutter.repo_name }}", - "description": "one line description of your project", - "setuptools_scm": ["False", "True"] + "description": "one line description of your project" } diff --git a/snapshots/default.yaml b/snapshots/default.yaml index 4f4af46..9ccde9b 100644 --- a/snapshots/default.yaml +++ b/snapshots/default.yaml @@ -3,4 +3,3 @@ default_context: package_name: "mypackage" project_name: "my-project" description: "example cookie rendered from the template" - setuptools_scm: "False" diff --git a/snapshots/default/pyproject.toml b/snapshots/default/pyproject.toml index 88930af..83a52ee 100644 --- a/snapshots/default/pyproject.toml +++ b/snapshots/default/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "my-project" description = "example cookie rendered from the template" -version = "0.0.0" +dynamic = ["version"] readme = "README.md" requires-python = ">=3.11" dependencies = [] @@ -16,12 +16,16 @@ dev = [ ] [build-system] -requires = ["setuptools~=69.1", "wheel~=0.42"] +requires = ["setuptools~=69.1", "setuptools_scm~=8.0", "wheel~=0.42"] [tool.setuptools.packages.find] where = ["."] exclude = ["tests*", "node_modules*", "build*"] +# enable setuptools_scm to set the version based on git tags +[tool.setuptools_scm] +fallback_version = "0.0.0" + [tool.pyright] venvPath = "." venv = ".venv" diff --git a/snapshots/setuptools-scm.yaml b/snapshots/setuptools-scm.yaml deleted file mode 100644 index 466392d..0000000 --- a/snapshots/setuptools-scm.yaml +++ /dev/null @@ -1,6 +0,0 @@ -default_context: - repo_name: "setuptools-scm" - package_name: "mypackage" - project_name: "my-project" - description: "example cookie rendered from the template with setuptools_scm" - setuptools_scm: "True" diff --git a/snapshots/setuptools-scm/.gitignore b/snapshots/setuptools-scm/.gitignore deleted file mode 100644 index 7829ca5..0000000 --- a/snapshots/setuptools-scm/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -.eggs/ -.idea/ -.vscode/ -*.code-workspace -*.iml -.pytest_cache/ -__pycache__/ -.mypy_cache/ -*.egg-info -build/ -dist/ -.DS_Store -typings/ -.tox/ -pip-wheel-metadata/ -node_modules/ -.venv/ -.env diff --git a/snapshots/setuptools-scm/.pre-commit-config.yaml b/snapshots/setuptools-scm/.pre-commit-config.yaml deleted file mode 100644 index dc5cf09..0000000 --- a/snapshots/setuptools-scm/.pre-commit-config.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# unless otherwise specified, hooks run on push only -default_stages: [push] -repos: - - repo: https://github.com/crate-ci/typos - rev: v1.23.2 - hooks: - - id: typos - # formatters and linters are available in the virtualenv so they can be run from the makefile & vscode - - repo: local - hooks: - - id: ruff - name: ruff - entry: .venv/bin/ruff check --force-exclude - language: system - types: [python] - require_serial: true - - id: ruff-format - name: ruff-format - entry: .venv/bin/ruff format - language: system - types: [python] - require_serial: true - - id: pyright - name: pyright - entry: node_modules/.bin/pyright - # run on all files to catch type errors that affect unchanged files - pass_filenames: false - language: system - types: [python] - - id: test - name: test - entry: .venv/bin/pytest - # run on all files - pass_filenames: false - language: system - types: [python] diff --git a/snapshots/setuptools-scm/.python-version b/snapshots/setuptools-scm/.python-version deleted file mode 100644 index 2c07333..0000000 --- a/snapshots/setuptools-scm/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.11 diff --git a/snapshots/setuptools-scm/CONTRIBUTING.md b/snapshots/setuptools-scm/CONTRIBUTING.md deleted file mode 100644 index a5ccf05..0000000 --- a/snapshots/setuptools-scm/CONTRIBUTING.md +++ /dev/null @@ -1,23 +0,0 @@ -# Contributing 🌳 - -## Prerequisites - -- make -- node (required for pyright) -- python >= 3.11 - -## Getting started - -`make install` creates the dev environment with: - -- a virtualenv in _.venv/_ -- pyright in _node_modules/_ -- git hooks for formatting & linting on git push - -`. .venv/bin/activate` activates the virtualenv. - -The make targets will update the virtualenv when _pyproject.toml_ changes. - -## Usage - -Run `make` to see the options for running tests, linting, formatting etc. diff --git a/snapshots/setuptools-scm/Makefile b/snapshots/setuptools-scm/Makefile deleted file mode 100644 index bda312d..0000000 --- a/snapshots/setuptools-scm/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -include *.mk - -# add additional targets here diff --git a/snapshots/setuptools-scm/Makefile-common.mk b/snapshots/setuptools-scm/Makefile-common.mk deleted file mode 100644 index c7688aa..0000000 --- a/snapshots/setuptools-scm/Makefile-common.mk +++ /dev/null @@ -1,70 +0,0 @@ -MAKEFLAGS += --warn-undefined-variables -SHELL = /bin/bash -o pipefail -.DEFAULT_GOAL := help -.PHONY: help clean install format check pyright test dist hooks install-hooks - -## display help message -help: - @awk '/^##.*$$/,/^[~\/\.0-9a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?##"}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | sort - -venv ?= .venv -# this is a symlink so we set the --check-symlink-times makeflag above -python := $(venv)/bin/python -# use uv if present, else fall back to pip -pip = $(shell command -v uv >/dev/null && echo "uv pip" || echo "$(venv)/bin/pip") - -$(python): $(if $(value CI),|,) .python-version -# create venv using system python even when another venv is active - PATH=$${PATH#$${VIRTUAL_ENV}/bin:} python3 -m venv --clear $(venv) - $(python) --version - $(pip) install --upgrade pip~=24.0 - -$(venv): $(if $(value CI),|,) pyproject.toml $(python) - $(pip) install -e '.[dev]' - touch $(venv) - -node_modules: package.json - npm install --no-save - touch node_modules - -# delete the venv -clean: - rm -rf $(venv) - -## create venv and install this package and hooks -install: $(venv) node_modules $(if $(value CI),,install-hooks) - -## format, lint and type check -check: export SKIP=test -check: hooks - -## format and lint -format: export SKIP=pyright,test -format: hooks - -## pyright type check -pyright: node_modules $(venv) - node_modules/.bin/pyright - -## run tests -test: $(venv) - $(venv)/bin/pytest - -## build python distribution -dist: $(venv) - # start with a clean slate (see setuptools/#2347) - rm -rf dist *.egg-info - $(venv)/bin/python -m build --sdist --wheel - -## publish to pypi -publish: $(venv) - $(venv)/bin/twine upload dist/* - -## run pre-commit git hooks on all files -hooks: node_modules $(venv) - $(venv)/bin/pre-commit run --color=always --all-files --hook-stage push - -install-hooks: .git/hooks/pre-push - -.git/hooks/pre-push: $(venv) - $(venv)/bin/pre-commit install --install-hooks -t pre-push diff --git a/snapshots/setuptools-scm/README.md b/snapshots/setuptools-scm/README.md deleted file mode 100644 index d6111d1..0000000 --- a/snapshots/setuptools-scm/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# my-project - -[![ci](../../actions/workflows/ci.yml/badge.svg)](../../actions/workflows/ci.yml) - -example cookie rendered from the template with setuptools_scm - -## Contributing - -See [CONTRIBUTING.md](CONTRIBUTING.md) to get started and develop in this repo. diff --git a/snapshots/setuptools-scm/mypackage/__init__.py b/snapshots/setuptools-scm/mypackage/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/snapshots/setuptools-scm/mypackage/main.py b/snapshots/setuptools-scm/mypackage/main.py deleted file mode 100644 index 0928088..0000000 --- a/snapshots/setuptools-scm/mypackage/main.py +++ /dev/null @@ -1,9 +0,0 @@ -import sys - - -def main(args: list[str] = sys.argv[1:]) -> None: - print(f"hello {args[0]}!") - - -if __name__ == "__main__": - main() diff --git a/snapshots/setuptools-scm/mypackage/py.typed b/snapshots/setuptools-scm/mypackage/py.typed deleted file mode 100644 index 1031418..0000000 --- a/snapshots/setuptools-scm/mypackage/py.typed +++ /dev/null @@ -1 +0,0 @@ -# when type checking dependents, tell type checkers to use this package's types diff --git a/snapshots/setuptools-scm/package.json b/snapshots/setuptools-scm/package.json deleted file mode 100644 index 923913b..0000000 --- a/snapshots/setuptools-scm/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "devDependencies": { - "pyright": "1.1.369" - } -} diff --git a/snapshots/setuptools-scm/pyproject.toml b/snapshots/setuptools-scm/pyproject.toml deleted file mode 100644 index d269fdb..0000000 --- a/snapshots/setuptools-scm/pyproject.toml +++ /dev/null @@ -1,87 +0,0 @@ -[project] -name = "my-project" -description = "example cookie rendered from the template with setuptools_scm" -dynamic = ["version"] -readme = "README.md" -requires-python = ">=3.11" -dependencies = [] - -[project.optional-dependencies] -dev = [ - "build~=1.0", - "pre-commit~=3.4", - "pytest~=8.0", - "ruff~=0.5.1", - "twine~=5.0", -] - -[build-system] -requires = ["setuptools~=69.1", "setuptools_scm~=8.0", "wheel~=0.42"] - -[tool.setuptools.packages.find] -where = ["."] -exclude = ["tests*", "node_modules*", "build*"] - -# enable setuptools_scm to set the version based on git tags -[tool.setuptools_scm] -fallback_version = "0.0.0" - -[tool.pyright] -venvPath = "." -venv = ".venv" -exclude = ["**/node_modules", "**/__pycache__", "**/.*", "build"] -strictListInference = true -strictDictionaryInference = true -strictParameterNoneValue = true -reportTypedDictNotRequiredAccess = false -reportIncompatibleVariableOverride = true -reportIncompatibleMethodOverride = true -reportMatchNotExhaustive = true -reportUnnecessaryTypeIgnoreComment = true - -[tool.ruff] -line-length = 120 -# first-party imports for sorting -src = ["."] -fix = true -show-fixes = true - -[tool.ruff.lint] -# rules to enable/ignore -select = [ - "F", # pyflakes - "E", # pycodestyle - "W", # pycodestyle - "ANN", # type annotations - "N", # pep8-naming - "B", # bugbear - "I", # isort - "ARG", # flake8-unused-arguments - "SLF", # flake8-self - "UP", # pyupgrade - "PERF", # perflint - "RUF", # ruff-specific - "SIM", # flake8-simplify - "S113", # request-without-timeout -] -ignore = [ - # allow untyped self and cls args - "ANN101", - "ANN102", - # allow no return type from dunder methods - "ANN204", - # allow == True because pandas dataframes overload equality - "E712", -] - -[tool.ruff.lint.isort] -combine-as-imports = true -force-wrap-aliases = true - -[tool.ruff.lint.per-file-ignores] -# test functions don't need return types -"tests/*" = ["ANN201", "ANN202"] - -[tool.ruff.lint.flake8-annotations] -# allow *args: Any, **kwargs: Any -allow-star-arg-any = true diff --git a/snapshots/setuptools-scm/tests/__init__.py b/snapshots/setuptools-scm/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/snapshots/setuptools-scm/tests/test_example.py b/snapshots/setuptools-scm/tests/test_example.py deleted file mode 100644 index 21b7c4f..0000000 --- a/snapshots/setuptools-scm/tests/test_example.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_example(): - assert 1 == 1 diff --git a/{{cookiecutter.repo_name}}/pyproject.toml b/{{cookiecutter.repo_name}}/pyproject.toml index 06f2eab..e1be01a 100644 --- a/{{cookiecutter.repo_name}}/pyproject.toml +++ b/{{cookiecutter.repo_name}}/pyproject.toml @@ -1,11 +1,7 @@ [project] name = "{{cookiecutter.project_name}}" description = "{{cookiecutter.description}}" -{%- if cookiecutter.setuptools_scm == "True" %} dynamic = ["version"] -{% else %} -version = "0.0.0" -{% endif -%} readme = "README.md" requires-python = ">=3.11" dependencies = [] @@ -20,19 +16,16 @@ dev = [ ] [build-system] -{%- if cookiecutter.setuptools_scm == "True" %} requires = ["setuptools~=69.1", "setuptools_scm~=8.0", "wheel~=0.42"] -{% else %} -requires = ["setuptools~=69.1", "wheel~=0.42"] -{% endif %} + [tool.setuptools.packages.find] where = ["."] exclude = ["tests*", "node_modules*", "build*"] -{% if cookiecutter.setuptools_scm == "True" %} + # enable setuptools_scm to set the version based on git tags [tool.setuptools_scm] fallback_version = "0.0.0" -{% endif %} + [tool.pyright] venvPath = "." venv = ".venv"