Skip to content

Commit fdc239c

Browse files
committed
2 parents f5b09ac + 48dc713 commit fdc239c

19 files changed

Lines changed: 2970 additions & 1316 deletions

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PYTHONPATH=${workspaceFolder}/src
2+
MPLBACKEND=Agg
3+
VISPY_GL_LIB=osmesa
4+
VISPY_USE_EGL=0

.github/workflows/examples.yml

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: |
2121
python -m pip install --upgrade pip
2222
pip install -r requirements.txt
23-
pip install deepdiff
23+
pip install deepdiff colorama
2424
pip install .
2525
2626
- name: Run examples from README.md
@@ -29,44 +29,15 @@ jobs:
2929
cat test_examples.py
3030
python test_examples.py
3131
32-
- name: Run examples from README.md and compare JSON outputs
32+
- name: Parse README.md and generate test files
3333
run: |
34-
echo 'results = []' > test_examples.py
35-
cat README.md | grep -e '```python' -e '```' -e '^[^`]*$' | sed -e '/^```python/,/^```/!d' -e '/^```/d' -e 's/\(vfb.[^)]*)\)/results.append(\1)/g' >> test_examples.py
36-
echo 'from src.vfbquery.term_info_queries import *' > test_results.py
37-
cat README.md | grep -e '```python' -e '```' -e '^[^`]*$' | sed -e '/^```json/,/^```/!d' -e '/^```/d' -e 's/\(vfb.[^)]*)\)/print(\1)/g' | sed -e ':a;N;$!ba;s/\n/ /g' -e 's/```json/```json\n/g' -e 's/}[[:space:]]*{/},{/g' -e 's/ \+/ /g' | sed -e '1s/^/results=[/' -e '1s/$/]/' | sed 's/\btrue\b/True/g' | sed 's/\bfalse\b/False/g' >> test_results.py
38-
python -c """
39-
import sys
40-
import json
41-
import vfbquery as vfb
42-
from deepdiff import DeepDiff
43-
from io import StringIO
44-
from test_results import results
45-
json_blocks = results
46-
from test_examples import results
47-
python_blocks = results
34+
python -m src.test.readme_parser
35+
env:
36+
PYTHONPATH: ${{ github.workspace }}
4837

49-
print(f'Found {len(python_blocks)} Python code blocks')
50-
print(f'Found {len(json_blocks)} JSON blocks')
51-
52-
for python_code, expected_json in zip(python_blocks, json_blocks):
53-
# Compare the output JSON with the expected JSON
54-
diff = DeepDiff(expected_json, python_code, ignore_order=True, ignore_numeric_type_changes=True)
55-
56-
if diff:
57-
print('Error in example:')
58-
print('Expected JSON:')
59-
print(expected_json)
60-
print('Output JSON:')
61-
print(python_code)
62-
print('Difference:')
63-
print(diff)
64-
sys.exit(1)
65-
66-
print('All examples passed.')
67-
sys.stdout = sys.__stdout__"""
68-
shell: /usr/bin/bash -e {0}
38+
- name: Run examples from README.md and compare JSON outputs
39+
run: |
40+
python -m src.test.test_examples_diff
6941
env:
70-
pythonLocation: /opt/hostedtoolcache/Python/3.8.16/x64
71-
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.16/x64/lib
72-
42+
PYTHONPATH: ${{ github.workspace }}
43+

.github/workflows/publish_to_pypi.yaml

Lines changed: 102 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,115 @@
1-
name: Publish to PyPI
1+
name: Publish 🐍 📦 to PyPI
22

33
on:
4-
workflow_dispatch:
54
release:
65
types: [created]
7-
# TODO: For testing purpose, delete this trigger afterwards
8-
# push:
9-
# paths:
10-
# - '.github/workflows/publish_to_pypi.yaml'
116

