-
Notifications
You must be signed in to change notification settings - Fork 6
Add Python bindings and publish them to PyPi #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Python CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Build & Test | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: jdx/mise-action@3c2e0cf82a5b2e5249f0d3635a4d83d0ae861518 # v4.2.5 | ||
| with: | ||
| install_args: rust | ||
| - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 | ||
| - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | ||
| with: | ||
| python-version: "3.14" | ||
| - run: pip install maturin pytest typst | ||
| - run: maturin build --out dist | ||
| - run: pip install dist/*.whl | ||
| - run: pytest bindings/python/tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| name: Python Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| linux: | ||
| name: Wheels (linux-${{ matrix.platform.target }}) | ||
| runs-on: ${{ matrix.platform.runner || 'ubuntu-latest' }} | ||
| timeout-minutes: 60 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| platform: | ||
| - target: x86_64 | ||
| - target: aarch64 | ||
| runner: ubuntu-24.04-arm | ||
| - target: armv7 | ||
| - target: s390x | ||
| - target: ppc64le | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | ||
| with: | ||
| python-version: "3.14" | ||
| - name: Build wheels | ||
| uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0 | ||
| with: | ||
| target: ${{ matrix.platform.target }} | ||
| args: --release --out dist | ||
| manylinux: auto | ||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: wheels-linux-${{ matrix.platform.target }} | ||
| path: dist | ||
| if-no-files-found: error | ||
|
|
||
| macos: | ||
| name: Wheels (macos-${{ matrix.target }}) | ||
| runs-on: macos-latest | ||
| timeout-minutes: 60 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: [x86_64, aarch64] | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: jdx/mise-action@3c2e0cf82a5b2e5249f0d3635a4d83d0ae861518 # v4.2.5 | ||
| with: | ||
| install_args: rust | ||
| - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | ||
| with: | ||
| python-version: "3.14" | ||
| - name: Build wheels | ||
| uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0 | ||
| with: | ||
| target: ${{ matrix.target }} | ||
| args: --release --out dist | ||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: wheels-macos-${{ matrix.target }} | ||
| path: dist | ||
| if-no-files-found: error | ||
|
|
||
| windows: | ||
| name: Wheels (windows-${{ matrix.target }}) | ||
| runs-on: windows-latest | ||
| timeout-minutes: 60 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: [x64] | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: jdx/mise-action@3c2e0cf82a5b2e5249f0d3635a4d83d0ae861518 # v4.2.5 | ||
| with: | ||
| install_args: rust | ||
| - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | ||
| with: | ||
| python-version: "3.14" | ||
| architecture: ${{ matrix.target }} | ||
| - name: Build wheels | ||
| uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0 | ||
| with: | ||
| target: ${{ matrix.target }} | ||
| args: --release --out dist | ||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: wheels-windows-${{ matrix.target }} | ||
| path: dist | ||
| if-no-files-found: error | ||
|
|
||
| sdist: | ||
| name: sdist | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - name: Build sdist | ||
| uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0 | ||
| with: | ||
| command: sdist | ||
| args: --out dist | ||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: wheels-sdist | ||
| path: dist | ||
| if-no-files-found: error | ||
|
|
||
| release: | ||
| name: Publish to PyPI | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| needs: [linux, macos, windows, sdist] | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| pattern: wheels-* | ||
| path: dist | ||
| merge-multiple: true | ||
| - name: Publish to PyPI | ||
| uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 | ||
| with: | ||
| packages-dir: dist | ||
| skip-existing: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [package] | ||
| name = "typdiff-python" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| publish = false | ||
|
|
||
| [lib] | ||
| name = "_typdiff" | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| typdiff = { path = "../.." } | ||
| pyo3 = { version = "0.29", features = ["extension-module", "abi3-py38"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from ._typdiff import diff, diff_files | ||
|
|
||
| __all__ = ["diff", "diff_files"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import os | ||
|
|
||
| def diff(old: bytes, new: bytes) -> bytes: | ||
| """Diff two Typst documents given as source bytes, returning diff markup as bytes.""" | ||
|
|
||
| def diff_files(old_path: str | os.PathLike[str], new_path: str | os.PathLike[str]) -> bytes: | ||
| """Diff two Typst documents given as file paths, returning diff markup as bytes.""" |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Restrict PyPI publishing to version tags.
workflow_dispatchcan run this workflow from a branch. Thereleasejob has no tag guard, so that run can publish an untagged build to PyPI.Remove
workflow_dispatchor addif: startsWith(github.ref, 'refs/tags/v')torelease.Proposed fix
release: name: Publish to PyPI + if: startsWith(github.ref, 'refs/tags/v') needs: [linux, macos, windows, sdist]🤖 Prompt for AI Agents
✅ Addressed in commits d55cd9b to 17b0338
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, but the
release.yamldoesn't have this guard either. Still adding it, but worth a second look by the maintainer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 10583
@imphil, the Python workflow now has the required tag guard at Line 118. A branch-dispatched run can build artifacts, but it cannot publish to PyPI.Your concern about
.github/workflows/release.ymlis valid. Itsworkflow_dispatchtrigger can run from a branch, and it has no equivalent guard:releasejob can create a GitHub Release.publishjob can executecargo publish.The maintainer should add the same tag condition to both jobs, or remove
workflow_dispatchif manual release runs are not required.You are interacting with an AI system.