Skip to content

Commit d18e591

Browse files
authored
Add PyPI publishing workflows, uv, pytest (#5)
1 parent 03b60ae commit d18e591

File tree

12 files changed

+1029
-1502
lines changed

12 files changed

+1029
-1502
lines changed

.github/workflows/build.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Build
5+
6+
on:
7+
push:
8+
branches: ["main"]
9+
pull_request:
10+
branches: ["main"]
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v5
24+
with:
25+
python-version: "3.12"
26+
enable-cache: true
27+
cache-dependency-glob: "requirements.txt"
28+
29+
- name: Install dependencies
30+
run: |
31+
if [ -f requirements.txt ]; then uv pip install -r requirements.txt; fi
32+
uv pip install pytest
33+
34+
- name: Install the package
35+
run: |
36+
uv pip install .
37+
38+
- name: Test with pytest
39+
run: |
40+
uv run pytest
41+
42+
- name: Check if the main script is installed
43+
run: |
44+
uv run convert_jsondoc --help

.github/workflows/publish.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: "3.12"
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v5
32+
33+
- name: Build package
34+
run: uv build --no-sources
35+
36+
- name: Publish package
37+
uses: pypa/gh-action-pypi-publish@v1
38+
with:
39+
user: __token__
40+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yaml

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,26 @@ on:
1010

1111
jobs:
1212
test:
13+
name: python
1314
runs-on: ubuntu-latest
1415

1516
steps:
1617
- name: Check out repository
17-
uses: actions/checkout@v2
18+
uses: actions/checkout@v4
1819

1920
- name: Set up Python
20-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v4
2122
with:
22-
python-version: '3.11'
23+
python-version: '3.12'
2324

24-
- name: Install Poetry
25-
uses: snok/install-poetry@v1
26-
with:
27-
version: 1.5.0
28-
virtualenvs-create: true
29-
virtualenvs-in-project: true
30-
31-
- name: Load cached venv
32-
id: cached-poetry-dependencies
33-
uses: actions/cache@v2
34-
with:
35-
path: .venv
36-
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v5
3727

3828
- name: Install dependencies
39-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
40-
run: poetry install --no-interaction
29+
run: uv sync --all-extras --dev
4130

4231
- name: Run tests
4332
run: |
44-
source .venv/bin/activate
45-
python tests/test_validation.py schema
46-
python tests/test_serialization.py
47-
python tests/test_html_to_jsondoc.py
48-
49-
# - name: Upload test results
50-
# uses: actions/upload-artifact@v2
51-
# with:
52-
# name: test-results
53-
# path: test-results # Adjust this path if your tests output results to a different directory
33+
uv run pytest
5434
5535

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
*.pdf
44
*.png
55
__pycache__
6-
build/
6+
build/
7+
*.docx
8+
*.pptx

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.12

conftest.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
# This collects tests that aren't standard pytest tests
6+
def pytest_collect_file(parent, file_path):
7+
# Special handling for test_validation.py
8+
if file_path.name == "test_validation.py":
9+
return ValidationTestFile.from_parent(parent, path=file_path)
10+
return None
11+
12+
class ValidationTestFile(pytest.File):
13+
def collect(self):
14+
# Create a special test item for test_validation.py
15+
yield ValidationTestItem.from_parent(self, name="test_validation")
16+
17+
class ValidationTestItem(pytest.Item):
18+
def runtest(self):
19+
# Run the test_validation.py script with "schema" as the argument
20+
import subprocess
21+
print(f"\n{'-'*80}\nRunning test_validation.py with 'schema' argument...")
22+
23+
result = subprocess.run(
24+
[sys.executable, str(self.fspath), "schema"],
25+
capture_output=True,
26+
text=True,
27+
)
28+
29+
# Always print the stdout for visibility
30+
if result.stdout:
31+
print(f"\nOutput from test_validation.py:")
32+
print(result.stdout)
33+
34+
if result.returncode != 0:
35+
raise ValidationTestFailure(result.stdout, result.stderr)
36+
37+
print(f"test_validation.py completed successfully.\n{'-'*80}")
38+
39+
def reportinfo(self):
40+
return self.fspath, 0, f"test_validation.py schema"
41+
42+
class ValidationTestFailure(Exception):
43+
def __init__(self, stdout, stderr):
44+
self.stdout = stdout
45+
self.stderr = stderr
46+
super().__init__(f"test_validation.py failed")
47+
48+
@pytest.hookimpl(tryfirst=True)
49+
def pytest_exception_interact(node, call, report):
50+
if isinstance(call.excinfo.value, ValidationTestFailure):
51+
failure = call.excinfo.value
52+
print(f"test_validation.py failed!")
53+
if failure.stderr:
54+
print(f"STDERR:\n{failure.stderr}")
55+
print(f"{'-'*80}")

jsondoc/transcribe/benchmark.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,3 @@ def transcribe_resize(
113113
print(f"Skipping resolution {height}")
114114
print("====================================================")
115115

116-
import ipdb
117-
118-
ipdb.set_trace()

0 commit comments

Comments
 (0)