Skip to content

Commit f8098db

Browse files
committed
New solution for publishing python packages that does not require env var
1 parent 94ebb49 commit f8098db

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ jobs:
1010
permissions:
1111
contents: write
1212
packages: write
13-
id-token: write
14-
# environment:
15-
# name: testpypi
16-
# url: https://test.pypi.org/p/polypheny-prism-api
13+
id-token: write
1714
steps:
1815
- uses: actions/checkout@v4
1916
- name: Set up Python 3.8
@@ -24,11 +21,12 @@ jobs:
2421
id: version
2522
run: |
2623
if [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then
27-
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
24+
echo "${GITHUB_REF#refs/tags/}" > prism-api-version.txt
2825
else
2926
TIMESTAMP=$(date +'%Y%m%d%H%M%S')
30-
echo "VERSION=0.0.dev${TIMESTAMP}" >> $GITHUB_ENV
31-
fi
27+
echo "0.0.dev${TIMESTAMP}" > prism-api-version.txt
28+
- name: Create MANIFEST.in
29+
run: echo "include prism-api-version.txt" > MANIFEST.in
3230
- name: Download protobuf for Linux
3331
run: |
3432
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v26.0/protoc-26.0-linux-x86_64.zip
@@ -37,11 +35,5 @@ jobs:
3735
run: bin/protoc --experimental_allow_proto3_optional -I . --python_out . org/polypheny/prism/*.proto
3836
- name: Build package
3937
run: python setup.py sdist bdist_wheel
40-
env:
41-
VERSION: ${{ env.VERSION }}
42-
# - name: Publish distribution 📦 to Test PyPI
43-
# uses: pypa/gh-action-pypi-publish@release/v1
44-
# with:
45-
# repository-url: https://test.pypi.org/legacy/
4638
- name: Publish distribution 📦 to PyPI
4739
uses: pypa/gh-action-pypi-publish@release/v1

setup.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
import os
2-
import sys
3-
42
from setuptools import setup
53

6-
# Retrieve 'VERSION' environment variable, default to '0.0' if not found.
7-
version = os.getenv('VERSION', '0.0')
4+
version_file = 'prism-api-version.txt'
5+
6+
if not os.path.exists(version_file):
7+
raise ValueError(f"Version file '{version_file}' not found. Please create the file with the version number.")
8+
9+
with open(version_file, 'r') as f:
10+
version = f.read().strip()
811

912
print(f"Building version: {version}")
1013

1114
if version == '0.0':
12-
raise ValueError("Version not set or defaulting to '0.0'. Please set the VERSION environment variable.")
15+
raise ValueError("Version is set to '0.0'. Please set a valid version number in the version file.")
1316

1417
# Attempt to split the version number, default to '0' for both if it fails
1518
try:
1619
major, minor = version.split('.')
1720
except ValueError:
1821
raise ValueError(f"Invalid version format: {version}. Expected 'major.minor' format.")
1922

20-
2123
with open('org/polypheny/prism/version.py', 'w') as f:
2224
f.write(f'MAJOR_VERSION = {major}\n')
2325
f.write(f'MINOR_VERSION = {minor}\n')
2426

25-
2627
with open('README.md', 'r', encoding='utf-8') as f:
2728
long_description = f.read()
2829

29-
setup(name='polypheny-prism-api',
30-
version=version,
31-
description='Polypheny Prism API files for Python',
32-
long_description=long_description,
33-
long_description_content_type='text/markdown',
34-
author="The Polypheny Project",
35-
author_email="[email protected]",
36-
url="https://polypheny.com/",
37-
project_urls={
30+
setup(
31+
name='polypheny-prism-api',
32+
version=version,
33+
description='Polypheny Prism API files for Python',
34+
long_description=long_description,
35+
long_description_content_type='text/markdown',
36+
author="The Polypheny Project",
37+
author_email="[email protected]",
38+
url="https://polypheny.com/",
39+
project_urls={
3840
"Documentation": "https://docs.polypheny.com/en/latest/query_interfaces/prism/protocol",
3941
"Code": "https://github.com/polypheny/Polypheny-Prism-API"
40-
},
41-
license="Apache License, Version 2.0",
42-
packages=['org/polypheny/prism'],
43-
install_requires=[
44-
"protobuf==4.24.3",
45-
],
42+
},
43+
license="Apache License, Version 2.0",
44+
packages=['org/polypheny/prism'],
45+
install_requires=[
46+
"protobuf==4.24.3",
47+
],
4648
)

0 commit comments

Comments
 (0)