Skip to content

Commit

Permalink
chore: enable hatch static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
hartungstenio committed Jul 11, 2024
1 parent 15cb73c commit f2ac93b
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 94 deletions.
15 changes: 5 additions & 10 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"image": "mcr.microsoft.com/devcontainers/python:3",
"features": {
"ghcr.io/devcontainers-contrib/features/hatch:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/devcontainers-contrib/features/ruff:1": {}
},

"forwardPorts": [],
Expand All @@ -13,27 +14,21 @@
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"github.vscode-github-actions",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.python",
"redhat.vscode-yaml",
"tamasfe.even-better-toml"
],
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"isort.args": [
"--profile",
"black"
]
}
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
name: lint
static-analysis:
name: static analysis
runs-on: ubuntu-latest
env:
HATCH_ENV: lint
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Hatch
run: pipx install hatch

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Run linters
run: |
hatch env run lint
- name: Setup Hatch
run: pipx install hatch

- name: Run static analysis
run: hatch fmt --check

test:
name: Run tests
Expand All @@ -50,9 +47,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Setup Hatch
run: |
pipx install hatch
run: pipx install hatch

- name: Run tests
run: |
hatch env run -i py=${{ matrix.python-version }} test
run: hatch env run -i py=${{ matrix.python-version }} test
11 changes: 2 additions & 9 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
[envs.lint]
detached = true
dependencies = ["pre-commit"]

[envs.lint.env-vars]
SKIP = "no-commit-to-branch"

[envs.lint.scripts]
lint = "pre-commit run -a -v"
[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"

[envs.test.env-vars]
DJANGO_SETTINGS_MODULE = "tests.settings"
Expand Down
6 changes: 3 additions & 3 deletions pwa/templatetags/pwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.safestring import mark_safe

from .. import app_settings
from pwa import app_settings

register = template.Library()


@register.filter(is_safe=True)
def js(obj):
"""Transform a python object so it can be safely used in javascript/JSON."""
return mark_safe(json.dumps(obj, cls=DjangoJSONEncoder))
return mark_safe(json.dumps(obj, cls=DjangoJSONEncoder)) # noqa: S308


@register.inclusion_tag("pwa.html", takes_context=True)
def progressive_web_app_meta(context):
def progressive_web_app_meta(context): # noqa: ARG001
# Pass all PWA_* settings into the template
return {
setting_name: getattr(app_settings, setting_name)
Expand Down
5 changes: 2 additions & 3 deletions pwa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
from . import app_settings


def service_worker(request):
def service_worker(request): # noqa: ARG001
with open(app_settings.PWA_SERVICE_WORKER_PATH) as serviceworker_file:
response = HttpResponse(
return HttpResponse(
serviceworker_file.read(),
content_type="application/javascript",
)
return response


def manifest(request):
Expand Down
111 changes: 56 additions & 55 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "django-pwa"
version = "1.1.0"
description = "A Django app to include a manifest.json and Service Worker instance to enable progressive web app behavior"
readme = "README.md"
license = { file = "LICENSE" }
authors = [{ name = "Silvio Luis", email = "[email protected]" }]
maintainers = [{ name = "Christian Hartung", email = "[email protected]" }]
classifiers = [
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
]
requires-python = ">=3.8"
dependencies = ["django>=3.2"]

[project.urls]
Repository = "http://github.com/silviolleite/django-pwa"

[tool.hatch.build.targets.sdist]
packages = ["/pwa", "/tests"]

[tool.hatch.build.targets.wheel]
packages = ["/pwa"]

[tool.black]
line-length = 110
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.isort]
profile = "black"
line_length = 110
known_localfolder = ["pwa", "tests"]
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "LOCALFOLDER"]
default_section = "THIRDPARTY"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "django-pwa"
version = "1.1.0"
description = "A Django app to include a manifest.json and Service Worker instance to enable progressive web app behavior"
readme = "README.md"
license = { file = "LICENSE" }
authors = [{ name = "Silvio Luis", email = "[email protected]" }]
maintainers = [{ name = "Christian Hartung", email = "[email protected]" }]
classifiers = [
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
]
requires-python = ">=3.8"
dependencies = ["django>=3.2"]

[project.urls]
Repository = "http://github.com/silviolleite/django-pwa"

[tool.hatch.build.targets.sdist]
packages = ["/pwa", "/tests"]

[tool.hatch.build.targets.wheel]
packages = ["/pwa"]

[tool.ruff]
extend = "ruff_defaults.toml"

[tool.ruff.lint]
extend-select = ["DJ"]

[tool.ruff.lint.extend-per-file-ignores]
"tests/test_*.py" = ["PT"]

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "parents"
Loading

0 comments on commit f2ac93b

Please sign in to comment.