Skip to content

Commit fd25a52

Browse files
authored
Use hynek/build-and-inspect-python-package (#392)
2 parents 31ad421 + 670de76 commit fd25a52

File tree

6 files changed

+63
-32
lines changed

6 files changed

+63
-32
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[flake8]
2-
max_line_length = 88
2+
max-line-length = 88

.github/workflows/deploy.yml

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,71 @@ name: Deploy
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
6+
tags: ["*"]
7+
pull_request:
8+
branches: [main]
79
release:
810
types:
911
- published
1012
workflow_dispatch:
1113

14+
permissions:
15+
contents: read
16+
1217
jobs:
13-
deploy:
14-
if: github.repository_owner == 'hugovk'
18+
# Always build & lint package.
19+
build-package:
20+
name: Build & verify package
1521
runs-on: ubuntu-latest
1622

17-
permissions:
18-
# IMPORTANT: this permission is mandatory for OIDC publishing
19-
id-token: write
20-
2123
steps:
2224
- uses: actions/checkout@v3
2325
with:
2426
fetch-depth: 0
2527

26-
- name: Set up Python
27-
uses: actions/setup-python@v4
28+
- uses: hynek/build-and-inspect-python-package@v1
29+
30+
# Upload to Test PyPI on every commit on main.
31+
release-test-pypi:
32+
name: Publish in-dev package to test.pypi.org
33+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
34+
runs-on: ubuntu-latest
35+
needs: build-package
36+
37+
permissions:
38+
# IMPORTANT: this permission is mandatory for trusted publishing
39+
id-token: write
40+
41+
steps:
42+
- name: Download packages built by build-and-inspect-python-package
43+
uses: actions/download-artifact@v3
2844
with:
29-
python-version: "3.x"
30-
cache: pip
31-
cache-dependency-path: pyproject.toml
32-
33-
- name: Install dependencies
34-
run: |
35-
python -m pip install -U pip
36-
python -m pip install -U build twine wheel
37-
38-
- name: Build package
39-
run: |
40-
python -m build
41-
twine check --strict dist/*
42-
43-
- name: Publish package to PyPI
44-
if: github.event.action == 'published'
45-
uses: pypa/gh-action-pypi-publish@release/v1
45+
name: Packages
46+
path: dist
4647

47-
- name: Publish package to TestPyPI
48+
- name: Upload package to Test PyPI
4849
uses: pypa/gh-action-pypi-publish@release/v1
4950
with:
5051
repository-url: https://test.pypi.org/legacy/
52+
53+
# Upload to real PyPI on GitHub Releases.
54+
release-pypi:
55+
name: Publish released package to pypi.org
56+
if: github.event.action == 'published'
57+
runs-on: ubuntu-latest
58+
needs: build-package
59+
60+
permissions:
61+
# IMPORTANT: this permission is mandatory for trusted publishing
62+
id-token: write
63+
64+
steps:
65+
- name: Download packages built by build-and-inspect-python-package
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: Packages
69+
path: dist
70+
71+
- name: Upload package to PyPI
72+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Lint
22

33
on: [push, pull_request, workflow_dispatch]
44

5+
permissions:
6+
contents: read
7+
58
jobs:
69
lint:
710
runs-on: ubuntu-latest

.github/workflows/require-pr-label.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ jobs:
88
label:
99
runs-on: ubuntu-latest
1010

11+
permissions:
12+
issues: write
13+
1114
steps:
1215
- uses: mheap/github-action-required-labels@v4
1316
with:

.pre-commit-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ repos:
1919
rev: 6.0.0
2020
hooks:
2121
- id: flake8
22-
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
22+
additional_dependencies:
23+
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]
2324

2425
- repo: https://github.com/pre-commit/pygrep-hooks
2526
rev: v1.10.0
@@ -30,8 +31,9 @@ repos:
3031
- repo: https://github.com/pre-commit/pre-commit-hooks
3132
rev: v4.4.0
3233
hooks:
33-
- id: check-json
34+
- id: check-case-conflict
3435
- id: check-merge-conflict
36+
- id: check-json
3537
- id: check-toml
3638
- id: check-yaml
3739
- id: end-of-file-fixer

src/pypistats/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ def pypi_stats_api(
128128

129129
# Validate end date
130130
if end_date and end_date < first:
131-
raise ValueError(
131+
msg = (
132132
f"Requested end date ({end_date}) is before earliest available "
133133
f"data ({first}), because data is only available for 180 days. "
134134
"See https://pypistats.org/about#data"
135135
)
136+
raise ValueError(msg)
136137

137138
# Validate start date
138139
if start_date and start_date < first:

0 commit comments

Comments
 (0)