diff --git a/.flake8 b/.flake8 index ecb802a..9d578eb 100644 --- a/.flake8 +++ b/.flake8 @@ -10,4 +10,4 @@ ignore = D203,W503,W504 max-complexity = 12 max-line-length = 120 per-file-ignores = - app/__init__.py : E501 + tests/utils/app.py : E501 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a8755a7..a015092 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,12 +25,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install build twine - name: Build and publish env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} run: | - python setup.py sdist bdist_wheel + python -m build twine upload dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21a692f..8ea1e27 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,9 @@ jobs: - name: Get package version id: package_version - run: echo "python=$(python setup.py --version)" >> $GITHUB_OUTPUT + run: | + python -m pip install -e . + echo "python=$(python -c 'import importlib.metadata; print(importlib.metadata.version("ccs-digitalmarketplace-frontend-jinja"))')" >> $GITHUB_OUTPUT - name: Check if version tag already exists id: version_tag diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 409b30e..1f34e0f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,18 +1,20 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks +--- repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: d6d3bd94604578adbd918c5a00d531d98350d86f # v2.3.0 - hooks: - - id: detect-private-key -- repo: https://github.com/Yelp/detect-secrets - rev: a3e7998bfa4924b13df3f9cb49070abdbdff8802 # v0.13.1 - hooks: - - id: detect-secrets - args: ['--baseline', '.secrets.baseline'] - exclude: .*/keys/.*| - (?x)( - ^package-lock.json$/| - ^Pipfile/| - ^pyproject.toml - ) +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: detect-private-key + +- repo: https://github.com/abravalheri/validate-pyproject + rev: v0.22 + hooks: + - id: validate-pyproject + +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b1d2f..78a5006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Records breaking changes from major version bumps. ## Unreleased +Replace `setup.py` with `pyproject.toml` + ## 2.10.0 Upgrade Digital Marketplace Frontend to v1.3.1 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1eeef06 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +prune tests diff --git a/README.md b/README.md index 3eaa980..9b2b739 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,11 @@ To make a new version: When the pull request is merged a GitHub Action will tag the new version. +## Pre-commit hooks + +This project has a [pre-commit hook][pre-commit hook] to do some general file checks and check the `pyproject.toml`. +Follow the [Quick start][pre-commit quick start] to see how to set this up in your local checkout of this project. + ## Licence Unless stated otherwise, the codebase is released under [the MIT License][mit]. @@ -105,3 +110,6 @@ of the [Open Government 3.0][ogl] licence. [mit]: LICENCE [copyright]: http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/ [ogl]: http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/ + +[pre-commit hook]: https://pre-commit.com/ +[pre-commit quick start]: https://pre-commit.com/#quick-start diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9bc2ab2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "ccs-digitalmarketplace-frontend-jinja" +dynamic = ["version"] +dependencies = [ + 'jinja2>3', + 'ccs-govuk-frontend-jinja>=1.4,<2', + 'ccs-digitalmarketplace-utils>=68.0.0', +] +requires-python = ">=3.10,<3.13" +authors = [ + {name = "CCS Developers"}, +] +description = "Jinja templates for Digital Marketplace apps." +readme = "README.md" +license = {file = "LICENSE"} + +[project.urls] +Homepage = "https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-frontend-jinja" +Repository = "https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-frontend-jinja.git" +Issues = "https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-frontend-jinja/issues" +Changelog = "https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-frontend-jinja/CHANGELOG.md" + +[tool.setuptools.dynamic] +version = {attr = "digitalmarketplace_frontend_jinja.__version__"} + +[tool.setuptools.packages.find] +exclude = ["node_modules*"] + +[tool.setuptools.package-data] +digitalmarketplace_frontend_jinja = ["**/*.html"] diff --git a/requirements-dev.txt b/requirements-dev.txt index 8ceebf7..b65a336 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -18,11 +18,11 @@ botocore==1.34.142 # s3transfer cachelib==0.13.0 # via flask-session -ccs-digitalmarketplace-apiclient==25.11.0 +ccs-digitalmarketplace-apiclient==27.3.0 # via ccs-digitalmarketplace-utils -ccs-digitalmarketplace-utils==68.0.0 +ccs-digitalmarketplace-utils==68.1.0 # via ccs-digitalmarketplace-frontend-jinja -ccs-govuk-frontend-jinja==1.3.0 +ccs-govuk-frontend-jinja==1.4.0 # via ccs-digitalmarketplace-frontend-jinja certifi==2024.7.4 # via requests @@ -47,6 +47,7 @@ flake8==7.1.1 flask==3.0.3 # via # -r requirements-dev.in + # ccs-digitalmarketplace-apiclient # ccs-digitalmarketplace-utils # flask-gzip # flask-login diff --git a/setup.py b/setup.py deleted file mode 100644 index eaa9f6d..0000000 --- a/setup.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -Jinja templates for Digital Marketplace apps. -""" -import re -import ast -import glob -import os -from setuptools import setup, find_packages - - -_version_re = re.compile(r'__version__\s+=\s+(.*)') - -with open('digitalmarketplace_frontend_jinja/__init__.py', 'rb') as f: - version = str(ast.literal_eval(_version_re.search(f.read().decode('utf-8')).group(1))) - -components = [] -directories = glob.glob("digitalmarketplace_frontend_jinja/**/**/*.html", recursive=True) -for directory in directories: - components.append(os.path.relpath(os.path.dirname(directory), "digitalmarketplace_frontend_jinja") + "/*.html") - -setup( - name='ccs-digitalmarketplace-frontend-jinja', - version=version, - url='https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja', - license='MIT', - author='CCS', - description='Jinja templates for Digital Marketplace apps.', - long_description=__doc__, - packages=find_packages(), - package_data={'digitalmarketplace_frontend_jinja': components}, - include_package_data=True, - install_requires=[ - 'jinja2>3', - 'ccs-govuk-frontend-jinja>=1.2,<2', - 'ccs-digitalmarketplace-utils>=67.0.0', - ], - python_requires=">=3.10,<3.13", -) diff --git a/tasks.py b/tasks.py index 5a7fa21..144016c 100644 --- a/tasks.py +++ b/tasks.py @@ -6,7 +6,7 @@ @task(ns["virtualenv"], ns["requirements_dev"]) def test_mypy(c): - c.run("mypy app/") + c.run("mypy tests/utils/") ns.add_task(npm_install) diff --git a/tests/conftest.py b/tests/conftest.py index a0f5baf..15e8986 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ import pytest -from app import create_app +from utils.app import create_app @pytest.fixture diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/__init__.py b/tests/utils/app.py similarity index 97% rename from app/__init__.py rename to tests/utils/app.py index 771add3..76602f1 100644 --- a/app/__init__.py +++ b/tests/utils/app.py @@ -28,7 +28,7 @@ def create_app(): "digitalmarketplace_frontend_jinja": FileSystemLoader( searchpath=os.path.join( os.path.dirname(__file__), - "../digitalmarketplace_frontend_jinja/templates" + "../../digitalmarketplace_frontend_jinja/templates" ) ) } diff --git a/app/templates/_base_page.html b/tests/utils/templates/_base_page.html similarity index 100% rename from app/templates/_base_page.html rename to tests/utils/templates/_base_page.html