Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Build

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
enable-cache: true
cache-dependency-glob: "requirements.txt"

- name: Install dependencies
run: |
if [ -f requirements.txt ]; then uv pip install -r requirements.txt; fi
uv pip install pytest

- name: Install the package
run: |
uv pip install .

- name: Test with pytest
run: |
uv run pytest

- name: Check if the main script is installed
run: |
uv run convert_jsondoc --help
40 changes: 40 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Build package
run: uv build --no-sources

- name: Publish package
uses: pypa/gh-action-pypi-publish@v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
36 changes: 8 additions & 28 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,26 @@ on:

jobs:
test:
name: python
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.0
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install uv
uses: astral-sh/setup-uv@v5

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

- name: Run tests
run: |
source .venv/bin/activate
python tests/test_validation.py schema
python tests/test_serialization.py
python tests/test_html_to_jsondoc.py

# - name: Upload test results
# uses: actions/upload-artifact@v2
# with:
# name: test-results
# path: test-results # Adjust this path if your tests output results to a different directory
uv run pytest


4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
*.pdf
*.png
__pycache__
build/
build/
*.docx
*.pptx
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11
3.12
55 changes: 55 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import sys
import pytest

# This collects tests that aren't standard pytest tests
def pytest_collect_file(parent, file_path):
# Special handling for test_validation.py
if file_path.name == "test_validation.py":
return ValidationTestFile.from_parent(parent, path=file_path)
return None

class ValidationTestFile(pytest.File):
def collect(self):
# Create a special test item for test_validation.py
yield ValidationTestItem.from_parent(self, name="test_validation")

class ValidationTestItem(pytest.Item):
def runtest(self):
# Run the test_validation.py script with "schema" as the argument
import subprocess
print(f"\n{'-'*80}\nRunning test_validation.py with 'schema' argument...")

result = subprocess.run(
[sys.executable, str(self.fspath), "schema"],
capture_output=True,
text=True,
)

# Always print the stdout for visibility
if result.stdout:
print(f"\nOutput from test_validation.py:")
print(result.stdout)

if result.returncode != 0:
raise ValidationTestFailure(result.stdout, result.stderr)

print(f"test_validation.py completed successfully.\n{'-'*80}")

def reportinfo(self):
return self.fspath, 0, f"test_validation.py schema"

class ValidationTestFailure(Exception):
def __init__(self, stdout, stderr):
self.stdout = stdout
self.stderr = stderr
super().__init__(f"test_validation.py failed")

@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(node, call, report):
if isinstance(call.excinfo.value, ValidationTestFailure):
failure = call.excinfo.value
print(f"test_validation.py failed!")
if failure.stderr:
print(f"STDERR:\n{failure.stderr}")
print(f"{'-'*80}")
3 changes: 0 additions & 3 deletions jsondoc/transcribe/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,3 @@ def transcribe_resize(
print(f"Skipping resolution {height}")
print("====================================================")

import ipdb

ipdb.set_trace()
Loading
Loading