Skip to content

Commit 7bd4345

Browse files
committed
Finalized publishing
1 parent e6ccb33 commit 7bd4345

File tree

10 files changed

+188
-33
lines changed

10 files changed

+188
-33
lines changed

.github/workflows/publish.yml

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
name: Publish package
2-
on: workflow_dispatch
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
destination:
6+
type: choice
7+
description: 'Publish to:'
8+
options:
9+
- pypi
10+
- testpypi
311

412
jobs:
5-
publish:
13+
prepare:
614
runs-on: ubuntu-latest
715
permissions: write-all
816
steps:
@@ -24,12 +32,6 @@ jobs:
2432
run: |
2533
echo "NEW_VERSION=$(tools/update-version.py release)" >> $GITHUB_ENV
2634
27-
- name: Build
28-
run: |
29-
rm -rf code/wrappers/python/src/spreader.egg-info
30-
mkdir -p dist/tmp
31-
python3 setup.py egg_info --egg-base dist/tmp sdist
32-
3335
- name: Update changelog
3436
uses: superfaceai/release-changelog-action@v2
3537
with:
@@ -38,11 +40,19 @@ jobs:
3840
operation: release
3941

4042
- name: Commit CHANGELOG.md and package.json changes and create tag
43+
id: tagRelease
4144
run: |
4245
git add "setup.py"
4346
git add "CHANGELOG.md"
4447
git commit -m "chore: release ${{ env.NEW_VERSION }}"
45-
git tag ${{ env.NEW_VERSION }}
48+
git tag v${{ env.NEW_VERSION }}
49+
echo "newVersion=${{ env.NEW_VERSION }}" >> "$GITHUB_OUTPUT"
50+
51+
- name: Build Source Distribution
52+
run: |
53+
rm -rf code/wrappers/python/src/spreader.egg-info
54+
mkdir -p dist/tmp
55+
python3 setup.py egg_info --egg-base dist/tmp sdist
4656
4757
- name: Set next dev version
4858
run: |
@@ -56,28 +66,96 @@ jobs:
5666
run: |
5767
git push origin && git push --tags
5868
69+
- name: Upload artifacts
70+
uses: actions/upload-artifact@v3
71+
with:
72+
path: dist/*.tar.gz
73+
74+
outputs:
75+
newVersion: ${{ steps.tagRelease.outputs.newVersion }}
76+
77+
wheels:
78+
needs: prepare
79+
runs-on: ${{matrix.os}}
80+
strategy:
81+
fail-fast: false
82+
matrix:
83+
os: [windows-latest, macos-latest]
84+
pyver: [cp37, cp38, cp39, cp310, cp311, pp38, pp39]
85+
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v3
89+
with:
90+
ref: v${{needs.prepare.outputs.newVersion}}
91+
submodules: true
92+
93+
- name: Build wheels
94+
uses: pypa/cibuildwheel@v2.12.1
95+
env:
96+
CIBW_BUILD: ${{matrix.pyver}}-*
97+
CIBW_ARCHS_MACOS: x86_64 universal2
98+
MACOSX_DEPLOYMENT_TARGET: 10.15
99+
CIBW_ARCHS_WINDOWS: AMD64 x86 ARM64
100+
CIBW_BEFORE_BUILD_WINDOWS: if exist "{package}\_skbuild" rmdir /s /q "{package}\_skbuild"
101+
CIBW_TEST_REQUIRES: pytest
102+
CIBW_TEST_COMMAND: pytest --color=yes {project}/code/wrappers/python
103+
104+
- name: Upload artifacts
105+
uses: actions/upload-artifact@v3
106+
with:
107+
path: ./wheelhouse/*.whl
108+
109+
publish:
110+
needs:
111+
- prepare
112+
- wheels
113+
runs-on: ubuntu-latest
114+
permissions: write-all
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v3
118+
with:
119+
ref: v${{needs.prepare.outputs.newVersion}}
120+
submodules: true
121+
122+
- name: Setup python environment
123+
run: |
124+
pip3 install -r requirements.txt
125+
126+
- name: Download artifacts
127+
uses: actions/download-artifact@v3
128+
with:
129+
name: artifact
130+
path: dist
131+
59132
- name: Publish
60-
run: twine upload --non-interactive dist/eg.spreader-${{ env.NEW_VERSION }}.tar.gz
133+
run: |
134+
if [[ "$TWINE_REPOSITORY" == "testpypi" ]]; then
135+
export TWINE_PASSWORD=${{ secrets.TESTPYPI_ACCESS_TOKEN }}
136+
else
137+
export TWINE_PASSWORD=${{ secrets.PYPI_ACCESS_TOKEN }}
138+
fi
139+
twine upload --non-interactive dist/*
61140
env:
62-
TWINE_REPOSITORY: testpypi
141+
TWINE_REPOSITORY: ${{ github.event.inputs.destination }}
63142
TWINE_USERNAME: __token__
64-
TWINE_PASSWORD: ${{ secrets.TESTPYPI_ACCESS_TOKEN }}
65143

66144
- id: get-changelog
67145
name: Get version changelog
68146
uses: superfaceai/release-changelog-action@v2
69147
with:
70148
path-to-changelog: CHANGELOG.md
71-
version: ${{ env.NEW_VERSION }}
149+
version: ${{needs.prepare.outputs.newVersion}}
72150
operation: read
73151

74152
- name: Update GitHub release documentation
75153
uses: softprops/action-gh-release@v1
76154
with:
77-
tag_name: ${{ env.NEW_VERSION }}
155+
tag_name: v${{needs.prepare.outputs.newVersion}}
78156
body: ${{ steps.get-changelog.outputs.changelog }}
79157
files: |
80-
dist/eg.spreader-${{ env.NEW_VERSION }}.tar.gz
158+
dist/*
81159
draft: true
82160
env:
83161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ jobs:
3838
- name: Install Nox
3939
run: pip install Nox
4040

41-
- name: Fixup Build Params
42-
if: matrix.os == 'windows-latest' && matrix.python-version == 'pypy-3.8'
43-
run: |
44-
$Python3_ROOT_DIR=$Env:Python3_ROOT_DIR -replace '\\', '/'
45-
echo SKBUILD_CONFIGURE_OPTIONS=-DPYTHON_LIBRARY=$Python3_ROOT_DIR/libs/python38.lib >> $Env:GITHUB_ENV
46-
#Get-ChildItem -Path $Env:Python3_ROOT_DIR -Recurse
47-
4841
- name: Test
4942
run: nox --sessions test --force-python ${{ steps.setup-python.outputs.python-path }}
5043

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/
88
.DS_Store
99
__pycache__
1010
.extrapythons
11+
.pypirc

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88
### Added
9-
Initial version
10-
9+
- Initial version

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include code/CMakeLists.txt
22
recursive-include code/cmake *.cmake
33
recursive-include code/lib/code *.h *.cpp *.l *.y *.txt
4-
recursive-include code/wrappers/python/src *.h *.cpp *.h *.txt *.py *.pyi
4+
recursive-include code/wrappers/python/src *.h *.cpp *.h *.py *.pyi
5+
include code/wrappers/python/CMakeLists.txt
56
include pyproject.toml
67
include setup.py
78

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ A fast spreadsheet logic library.
44

55
[![License](https://img.shields.io/badge/license-BSD-brightgreen.svg)](https://opensource.org/licenses/BSD-3-Clause)
66
[![pypi](https://img.shields.io/pypi/v/eg.spreader)](https://pypi.org/project/eg.spreader)
7-
[![Python](https://img.shields.io/badge/Python-3.7-blue.svg)](https://docs.python.org/3/whatsnew/3.7.html)
7+
[![python](https://img.shields.io/badge/python->=3.7-blue.svg)](https://www.python.org)
8+
<!--https://img.shields.io/pypi/pyversions/eg.spreader -->
89

910
<!-- References -->
1011

@@ -17,15 +18,18 @@ It is currently in alpha stage.
1718

1819
## Install
1920

20-
Spreader is a C++ library. In order to install it from source you will need
21+
Spreader is a C++ library. Binary wheels are provided for common configurations on macOS and Windows.
22+
If you are on another platform or have an uncommon configuration `pip` will build the module from
23+
source.
24+
In order for a build from source to succeed you will need
2125
- Working C++ compiler supporting C++20 standard
26+
- Linux: GCC 11.3 or above
2227
- macOS: Xcode 14 or above
2328
- Windows: Visual Studio 2022 or above
24-
- Linux: GCC 11.3 or above
2529
- On Linux you will also need Python development support (the python-dev or python3-dev package in most Linux distributions).
2630
No further external dependencies are required.
2731

28-
You can use pip to install the module
32+
To install the module
2933

3034
```bash
3135
pip install eg.spreader

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
scikit-build >= 0.16
22
pytest >= 7.2
3+
twine >= 4

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from skbuild import setup
99
from pathlib import Path
10+
import platform
11+
import sys
1012

1113
mydir = Path(__file__).parent
1214

@@ -33,9 +35,19 @@
3335
Typing :: Typed
3436
""".splitlines()
3537

38+
CMAKE_EXTRA_ARGS = []
39+
40+
pythonType = platform.python_implementation()
41+
system = platform.system()
42+
43+
#work around bug in scikit-build
44+
if system == 'Windows' and pythonType == 'PyPy':
45+
maj, min, _ = platform.python_version_tuple()
46+
CMAKE_EXTRA_ARGS += [f'-DPYTHON_LIBRARY={sys.base_prefix}/libs/python{maj}{min}.lib']
47+
3648
setup(
3749
name="eg.spreader",
38-
version="0.1.dev1",
50+
version="0.1.0.dev1",
3951
description="Fast spreadsheet logic library",
4052
long_description=README,
4153
long_description_content_type="text/markdown",
@@ -52,7 +64,7 @@
5264
python_requires=">=3.7",
5365

5466
cmake_source_dir="code",
55-
cmake_args=[
67+
cmake_args= [
5668
'-DSPR_PYTHON_PACKAGE_DIR=code/wrappers/python/src/eg'
57-
]
69+
] + CMAKE_EXTRA_ARGS
5870
)

tools/update-version.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import re
5+
import argparse
6+
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument('type', choices=['release', 'nextpatch', 'nextminor', 'nextmajor'])
9+
parser.add_argument('--dry-run', dest='dryRun', action='store_true')
10+
args = parser.parse_args()
11+
12+
13+
def updateVersion(major, minor, patch, dev):
14+
if args.type == 'release':
15+
if not dev:
16+
patch = int(patch) + 1
17+
dev = None
18+
elif args.type == 'nextpatch':
19+
patch = int(patch) + 1
20+
dev = 1
21+
elif args.type == 'nextminor':
22+
minor = int(minor) + 1
23+
patch = 0
24+
dev = 1
25+
else:
26+
major = int(major) + 1
27+
minor = 0
28+
patch = 0
29+
dev = 1
30+
31+
return (major, minor, patch, dev)
32+
33+
34+
lines = []
35+
newVersion = None
36+
regex = r'''(?P<prefix>\s*version=["'])(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?:\.dev(?P<dev>\d+))?(?P<suffix>["']\s*,?\s*)'''
37+
with open('setup.py', 'r') as setupFile:
38+
for line in setupFile:
39+
if newVersion is None:
40+
m = re.match(regex, line)
41+
if m:
42+
groups = m.groupdict()
43+
major = groups['major']
44+
minor = groups['minor']
45+
patch = groups['patch']
46+
dev = groups.get('dev', None)
47+
major, minor, patch, dev = updateVersion(major, minor, patch, dev)
48+
if dev:
49+
newVersion = f'{major}.{minor}.{patch}.dev{dev}'
50+
else:
51+
newVersion = f'{major}.{minor}.{patch}'
52+
53+
line = groups['prefix'] + newVersion + groups['suffix']
54+
55+
lines += line
56+
57+
if newVersion is None:
58+
print("version line not found", file = sys.stderr)
59+
sys.exit(1)
60+
61+
if not args.dryRun:
62+
with open('setup.py', 'w') as setupFile:
63+
setupFile.writelines(lines)
64+
65+
print(newVersion)
66+

0 commit comments

Comments
 (0)