127
jobs:
138
build-n-publish:
14-
name: Build and publish Python distributions to PyPI
15-
runs-on: ubuntu-22.04
9+
name: Build and publish Python 🐍 distributions 📦 to PyPI
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
1613
steps:
17-
- uses: actions/checkout@v2
18-
- name: Install semver
19-
run: |
20-
npm install semver
21-
- name: Update version in setup.py
22-
uses: actions/github-script@v4
23-
with:
24-
script: |
25-
const fs = require('fs');
26-
const semver = require('semver');
27-
const version = context.payload.release.tag_name.replace(/^v/, '');
28-
const setupFile = `${process.env.GITHUB_WORKSPACE}/setup.py`;
29-
const setupContent = fs.readFileSync(setupFile, 'utf8');
30-
const newSetupContent = setupContent.replace(
31-
/__version__\s*=\s*['"][^'"]*['"]/,
32-
`__version__ = '${version}'`
33-
);
34-
fs.writeFileSync(setupFile, newSetupContent, 'utf8');
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
- name: Set up Python 3.8
38-
uses: actions/setup-python@v2
14+
- uses: actions/checkout@v4
3915
with:
40-
python-version: 3.8
41-
- name: Install wheel and setuptools
42-
run: >-
43-
python -m
44-
pip install
45-
wheel
46-
setuptools
47-
get_version
48-
--user
49-
--upgrade
50-
- name: Build a binary wheel and a source tarball
51-
run: >-
52-
python3
53-
setup.py
54-
sdist
55-
bdist_wheel
56-
- name: Publish distribution to PyPI
57-
uses: pypa/gh-action-pypi-publish@release/v1
16+
fetch-depth: 0 # Fetch full history including tags
17+
ref: ${{ github.ref }} # Explicitly checkout the tag
18+
19+
- name: Set up Python 3.10.18
20+
uses: actions/setup-python@v5
5821
with:
59-
user: __token__
60-
password: ${{ secrets.PYPI_API_TOKEN }}
22+
python-version: 3.10.18
23+
24+
- name: Install build dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install build wheel "setuptools>=45,<69" twine
28+
python -m pip list
29+
30+
- name: Set version from GitHub Release tag
31+
run: |
32+
echo "Git information:"
33+
git tag -l
34+
git log -1 --oneline
35+
git describe --tags --always
36+
37+
# When running from a release, extract version from tag
38+
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
39+
# Extract clean version number from tag (removes v prefix)
40+
VERSION=${GITHUB_REF#refs/tags/v}
41+
echo "Running from GitHub release tag: v$VERSION"
42+
43+
# Set environment variables for the build
44+
echo "VERSION=$VERSION" >> $GITHUB_ENV
45+
46+
# Update version in setup.py
47+
echo "Updating version in setup.py to $VERSION"
48+
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$VERSION\"/" setup.py
49+
50+
# Update version in package __init__.py
51+
echo "Updating version in src/vfbquery/__init__.py to $VERSION"
52+
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$VERSION\"/" src/vfbquery/__init__.py
53+
54+
echo "Updated setup.py version:"
55+
grep "__version__" setup.py
56+
echo "Updated package version:"
57+
grep "__version__" src/vfbquery/__init__.py
58+
else
59+
# Not running from a tag, show current version
60+
echo "Not running from a tag, using existing version from setup.py"
61+
grep "__version__" setup.py
62+
fi
63+
64+
- name: Build distributions
65+
run: |
66+
echo "Building distributions..."
67+
python -m build
68+
69+
# Verify the source distribution metadata
70+
if [[ -n "$VERSION" ]]; then
71+
echo "Checking source distribution metadata:"
72+
SDIST_NAME_BASE="vfbquery-${VERSION}"
73+
SDIST_FILE="dist/${SDIST_NAME_BASE}.tar.gz"
74+
PKG_INFO_PATH="${SDIST_NAME_BASE}/PKG-INFO"
75+
echo "Extracting Version from PKG-INFO in ${SDIST_FILE} (path: ${PKG_INFO_PATH})"
76+
tar -zxf "${SDIST_FILE}" -O "${PKG_INFO_PATH}" | grep "^Version:"
77+
78+
# Verify the wheel metadata
79+
WHEEL_NAME="vfbquery-${VERSION}-py3-none-any.whl"
80+
WHEEL_FILE="dist/${WHEEL_NAME}"
81+
DIST_INFO_PATH="vfbquery-${VERSION}.dist-info/METADATA"
82+
echo "Extracting Version from ${DIST_INFO_PATH} in ${WHEEL_FILE}"
83+
unzip -p "${WHEEL_FILE}" "${DIST_INFO_PATH}" | grep "^Version:"
84+
fi
85+
86+
- name: Verify metadata with twine
87+
run: |
88+
python -m twine check dist/*
89+
90+
- name: Install and verify wheel version
91+
run: |
92+
# Install the wheel
93+
python -m pip install dist/*.whl
94+
95+
# Verify the installed version matches the expected version
96+
if [[ -n "$VERSION" ]]; then
97+
INSTALLED_VERSION=$(python -c "import vfbquery; print(getattr(vfbquery, '__version__', 'unknown'))" 2>/dev/null || echo "unknown")
98+
echo "Expected version: $VERSION"
99+
echo "Installed version: $INSTALLED_VERSION"
100+
101+
if [[ "$VERSION" != "$INSTALLED_VERSION" ]] && [[ "$INSTALLED_VERSION" != "unknown" ]]; then
102+
echo "WARNING: Version mismatch detected, but proceeding with build"
103+
fi
104+
105+
echo "Version verification completed"
106+
else
107+
echo "No explicit version set, skipping version verification"
108+
python -c "import vfbquery; print(f'Package installed successfully')" 2>/dev/null || echo "Package verification completed"
109+
fi
110+
111+
- name: Publish distribution 📦 to PyPI
112+
uses: pypa/gh-action-pypi-publish@v1.12.2
61113
# - name: Publish package to TestPyPI
62114
# uses: pypa/gh-action-pypi-publish@release/v1
63115
# with:

.github/workflows/python-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
- name: Set up Python
1313
uses: actions/setup-python@v2
1414
with:
15-
python-version: 3.7
15+
python-version: 3.8
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install -U pip
19-
python -m pip install -r requirements.txt
19+
python -m pip install -U -r requirements.txt
2020
python -m pip install .
2121
- name: Run term_info_queries_test
2222
run: |

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ src/vfbquery/ontology/__pycache__/
88
build/
99
test_examples.py
1010
test_results.py
11-
.vscode/launch.json
12-
.vscode/tasks.json
11+
.vscode
12+
.pytest_cache
13+
.venv
14+
.vscode/settings.json

.vscode/settings.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
{
2-
"python.analysis.typeCheckingMode": "basic"
2+
"python.analysis.typeCheckingMode": "basic",
3+
"python.testing.unittestArgs": [
4+
"-v",
5+
"-s",
6+
"./src/test/",
7+
"-p",
8+
"*test*.py"
9+
],
10+
"python.testing.pytestEnabled": false,
11+
"python.testing.unittestEnabled": true,
12+
"python.testing.cwd": "${workspaceFolder}",
13+
"python.envFile": "${workspaceFolder}/.env",
14+
"python.terminal.activateEnvironment": true,
15+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
316
}

0 commit comments

Comments
 (0)