Skip to content

Commit a912237

Browse files
authored
fix: get pypi publish working (#64)
* fix: get pypi publish working * prod: run packaging build on PRs to check that it works * fix: try to get git config correct * fix: get prod too * fix: ignore race conditions * fix: ignore race conditions
1 parent 4a2f4a8 commit a912237

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

.github/workflows/build-ultraplot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
timeout-minutes: 15
2121
steps:
2222
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
2326
- uses: mamba-org/setup-micromamba@v2.0.4
2427
with:
2528
environment-file: ./environment.yml

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
matplotlib-versions: ${{ steps.set-versions.outputs.matplotlib-versions }}
1414
steps:
1515
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
1619
- uses: actions/setup-python@v5
1720
with:
1821
python-version: "3.11"

.github/workflows/publish-pypi.yml

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
name: Publish to PyPI
22
on:
3+
pull_request:
34
release:
45
types: [published]
56
push:
67
tags: ["v*"]
78

9+
concurrency:
10+
group: publish-pypi
11+
cancel-in-progress: false
12+
813
jobs:
914
publish-pypi-test:
1015
name: Publish to TestPyPI
@@ -19,18 +24,50 @@ jobs:
1924
- uses: actions/checkout@v4
2025
with:
2126
fetch-depth: 0
27+
28+
- name: Get tags
29+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
30+
shell: bash
31+
2232
- uses: actions/setup-python@v5
2333
with:
24-
python-version: "3.x"
34+
python-version: "3.12"
35+
2536
- name: Build package
2637
run: |
27-
python -m pip install build
28-
python -m build
38+
python -m pip install --upgrade pip wheel setuptools setuptools_scm build twine
39+
python -m build --sdist --wheel . --outdir dist
40+
41+
- name: CheckFiles
42+
run: |
43+
ls dist
44+
shell: bash
45+
46+
- name: Test wheels
47+
run: |
48+
pushd dist
49+
python -m pip install ultraplot*.whl
50+
51+
version=$(python -c "import ultraplot; print(ultraplot.__version__)")
52+
echo "Version: $version"
53+
if [[ "$version" == "0."* ]]; then
54+
echo "Version is not set correctly!"
55+
exit 1
56+
fi
57+
58+
python -m twine check *
59+
popd
60+
shell: bash
61+
2962
- name: Publish to TestPyPI
63+
if: github.event_name != 'pull_request'
3064
uses: pypa/gh-action-pypi-publish@release/v1
3165
with:
3266
repository-url: https://test.pypi.org/legacy/
3367
verbose: true
68+
# releases generate both release and tag events so
69+
# we get a race condition if we don't skip existing
70+
skip-existing: ${{ github.event_name == 'release' && 'true' || 'false' }}
3471

3572
publish-prod:
3673
name: Publish to PyPI
@@ -47,13 +84,41 @@ jobs:
4784
- uses: actions/checkout@v4
4885
with:
4986
fetch-depth: 0
87+
88+
- name: Get tags
89+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
90+
shell: bash
91+
5092
- uses: actions/setup-python@v5
5193
with:
52-
python-version: "3.x"
94+
python-version: "3.12"
95+
5396
- name: Build package
5497
run: |
55-
python -m pip install build
56-
python -m build
98+
python -m pip install --upgrade pip wheel setuptools setuptools_scm build twine
99+
python -m build --sdist --wheel . --outdir dist
100+
101+
- name: CheckFiles
102+
run: |
103+
ls dist
104+
shell: bash
105+
106+
- name: Test wheels
107+
run: |
108+
pushd dist
109+
python -m pip install ultraplot*.whl
110+
111+
version=$(python -c "import ultraplot; print(ultraplot.__version__)")
112+
echo "Version: $version"
113+
if [[ "$version" == "0."* ]]; then
114+
echo "Version is not set correctly!"
115+
exit 1
116+
fi
117+
118+
python -m twine check *
119+
popd
120+
shell: bash
121+
57122
- name: Publish to PyPI
58123
uses: pypa/gh-action-pypi-publish@release/v1
59124
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ __pycache__
3838
tmp
3939
trash
4040
garbage
41+
42+
# version file
43+
ultraplot/_version.py

pyproject.toml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[build-system]
2-
requires = ["setuptools>=64",
3-
"setuptools_scm[toml]>=8",
4-
"wheel",
5-
"numpy>=1.26.0",
6-
"matplotlib>=3.9",
7-
]
2+
requires = [
3+
"setuptools>=64",
4+
"setuptools_scm[toml]>=8",
5+
"wheel",
6+
]
87
build-backend = "setuptools.build_meta"
98

109
[project]
@@ -13,7 +12,6 @@ authors = [
1312
{name = "Casper van Elteren", email = "caspervanelteren@gmail.com"},
1413
{name = "Luke Davis", email = "lukelbd@gmail.com"},
1514
]
16-
1715
maintainers = [
1816
{name = "Casper van Elteren", email = "caspervanelteren@gmail.com"},
1917
]
@@ -38,21 +36,15 @@ dependencies= [
3836
]
3937
dynamic = ["version"]
4038

41-
4239
[project.urls]
4340
"Documentation" = "https://ultraplot.readthedocs.io"
4441
"Issue Tracker" = "https://github.com/ultraplot/ultraplot/issues"
4542
"Source Code" = "https://github.com/ultraplot/ultraplot"
4643

47-
[project.entry-points."setuptools.finalize_distribution_options"]
48-
setuptools_scm = "setuptools_scm._integration.setuptools:infer_version"
49-
50-
51-
5244
[tool.setuptools]
53-
packages = ["ultraplot"]
45+
packages = {find = {exclude=["docs*", "baseline*", "logo*"]}}
5446
include-package-data = true
5547

5648
[tool.setuptools_scm]
57-
version_scheme = "post-release"
58-
local_scheme = "dirty-tag"
49+
write_to = "ultraplot/_version.py"
50+
write_to_template = "__version__ = '{version}'\n"

ultraplot/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
name = "ultraplot"
77

88
try:
9-
from importlib.metadata import version as get_version
10-
except ImportError: # for Python < 3.8
11-
from importlib_metadata import version as get_version
12-
try:
13-
version = __version__ = get_version(name)
14-
except Exception:
15-
version = __version__ = "unknown"
9+
from ._version import __version__
10+
except ImportError:
11+
__version__ = "unknown"
12+
13+
version = __version__
1614

1715
# Import dependencies early to isolate import times
1816
from . import internals, externals, tests # noqa: F401

0 commit comments

Comments
 (0)