Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ All pull requests must:

Follow the patterns seen in the code. Walk where others have walked.

The majority of code style nits will be met when passing `pre-commit` checks
prior to submitting a pull request.
Be sure to run the expected formatters and linters prior to opening the PR.

### Tests

Expand Down Expand Up @@ -70,22 +69,22 @@ package, and installs all dependency files.
nox -s dev
```

### Run tests with coverage (quick)
### Run tests with coverage

```console
nox -e coverage
nox -s test
```

### Run tests (slow)
### Run formatters and linters

```console
nox
nox -s lint
```

### Build dist

```console
nox -e build
nox -s build
```

---
Expand Down Expand Up @@ -119,9 +118,3 @@ nox -s upgrade-deps

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.

---

## Error: File "setup.py" not found

Update `pip` to at least version 22.3.1
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ fit.

- **Q:** Why not put the requirements into the `pyproject.toml`?
- **A:** Mostly because `pip-compile` does all the work for me and doesn't
target the `pyproject.toml`. Partly because many of my projects need to be
scanned by utilities that still think `requirements.txt` is the only pattern
to use.
target the `pyproject.toml` dependency groups yet.

- **Q:** Why does this template change so often?
- **A:** I'm constantly finding new tweaks that make the template fit just a
Expand All @@ -39,7 +37,3 @@ fit.

- **Q:** Have I heard of uv?
- **A:** Yes. I'm already exploring a uv driven workflow for this template.
You can see it on the `uv-workflow` branch. I will be waiting until the
April 2025 release of pip for support of
[dependency-groups](https://packaging.python.org/en/latest/specifications/dependency-groups/)
before committing to any changes.
28 changes: 12 additions & 16 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
MODULE_NAME = "module_name"
TESTS_PATH = "tests"
COVERAGE_FAIL_UNDER = 50
DEFAULT_PYTHON = "3.12"
VENV_PATH = "./.venv"
LINT_PATH = "./src"
REQUIREMENTS_PATH = "./requirements"
Expand All @@ -37,33 +36,31 @@
nox.options.sessions = ["lint", "test"]


@nox.session(python=False)
@nox.session()
def dev(session: nox.Session) -> None:
"""Setup a development environment by creating the venv and installs dependencies."""
# Use the active environement if it exists, otherwise create a new one
venv_path = os.environ.get("VIRTUAL_ENV", VENV_PATH)

if sys.platform == "win32":
py_command = "py"
venv_path = f"{venv_path}/Scripts"
activate_command = f"{venv_path}/activate"
else:
py_command = f"python{DEFAULT_PYTHON}"
venv_path = f"{venv_path}/bin"
activate_command = f"source {venv_path}/activate"

if not os.path.exists(VENV_PATH):
session.run(py_command, "-m", "venv", VENV_PATH, "--upgrade-deps")
session.run("python", "-m", "venv", VENV_PATH, "--upgrade-deps")

python = f"{venv_path}/python"
requirement_files = get_requirement_files()
python = partial(session.run, f"{venv_path}/python", "-m")

session.run(python, "-m", "pip", "install", "-e", ".")
requirement_files = get_requirement_files()
for requirement_file in requirement_files:
session.run(python, "-m", "pip", "install", "-r", requirement_file)
python("pip", "install", "-r", requirement_file, external=True)
python("pip", "install", "--editable", ".", external=True)

session.run(python, "-m", "pip", "install", "pre-commit")
session.run(f"{venv_path}/pre-commit", "install")
python("pip", "install", "pre-commit", external=True)
session.run(f"{venv_path}/pre-commit", "install", external=True)

if not os.environ.get("VIRTUAL_ENV"):
session.log(f"\n\nRun '{activate_command}' to enter the virtual environment.\n")
Expand All @@ -74,8 +71,7 @@ def run_tests_with_coverage(session: nox.Session) -> None:
"""Run pytest with coverage, outputs console report and json."""
print_standard_logs(session)

session.install(".")
session.install("-r", f"{REQUIREMENTS_PATH}/requirements-test.txt")
session.install(".", "-r", f"{REQUIREMENTS_PATH}/requirements-test.txt")

coverage = partial(session.run, "python", "-m", "coverage")

Expand Down Expand Up @@ -129,7 +125,7 @@ def run_linters_and_formatters(session: nox.Session) -> None:
python("mypy", "--no-incremental", "--package", MODULE_NAME)


@nox.session(python=DEFAULT_PYTHON)
@nox.session()
def build(session: nox.Session) -> None:
"""Build distribution files."""
print_standard_logs(session)
Expand All @@ -138,7 +134,7 @@ def build(session: nox.Session) -> None:
session.run("python", "-m", "build")


@nox.session(python=DEFAULT_PYTHON, name="update-deps")
@nox.session(name="update-deps")
def update_deps(session: nox.Session) -> None:
"""Process requirement*.txt files, updating only additions/removals."""
print_standard_logs(session)
Expand All @@ -156,7 +152,7 @@ def update_deps(session: nox.Session) -> None:
)


@nox.session(python=DEFAULT_PYTHON, name="upgrade-deps")
@nox.session(name="upgrade-deps")
def upgrade_deps(session: nox.Session) -> None:
"""Process requirement*.txt files and upgrade all libraries as possible."""
print_standard_logs(session)
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "module-name"
requires-python = ">=3.9"
version = "0.1.0"
description = "Module Description"
readme = "README.md"
license = { file = "LICENSE" }
Expand All @@ -19,17 +20,13 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
]
dynamic = ["version"]

[project.urls]
homepage = "https://github.com/[ORG NAME]/[REPO NAME]"

# [project.scripts]
# python-src-example = "module_name.sample:main"

[tool.setuptools_scm]
# Purposely left empty

[tool.setuptools.package-data]
"module_name" = ["py.typed"]

Expand Down