From 5ef6acacc2614a2f66ef61bf685345710f7ecbb3 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Fri, 9 Feb 2024 14:24:05 +0000 Subject: [PATCH 1/3] Fix packaging issues - Don't include wheel as a build dep - Fix readme path in wheel, add a test that catches this --- docs/how-to/make-release.md | 2 +- pyproject.toml | 2 +- template/pyproject.toml.jinja | 4 ++-- tests/test_example.py | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/how-to/make-release.md b/docs/how-to/make-release.md index 9402cb3fa..dd7cbbfc9 100644 --- a/docs/how-to/make-release.md +++ b/docs/how-to/make-release.md @@ -2,7 +2,7 @@ To make a new release, please follow this checklist: -- Ensure that you have previously followed `./pypi` +- Ensure that you have previously followed [](./pypi) - Choose a new PEP440 compliant release number (see ) - Go to the GitHub [release] page - Choose `Draft New Release` diff --git a/pyproject.toml b/pyproject.toml index 86ef30ed8..25ba95f2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"] +requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" [project] diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 49ea22fda..3f2c5091b 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"] +requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" [project] @@ -19,7 +19,7 @@ dependencies = [ ] # Add project dependencies here, e.g. ["click", "numpy"] dynamic = ["version"] license.file = "LICENSE" -readme = "README.rst" +readme = "README.md" requires-python = ">=3.7" [project.optional-dependencies] diff --git a/tests/test_example.py b/tests/test_example.py index e2801b5b8..e1e471440 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -44,6 +44,9 @@ def test_template(tmp_path: Path): run(f"python -m venv {venv_path}") run(f"{venv_path}/bin/python -m pip install -e .[dev]") run(f"{venv_path}/bin/tox -p") + run(f"{venv_path}/bin/python -m pip install build twine") + run(f"{venv_path}/bin/python -m build") + run(f"{venv_path}/bin/python -m twine check --strict dist/*") def test_bad_repo_name(tmp_path: Path): From 6abb935d39182bcd05f886d9b9e8b849d1a6c3d2 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Fri, 9 Feb 2024 14:51:46 +0000 Subject: [PATCH 2/3] Remove docs tox env if sphinx not selected Also add a test for this Fixes #57 --- template/README.md.jinja | 5 +++-- template/pyproject.toml.jinja | 12 ++++++------ tests/test_example.py | 31 +++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/template/README.md.jinja b/template/README.md.jinja index 586f6ee8e..88d8ac040 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -11,7 +11,7 @@ how it does it, and why people should use it. Source | <{{repo_url}}> :---: | :---: PyPI | `pip install {{pypi_name}}` -Documentation | <{{docs_url}}> +{% if sphinx %}Documentation | <{{docs_url}}>{% endif %} Releases | <{{repo_url}}/releases> This is where you should put some images or code snippets that illustrate @@ -29,7 +29,8 @@ Or if it is a commandline tool then you might put some example commands here: ``` python -m {{package_name}} --version ``` - +{% if sphinx %} See {{docs_url}} for more detailed documentation. +{% endif %} \ No newline at end of file diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 3f2c5091b..f2331f9f9 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -61,7 +61,7 @@ reportMissingImports = false # Ignore missing stubs in imported modules [tool.pytest.ini_options] # Run pytest with all our checkers, and don't spam us with massive tracebacks on error addopts = """ - --tb=native -vv --doctest-modules --doctest-glob="*.rst" + --tb=native -vv{% if sphinx %} --doctest-modules --doctest-glob="*.rst"{% endif %} """ # https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings filterwarnings = "error" @@ -82,7 +82,7 @@ legacy_tox_ini = """ [tox] skipsdist=True -[testenv:{pre-commit,pyright,pytest,docs}] +[testenv:{pre-commit,pyright,pytest{% if sphinx %},docs{% endif %}}] # Don't create a virtualenv for the command, requires tox-direct plugin direct = True passenv = * @@ -90,14 +90,14 @@ allowlist_externals = pytest pre-commit pyright - sphinx-build +{% if sphinx %} sphinx-build sphinx-autobuild -commands = +{% endif %}commands = pytest: pytest --cov={{ package_name }} --cov-report term --cov-report xml:cov.xml {posargs} pyright: pyright src tests {posargs} pre-commit: pre-commit run --all-files {posargs} - docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html -""" +{% if sphinx %} docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html +{% endif %}""" [tool.ruff] src = ["src", "tests"] diff --git a/tests/test_example.py b/tests/test_example.py index e1e471440..8688b5e34 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -36,17 +36,28 @@ def run_pipe(cmd: str, cwd=None): return output -def test_template(tmp_path: Path): - project_path = tmp_path / "project" - venv_path = tmp_path / "venv" - copy_project(project_path) +def make_venv(project_path: Path) -> callable: + venv_path = project_path / "venv" + run_pipe(f"python -m venv {venv_path}") run = functools.partial(run_pipe, cwd=str(project_path)) - run(f"python -m venv {venv_path}") - run(f"{venv_path}/bin/python -m pip install -e .[dev]") - run(f"{venv_path}/bin/tox -p") - run(f"{venv_path}/bin/python -m pip install build twine") - run(f"{venv_path}/bin/python -m build") - run(f"{venv_path}/bin/python -m twine check --strict dist/*") + run(f"./venv/bin/pip install -e .[dev]") + return run + + +def test_template(tmp_path: Path): + copy_project(tmp_path) + run = make_venv(tmp_path) + run(f"./venv/bin/tox -p") + run(f"./venv/bin/pip install build twine") + run(f"./venv/bin/python -m build") + run(f"./venv/bin/twine check --strict dist/*") + + +def test_template_no_docs(tmp_path: Path): + copy_project(tmp_path, docs_type="README") + run = make_venv(tmp_path) + run(f"./venv/bin/tox -p") + def test_bad_repo_name(tmp_path: Path): From 5213b93273681cc0700e52eb03a7d5cbc4b54465 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Fri, 9 Feb 2024 15:03:05 +0000 Subject: [PATCH 3/3] Lint and make sure we install pre-commit --- .devcontainer/devcontainer.json | 2 +- tests/test_example.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f82edd0f7..79b85ff41 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,5 +42,5 @@ // Mount the parent as /workspaces so we can pip install peers as editable "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", // After the container is created, install the python project in editable form - "postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]'" + "postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install" } \ No newline at end of file diff --git a/tests/test_example.py b/tests/test_example.py index 8688b5e34..0c9a8632b 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -40,24 +40,23 @@ def make_venv(project_path: Path) -> callable: venv_path = project_path / "venv" run_pipe(f"python -m venv {venv_path}") run = functools.partial(run_pipe, cwd=str(project_path)) - run(f"./venv/bin/pip install -e .[dev]") + run("./venv/bin/pip install -e .[dev]") return run def test_template(tmp_path: Path): copy_project(tmp_path) run = make_venv(tmp_path) - run(f"./venv/bin/tox -p") - run(f"./venv/bin/pip install build twine") - run(f"./venv/bin/python -m build") - run(f"./venv/bin/twine check --strict dist/*") + run("./venv/bin/tox -p") + run("./venv/bin/pip install build twine") + run("./venv/bin/python -m build") + run("./venv/bin/twine check --strict dist/*") def test_template_no_docs(tmp_path: Path): copy_project(tmp_path, docs_type="README") run = make_venv(tmp_path) - run(f"./venv/bin/tox -p") - + run("./venv/bin/tox -p") def test_bad_repo_name(tmp_path: Path):