Skip to content

Commit 4ac2d45

Browse files
committed
Initial packaging setup.
1 parent 73b7c35 commit 4ac2d45

File tree

11 files changed

+443
-0
lines changed

11 files changed

+443
-0
lines changed

.github/SECURITY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
In general, only the latest released `jsonschema-lexer` version is supported and will receive updates.
6+
7+
## Reporting a Vulnerability
8+
9+
To report a security vulnerability, please send an email to `Julian+Security` at `GrayVines.com` with subject line `SECURITY (jsonschema-lexer)`.
10+
11+
I will do my best to respond within 48 hours to acknowledge the message and discuss further steps.
12+
13+
If the vulnerability is accepted, an advisory will be sent out via GitHub's security advisory functionality.
14+
15+
For non-sensitive discussion related to this policy itself, feel free to open an issue on the issue tracker.

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [published]
8+
schedule:
9+
# Daily at 7:37
10+
- cron: "37 7 * * *"
11+
12+
env:
13+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
14+
PIP_NO_PYTHON_VERSION_WARNING: "1"
15+
16+
jobs:
17+
list:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
noxenvs: ${{ steps.noxenvs-matrix.outputs.noxenvs }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Set up nox
24+
uses: wntrblm/[email protected]
25+
- id: noxenvs-matrix
26+
run: |
27+
echo >>$GITHUB_OUTPUT noxenvs=$(
28+
nox --list-sessions --json | jq '[.[].session]'
29+
)
30+
31+
ci:
32+
needs: list
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
os: [macos-latest, ubuntu-latest]
38+
noxenv: ${{ fromJson(needs.list.outputs.noxenvs) }}
39+
posargs: [""]
40+
include:
41+
- os: ubuntu-latest
42+
noxenv: "tests-3.11"
43+
posargs: coverage github
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
- name: Install dependencies
48+
run: sudo apt-get update && sudo apt-get install -y libenchant-2-dev
49+
if: runner.os == 'Linux' && startsWith(matrix.noxenv, 'docs')
50+
- name: Install dependencies
51+
run: brew install enchant
52+
if: runner.os == 'macOS' && startsWith(matrix.noxenv, 'docs')
53+
- name: Set up Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: |
57+
3.8
58+
3.9
59+
3.10
60+
3.11
61+
3.12
62+
pypy3.10
63+
allow-prereleases: true
64+
- name: Set up nox
65+
uses: wntrblm/[email protected]
66+
- name: Run nox
67+
run: nox -s "${{ matrix.noxenv }}" -- ${{ matrix.posargs }}
68+
69+
packaging:
70+
needs: ci
71+
runs-on: ubuntu-latest
72+
environment:
73+
name: PyPI
74+
url: https://pypi.org/p/jsonschema-lexer
75+
permissions:
76+
contents: write
77+
id-token: write
78+
79+
steps:
80+
- uses: actions/checkout@v3
81+
- name: Set up Python
82+
uses: actions/setup-python@v4
83+
with:
84+
python-version: "3.x"
85+
- name: Install dependencies
86+
run: python -m pip install build
87+
- name: Create packages
88+
run: python -m build .
89+
- name: Publish to PyPI
90+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
91+
uses: pypa/gh-action-pypi-publish@release/v1
92+
- name: Create a Release
93+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
94+
uses: softprops/action-gh-release@v1
95+
with:
96+
files: |
97+
dist/*
98+
generate_release_notes: true

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-ast
7+
- id: check-toml
8+
- id: check-vcs-permalinks
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
- id: mixed-line-ending
13+
args: [--fix, lf]
14+
- id: trailing-whitespace
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: "v0.2.2"
17+
hooks:
18+
- id: ruff
19+
args: [--fix, --exit-non-zero-on-fix]
20+
- repo: https://github.com/PyCQA/isort
21+
rev: 5.13.2
22+
hooks:
23+
- id: isort
24+
- repo: https://github.com/psf/black
25+
rev: 24.2.0
26+
hooks:
27+
- name: black
28+
id: black
29+
args: ["--line-length", "79"]
30+
- repo: https://github.com/pre-commit/mirrors-prettier
31+
rev: "v4.0.0-alpha.8"
32+
hooks:
33+
- id: prettier

README.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
====================
2+
``jsonschema-lexer``
3+
====================
4+
5+
|PyPI| |Pythons| |CI|
6+
7+
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema-lexer.svg
8+
:alt: PyPI version
9+
:target: https://pypi.org/project/jsonschema-lexer/
10+
11+
.. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema-lexer.svg
12+
:alt: Supported Python versions
13+
:target: https://pypi.org/project/jsonschema-lexer/
14+
15+
.. |CI| image:: https://github.com/python-jsonschema/jsonschema-lexer/workflows/CI/badge.svg
16+
:alt: Build status
17+
:target: https://github.com/python-jsonschema/jsonschema-lexer/actions?query=workflow%3ACI

jsonschema_lexer/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Fill me in!
3+
"""

jsonschema_lexer/tests/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_it_imports():
2+
import jsonschema_lexer # noqa: F401

noxfile.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
from pathlib import Path
2+
from tempfile import TemporaryDirectory
3+
import os
4+
5+
import nox
6+
7+
ROOT = Path(__file__).parent
8+
PYPROJECT = ROOT / "pyproject.toml"
9+
DOCS = ROOT / "docs"
10+
11+
PACKAGE = ROOT / "jsonschema_lexer"
12+
13+
REQUIREMENTS = dict(
14+
tests=ROOT / "test-requirements.txt",
15+
)
16+
REQUIREMENTS_IN = {
17+
path.parent / f"{path.stem}.in" for path in REQUIREMENTS.values()
18+
}
19+
20+
21+
SUPPORTED = ["pypy3.10", "3.10", "3.11", "3.12"]
22+
LATEST = SUPPORTED[-1]
23+
24+
nox.options.sessions = []
25+
26+
27+
def session(default=True, python=LATEST, **kwargs): # noqa: D103
28+
def _session(fn):
29+
if default:
30+
nox.options.sessions.append(kwargs.get("name", fn.__name__))
31+
return nox.session(python=python, **kwargs)(fn)
32+
33+
return _session
34+
35+
36+
@session(python=SUPPORTED)
37+
def tests(session):
38+
"""
39+
Run the test suite.
40+
"""
41+
session.install("pytest")
42+
43+
if session.posargs and session.posargs[0] == "coverage":
44+
if len(session.posargs) > 1 and session.posargs[1] == "github":
45+
github = Path(os.environ["GITHUB_STEP_SUMMARY"])
46+
else:
47+
github = None
48+
49+
session.install("coverage[toml]")
50+
session.run("coverage", "run", "-m", "pytest", PACKAGE)
51+
if github is None:
52+
session.run("coverage", "report")
53+
else:
54+
with github.open("a") as summary:
55+
summary.write("### Coverage\n\n")
56+
summary.flush() # without a flush, output seems out of order.
57+
session.run(
58+
"coverage",
59+
"report",
60+
"--format=markdown",
61+
stdout=summary,
62+
)
63+
else:
64+
session.run("python", "-m", "pytest", *session.posargs, PACKAGE)
65+
66+
67+
@session(python=SUPPORTED)
68+
def audit(session):
69+
"""
70+
Audit Python dependencies for vulnerabilities.
71+
"""
72+
session.install("pip-audit", ROOT)
73+
session.run("python", "-m", "pip_audit")
74+
75+
76+
@session(tags=["build"])
77+
def build(session):
78+
"""
79+
Build a distribution suitable for PyPI and check its validity.
80+
"""
81+
session.install("build", "twine")
82+
with TemporaryDirectory() as tmpdir:
83+
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
84+
session.run("twine", "check", "--strict", tmpdir + "/*")
85+
86+
87+
@session()
88+
def secrets(session):
89+
"""
90+
Check for accidentally included secrets.
91+
"""
92+
session.install("detect-secrets")
93+
session.run("detect-secrets", "scan", ROOT)
94+
95+
96+
@session(tags=["style"])
97+
def style(session):
98+
"""
99+
Check for coding style.
100+
"""
101+
session.install("ruff")
102+
session.run("ruff", "check", ROOT)
103+
104+
105+
@session()
106+
def typing(session):
107+
"""
108+
Statically check typing annotations.
109+
"""
110+
session.install("pyright", ROOT)
111+
session.run("pyright", PACKAGE)
112+
113+
114+
@session(default=False)
115+
def requirements(session):
116+
"""
117+
Update requirements files.
118+
"""
119+
session.install("pip-tools")
120+
for each in REQUIREMENTS_IN:
121+
session.run(
122+
"pip-compile",
123+
"--resolver",
124+
"backtracking",
125+
"--strip-extras",
126+
"-U",
127+
each.relative_to(ROOT),
128+
)

0 commit comments

Comments
 (0)