-
Notifications
You must be signed in to change notification settings - Fork 0
feat(pypi): add tywrap-ir PyPI publishing #134
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
Some comments aren't visible on the classic Files Changed page.
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,141 @@ | ||
| name: Publish tywrap-ir to PyPI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'tywrap-ir-v*' | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: 'Dry run (skip actual publish)' | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| validate: | ||
| name: Validate Release | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version: ${{ steps.version.outputs.version }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Extract version from tag | ||
| id: version | ||
| run: | | ||
| if [[ "${{ github.ref }}" == refs/tags/tywrap-ir-v* ]]; then | ||
| VERSION="${GITHUB_REF#refs/tags/tywrap-ir-v}" | ||
| else | ||
| VERSION=$(grep 'version = ' tywrap_ir/pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | ||
| fi | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Publishing tywrap-ir version: $VERSION" | ||
|
|
||
| - name: Validate version format | ||
| run: | | ||
| VERSION="${{ steps.version.outputs.version }}" | ||
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then | ||
| echo "Invalid version format: $VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Check version matches pyproject.toml | ||
| if: startsWith(github.ref, 'refs/tags/tywrap-ir-v') | ||
| run: | | ||
| TAG_VERSION="${{ steps.version.outputs.version }}" | ||
| PKG_VERSION=$(grep 'version = ' tywrap_ir/pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | ||
| if [[ "$TAG_VERSION" != "$PKG_VERSION" ]]; then | ||
| echo "Tag version ($TAG_VERSION) does not match pyproject.toml ($PKG_VERSION)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| test: | ||
| name: Test | ||
| needs: validate | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: true | ||
| matrix: | ||
| python-version: ['3.10', '3.11', '3.12'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install tywrap_ir | ||
| run: | | ||
| cd tywrap_ir | ||
| pip install -e . | ||
|
|
||
| - name: Test CLI | ||
| run: | | ||
| tywrap-ir --module math --output /tmp/math_ir.json | ||
| python -c "import json; data = json.load(open('/tmp/math_ir.json')); print(f'Extracted {len(data.get(\"functions\", []))} functions from math module')" | ||
|
|
||
| - name: Test Python API | ||
| run: | | ||
| python -c "from tywrap_ir import extract_module_ir, IR_VERSION, __version__; print(f'IR_VERSION: {IR_VERSION}, __version__: {__version__}')" | ||
|
|
||
| build: | ||
| name: Build Package | ||
| needs: [validate, test] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install build tools | ||
| run: pip install build twine | ||
|
|
||
| - name: Build package | ||
| run: | | ||
| cd tywrap_ir | ||
| python -m build | ||
|
|
||
| - name: Check package | ||
| run: | | ||
| cd tywrap_ir | ||
| twine check dist/* | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: dist | ||
| path: tywrap_ir/dist/ | ||
|
|
||
| publish: | ||
| name: Publish to PyPI | ||
| needs: [validate, test, build] | ||
| runs-on: ubuntu-latest | ||
| environment: pypi | ||
| permissions: | ||
| id-token: write | ||
| steps: | ||
| - name: Download artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| - name: Publish (dry run) | ||
| if: inputs.dry_run == true | ||
| run: | | ||
| echo "Dry run - would publish:" | ||
| ls -la dist/ | ||
|
|
||
| - name: Publish to PyPI | ||
| if: inputs.dry_run != true | ||
bbopen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| packages-dir: dist/ | ||
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 |
|---|---|---|
| @@ -1,11 +1,45 @@ | ||
| # tywrap_ir | ||
| # tywrap-ir | ||
|
|
||
| Python IR extractor for tywrap. Emits versioned JSON IR for Python modules using inspect/typing/importlib. | ||
| [](https://pypi.org/project/tywrap-ir/) | ||
| [](https://pypi.org/project/tywrap-ir/) | ||
| [](https://opensource.org/licenses/MIT) | ||
|
|
||
| ## Usage | ||
| Python IR extractor for [tywrap](https://github.com/bbopen/tywrap). Emits versioned JSON IR for Python modules using inspect/typing/importlib. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install tywrap-ir | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| # Extract IR for a module | ||
| python -m tywrap_ir --module math | ||
| # or | ||
|
|
||
| # Or using the CLI | ||
| tywrap-ir --module math | ||
|
|
||
| # Output to file | ||
| tywrap-ir --module pandas --output pandas_ir.json | ||
| ``` | ||
|
|
||
| ## What is this? | ||
|
|
||
| This package is the Python component of tywrap, a TypeScript wrapper generator for Python libraries. It analyzes Python modules and extracts type information into a JSON intermediate representation (IR) that tywrap uses to generate TypeScript bindings. | ||
|
|
||
| You typically don't need to use this package directly - the `tywrap` npm package invokes it automatically during code generation. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Python 3.10+ | ||
|
|
||
| ## Related | ||
|
|
||
| - [tywrap](https://www.npmjs.com/package/tywrap) - The main TypeScript package | ||
| - [GitHub](https://github.com/bbopen/tywrap) - Source code and issues | ||
|
|
||
| ## License | ||
|
|
||
| MIT |
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 |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| __all__ = [ | ||
| "extract_module_ir", | ||
| "IR_VERSION", | ||
| "__version__", | ||
| ] | ||
|
|
||
| __version__ = "0.1.2" | ||
| IR_VERSION = "0.1.0" | ||
|
|
||
| from .ir import extract_module_ir # noqa: E402 |
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.