Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc docs and CI cleanup #59

Merged
merged 1 commit into from
Oct 28, 2024
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
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade hatch uv
# FIXME: Link checking temporarily disabled https://github.com/Archmonger/ServeStatic/issues/42
- name: Check documentation links
if: false
run: |
hatch run docs:linkcheck
- name: Check docs build
Expand Down Expand Up @@ -192,7 +190,7 @@ jobs:
with:
python-version: 3.x
cache: pip
- name: Install dependecies
- name: Install dependencies
run: |
pip install --upgrade hatch uv
- name: Configure Git
Expand All @@ -208,6 +206,7 @@ jobs:
run: |
hatch run docs:deploy_latest ${{ github.ref_name }}

# This workflow relies on the user manually creating a "stub release" on GitHub with the correct version number in the tag.
publish-github:
name: Publish GitHub Release
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ repos:
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.2.4"
hooks:
- id: pyproject-fmt
- repo: https://github.com/asottile/pyupgrade
rev: "v3.17.0"
hooks:
Expand Down
3 changes: 1 addition & 2 deletions docs/src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ By utilizing `hatch`, the following commands are available to manage the develop
| `hatch fmt --formatter` | Run only formatters |
| `hatch run precommit:check` | Run all [`pre-commit`](https://pre-commit.com/) checks configured within this repository |
| `hatch run precommit:update` | Update the [`pre-commit`](https://pre-commit.com/) hooks configured within this repository |
| `hatch run pyproject:format` | Format the `pyproject.toml` file using [`pyproject-fmt`](https://github.com/tox-dev/pyproject-fmt) |

??? tip "Configure your IDE for linting"

Expand All @@ -70,6 +69,6 @@ By utilizing `hatch`, the following commands are available to manage the develop

??? tip "Check out Hatch for all available commands!"

This documentation only covers commonly used commands for ServeStatic.
This documentation only covers commonly used commands.

You can type `hatch --help` to see all available commands.
2 changes: 1 addition & 1 deletion docs/src/wsgi.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ application.add_files("/path/to/more/static/files", prefix="more-files/")

<!--shared-desc-start-->

On initialization, `ServeStatic` walks over all the files in the directories that have been added (descending into sub-directories) and builds a list of available static files. Any requests which match a static file get served by `ServeStatic`, all others are passed through to the original WSGI application.
On initialization, `ServeStatic` walks over all the files in the directories that have been added (descending into sub-directories) and builds a list of available static files. Any requests which match a static file get served by `ServeStatic`, all others are passed through to the original application.

<!--shared-desc-end-->

Expand Down
80 changes: 35 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[build-system]
build-backend = "hatchling.build"
requires = [ "hatchling" ]
requires = ["hatchling"]

[project]
name = "servestatic"
description = "Production-grade static file server for Python web apps."
readme = "README.md"
keywords = [ "asgi", "django", "http", "server", "static", "staticfiles", "wsgi" ]
keywords = ["asgi", "django", "http", "server", "static", "staticfiles", "wsgi"]
license = "MIT"
authors = [ { name = "Mark Bakhit" } ]
authors = [{ name = "Mark Bakhit" }]
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -21,64 +21,65 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Communications :: File Sharing",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware",
]
dynamic = [ "version" ]
optional-dependencies.brotli = [ "brotli" ]
dynamic = ["version"]
optional-dependencies.brotli = ["brotli"]
urls.Changelog = "https://archmonger.github.io/ServeStatic/latest/changelog/"
urls.Documentation = "https://archmonger.github.io/ServeStatic/"
urls.Homepage = "https://github.com/Archmonger/ServeStatic"
urls.Source = "https://github.com/Archmonger/ServeStatic"

[tool.hatch.version]
path = "src/servestatic/__init__.py"

[tool.hatch.build.targets.sdist]
include = [ "/src" ]
include = ["/src"]

[tool.hatch.metadata]
license-files = { paths = [ "LICENSE.md" ] }
license-files = { paths = ["LICENSE.md"] }

[tool.hatch.envs.default]
installer = "uv"

# >>> Hatch Tests <<<
# >>> Hatch Test Suite <<<

[tool.hatch.envs.hatch-test]
extra-dependencies = [ "pytest-sugar", "requests", "brotli" ]
extra-dependencies = ["pytest-sugar", "requests", "brotli"]
randomize = true
matrix-name-format = "{variable}-{value}"

# Django 3.2
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.9", "3.10" ]
django = [ "3.2" ]
python = ["3.9", "3.10"]
django = ["3.2"]

# Django 4.0
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.9", "3.10" ]
django = [ "4.0" ]
python = ["3.9", "3.10"]
django = ["4.0"]

# Django 4.1
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.9", "3.10", "3.11" ]
django = [ "4.1" ]
python = ["3.9", "3.10", "3.11"]
django = ["4.1"]

# Django 4.2
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.9", "3.10", "3.11", "3.12" ]
django = [ "4.2" ]
python = ["3.9", "3.10", "3.11", "3.12"]
django = ["4.2"]

# Django 5.0
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.10", "3.11", "3.12" ]
django = [ "5.0" ]
python = ["3.10", "3.11", "3.12"]
django = ["5.0"]

# Django 5.1
[[tool.hatch.envs.hatch-test.matrix]]
python = [ "3.10", "3.11", "3.12", "3.13" ]
django = [ "5.1" ]
python = ["3.10", "3.11", "3.12", "3.13"]
django = ["5.1"]

[tool.hatch.envs.hatch-test.overrides]
matrix.django.dependencies = [
Expand All @@ -102,7 +103,7 @@ matrix.django.dependencies = [
], value = "django~=5.1" },
]

# >>> Hatch Documentation <<<
# >>> Hatch Documentation Scripts <<<

[tool.hatch.envs.docs]
template = "docs"
Expand All @@ -120,44 +121,33 @@ dependencies = [
]

[tool.hatch.envs.docs.scripts]
serve = [ "cd docs && mkdocs serve" ]
build = [ "cd docs && mkdocs build --strict" ]
serve = ["cd docs && mkdocs serve"]
build = ["cd docs && mkdocs build --strict"]
linkcheck = [
"linkcheckMarkdown docs/ -v -r",
"linkcheckMarkdown README.md -v -r",
"linkcheckMarkdown CHANGELOG.md -v -r",
]
deploy_latest = [ "cd docs && mike deploy --push --update-aliases {args} latest" ]
deploy_develop = [ "cd docs && mike deploy --push develop" ]
deploy_latest = ["cd docs && mike deploy --push --update-aliases {args} latest"]
deploy_develop = ["cd docs && mike deploy --push develop"]

# >>> Hatch pre-commit <<<

[tool.hatch.envs.precommit]
template = "pre-commit"
detached = true
dependencies = [ "pre-commit>=3,<4" ]
dependencies = ["pre-commit>=3,<4"]

[tool.hatch.envs.precommit.scripts]
check = [ "pre-commit run --all-files" ]
update = [ "pre-commit autoupdate" ]

# >>> Hatch pyproject-format <<<

[tool.hatch.envs.pyproject]
template = "pyproject"
detached = true
dependencies = [ "pyproject-fmt" ]

[tool.hatch.envs.pyproject.scripts]
format = [ "pyproject-fmt pyproject.toml" ]
check = ["pre-commit run --all-files"]
update = ["pre-commit autoupdate"]

# >>> Generic Tools <<<

[tool.black]
target-version = [ "py39" ]

[tool.ruff]
line-length = 120
extend-exclude = [".eggs/*", ".nox/*", ".venv/*", "build/*"]

format.preview = true
lint.extend-ignore = [
"ARG001", # Unused function argument
Expand All @@ -180,10 +170,10 @@ addopts = """\
[tool.coverage.run]
branch = true
parallel = true
source = [ "src/", "tests/" ]
source = ["src/", "tests/"]

[tool.coverage.paths]
source = [ "src/" ]
source = ["src/"]

[tool.coverage.report]
show_missing = true
19 changes: 15 additions & 4 deletions scripts/validate_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
GITHUB_RELEASE_TAG_URL_RE = GITHUB_RELEASE_TAG_URL_START_RE + r"([\w.]+)"
UNRELEASED_HEADER = "## [Unreleased]\n"
VERSION_HEADER_START_RE = r"## \[([\w.]+)\]"
VERSION_HEADER_FULL_RE = VERSION_HEADER_START_RE + r" - \d{4}-\d{2}-\d{2}\n"
VERSION_HEADER_FULL_RE = VERSION_HEADER_START_RE + r" - (\d{4}-\d{2}-\d{2})\n"
UNRELEASED_HYPERLINK_RE = r"\[Unreleased\]: " + GITHUB_COMPARE_URL_RE + r"\n"
VERSION_HYPERLINK_START_RE = r"\[([\w.]+)\]: "
VERSION_HYPERLINK_RE = VERSION_HYPERLINK_START_RE + GITHUB_COMPARE_URL_RE + r"\n"
Expand Down Expand Up @@ -61,9 +61,11 @@ def validate_changelog(changelog_path="CHANGELOG.md"):
f"The hyperlink for [Unreleased] was expected to contain '{previous_version[1]}' but instead found '{previous_version_linked_in_unreleased}'"
)

# Gather all version headers. Note that the 'Unreleased' hyperlink is validated separately.
# Gather info from version headers. Note that the 'Unreleased' hyperlink is validated separately.
versions_from_headers = re.findall(VERSION_HEADER_START_RE, changelog)
versions_from_headers = [header for header in versions_from_headers if header != "Unreleased"]
dates_from_headers = re.findall(VERSION_HEADER_FULL_RE, changelog)
dates_from_headers = [header[1] for header in dates_from_headers if header[0] != "Unreleased"]

# Ensure each version header has a hyperlink
for version in versions_from_headers:
Expand Down Expand Up @@ -144,6 +146,14 @@ def validate_changelog(changelog_path="CHANGELOG.md"):
f"Found '{versions_from_hyperlinks[position]}' in hyperlinks but expected '{version}'"
)

# Ensure the release dates are in descending order
for position, date in enumerate(dates_from_headers):
if position == len(dates_from_headers) - 1:
break

if date < dates_from_headers[position + 1]:
errors.append(f"Header with date '{date}' should be listed before '{dates_from_headers[position + 1]}'")

# Check if the user is using something other than <Added||Changed||Deprecated||Removed||Fixed||Security>
section_headers = re.findall(SECTION_HEADER_RE, changelog)
for header in section_headers:
Expand Down Expand Up @@ -190,6 +200,7 @@ def validate_changelog(changelog_path="CHANGELOG.md"):
or not changelog_header_and_bullet_lines[position + 1].startswith("-")
):
errors.append(f"Section '{line}' in version '{current_version}' is missing bullet points")

return errors


Expand All @@ -202,10 +213,10 @@ def validate_changelog(changelog_path="CHANGELOG.md"):

errors = validate_changelog()
if errors:
print("Changelog has formatting errors!")
print("Changelog has formatting errors!")
for error in errors:
print(f" - {error}")
sys.exit(1)

print("Changelog is valid!")
print("Changelog is valid!")
sys.exit(0)