Skip to content

Commit

Permalink
Merge pull request #31 from n-takumasa/env
Browse files Browse the repository at this point in the history
dev: migrate to tox-uv and fix metadata
  • Loading branch information
n-takumasa authored Sep 24, 2024
2 parents 3abe1d3 + 346934e commit e547274
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 149 deletions.
119 changes: 61 additions & 58 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,96 @@ name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
on:
push:
tags:
- 'v*'
- "v*"

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"

- name: Install Hatch
run: pip install --upgrade hatch
- name: Update pip
run: python -m pip install --upgrade pip

- name: Build a binary wheel and a source tarball
run: hatch build
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Build a binary wheel and a source tarball
run: uv build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/json-with-comments
url: https://pypi.org/p/janaf
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
79 changes: 61 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,71 @@ env:
FORCE_COLOR: "1"

jobs:
check:
name: Static analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uv venv
- name: Install tox
run: uv pip install tox tox-uv
- name: Run static analysis
run: uv run tox run -e lint
- name: Run mypy
run: uv run tox run -e type

run:
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
needs: check
name: ${{ startsWith(matrix.python-version, 'pypy') && 'PyPy' || 'CPython' }} ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "pypy3.7"
- "pypy3.8"
- "pypy3.9"
- "pypy3.10"
include:
- os: windows-latest
python-version: 3.12
- os: macos-latest
python-version: 3.12

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Hatch
run: pip install --upgrade hatch

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

- name: Run tests
run: hatch test --python ${{ matrix.python-version }} --cover --randomize --parallel --retries 2 --retry-delay 1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uv venv
- name: Install tox
if: ${{ ! endsWith(matrix.python-version, '3.7') }}
run: uv pip install tox tox-uv tox-gh-actions
- name: Run tests
if: ${{ ! endsWith(matrix.python-version, '3.7') }}
run: uv run tox
- name: Install deps (Python 3.7)
if: ${{ endsWith(matrix.python-version, '3.7') }}
run: |
uv pip install pytest pytest-cov
uv pip install -e .
- name: Run tests (Python 3.7)
if: ${{ endsWith(matrix.python-version, '3.7') }}
run: uv run python -m pytest .
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ wheels/
# lock
.python-version
requirements*.lock

# hatch-vcs
src/jsonc/_version.py

# coverage
.coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ pip install json-with-comments
{'spam': 'ham // egg'}
>>> jsonc.loads('{"spam": /* comment */"ham /* egg */"}')
{'spam': 'ham /* egg */'}

```

And just like `json` module
83 changes: 48 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,75 @@
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"
[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/jsonc/_version.py"
build.targets.sdist.exclude = [
"/.github"
]
build.targets.wheel.packages = ["src/jsonc"]

[project]
dynamic = ["version"]
name = "json-with-comments"
description = "JSON with Comments (jsonc) for Python"
readme = "README.md"
requires-python = ">=3.7"
license = "MIT"
license = { text = "MIT" }
authors = [
{ name = "Takumasa Nakamura", email = "[email protected]" },
]
keywords = ["jsonc", "json with comments"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"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",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = []
dynamic = ["version"]

[project.urls]
Repository = "https://github.com/n-takumasa/json-with-comments"
urls.Repository = "https://github.com/n-takumasa/json-with-comments"

[tool.hatch.build.targets.sdist]
exclude = [
"/.github"
]
dependencies = []

[tool.hatch.build.targets.wheel]
packages = ["jsonc"]
[tool.uv]
managed = false

[[tool.hatch.envs.test.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.ruff]
target-version = "py38"
line-length = 88

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN", # flake8-annotations
"D", # pydocstyle
"FIX", # flake8-fixme
"TD", # flake8-todos
"PTH123", # flake8-use-pathlib: builtin-open
"PLR0913", # too-many-arguments
# Conflicting lint rules
"W191", "E111", "E114", "E117", "D206", "D300", "Q000", "Q001", "Q002", "Q003",
"COM812", "COM819", "ISC001", "ISC002", "E501",
lint.extend-select = [
"B", # flake8-bugbear
"I", # isort
"UP", # pyupgrade
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"F401", # Pyflakes: unused-import
]
"**/tests/**/*.py" = [
"S101", # flake8-bandit: assert
"PLR2004", # magic-value-comparison
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--doctest-modules --doctest-glob='*.md' --ignore='src/jsonc/_types.py'"

[tool.coverage]
run.source_pkgs = ["jsonc", "tests"]
run.branch = true
run.parallel = true
report.exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"@overload",
]

[tool.mypy]
files = "src"
strict = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
6 changes: 6 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest
pytest-cov
ruff
mypy[install-types]
tox >= 4
tox-uv
Loading

0 comments on commit e547274

Please sign in to comment.