Skip to content

Commit 72b36da

Browse files
committed
Add Python package
1 parent 646102b commit 72b36da

File tree

12 files changed

+634
-20
lines changed

12 files changed

+634
-20
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: publish downstream packages
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
description: The release tag to publish
8+
required: true
9+
type: string
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
jobs:
16+
nodejs-publish:
17+
name: Publish Node.js release
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
id-token: write
22+
23+
defaults:
24+
run:
25+
working-directory: node
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v5
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: "20.x"
34+
registry-url: "https://registry.npmjs.org"
35+
36+
- name: Install dependencies cleanly
37+
run: npm ci
38+
39+
- name: Build package
40+
run: npm run build -- --tag ${{ inputs.tag }}
41+
42+
- name: Publish to NPM
43+
run: npm publish --provenance --access public
44+
env:
45+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
46+
47+
python-sdist:
48+
name: Build source distribution
49+
runs-on: ubuntu-latest
50+
51+
outputs:
52+
artifact-name: ${{ steps.locate-artifact.outputs.file-name }}
53+
54+
defaults:
55+
run:
56+
working-directory: python
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v5
60+
61+
- name: Install UV
62+
uses: astral-sh/setup-uv@v6
63+
64+
- name: Build source distribution
65+
run: uv build --sdist
66+
env:
67+
DOTSLASH_VERSION: ${{ inputs.tag }}
68+
69+
- name: Locate source distribution
70+
id: locate-artifact
71+
run: |-
72+
sdist_name=$(basename dist/*)
73+
echo "file-name=${sdist_name}" >> $GITHUB_OUTPUT
74+
75+
- name: Upload source distribution artifact
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: artifact-sdist
79+
path: dist/${{ steps.locate-artifact.outputs.file-name }}
80+
if-no-files-found: error
81+
82+
python-wheels:
83+
name: Build wheels for ${{ matrix.archs }} on ${{ matrix.os }}
84+
needs:
85+
- python-sdist
86+
runs-on: ${{ matrix.os }}
87+
strategy:
88+
fail-fast: false
89+
matrix:
90+
include:
91+
- os: ubuntu-24.04-arm
92+
archs: aarch64
93+
- os: ubuntu-latest
94+
archs: x86_64
95+
- os: macos-latest
96+
archs: arm64
97+
- os: macos-15-intel
98+
archs: x86_64
99+
- os: windows-11-arm
100+
archs: ARM64
101+
- os: windows-latest
102+
archs: AMD64
103+
104+
defaults:
105+
run:
106+
working-directory: python
107+
steps:
108+
- name: Checkout repository
109+
uses: actions/checkout@v5
110+
111+
- name: Download source distribution
112+
uses: actions/download-artifact@v4
113+
with:
114+
name: artifact-sdist
115+
path: dist
116+
117+
# TODO: Remove this once the action supports specifying extras, see:
118+
# https://github.com/pypa/cibuildwheel/pull/2630
119+
- name: Install UV
120+
if: runner.os != 'Linux'
121+
uses: astral-sh/setup-uv@v6
122+
123+
- name: Build wheels
124+
uses: pypa/[email protected]
125+
with:
126+
package-dir: dist/${{ needs.python-sdist.outputs.artifact-name }}
127+
env:
128+
DOTSLASH_VERSION: ${{ inputs.tag }}
129+
CIBW_ARCHS: ${{ matrix.archs }}
130+
131+
- name: Upload wheel artifacts
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: artifact-wheels-${{ matrix.os }}-${{ matrix.archs }}
135+
path: wheelhouse/*.whl
136+
if-no-files-found: error
137+
138+
python-publish:
139+
name: Publish Python release
140+
needs:
141+
- python-sdist
142+
- python-wheels
143+
runs-on: ubuntu-latest
144+
145+
permissions:
146+
id-token: write
147+
148+
steps:
149+
- name: Download artifacts
150+
uses: actions/download-artifact@v4
151+
with:
152+
pattern: artifact-*
153+
merge-multiple: true
154+
path: dist
155+
156+
- name: Push build artifacts to PyPI
157+
uses: pypa/[email protected]
158+
with:
159+
skip-existing: true

.github/workflows/release.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,14 @@ jobs:
243243
run: gh release upload %GITHUB_REF:~10% dotslash-windows-arm64.%GITHUB_REF:~10%.tar.gz
244244
shell: cmd
245245

246-
npm-publish:
246+
publish-downstream:
247247
# This job depends on release assets uploaded by the previous jobs.
248248
# Keep this job's dependencies in sync with node/platforms.js.
249249
needs: [macos, windows, windows-arm64, linux-musl-x86_64, linux-musl-arm64]
250-
runs-on: ubuntu-latest
250+
uses: ./.github/workflows/release-downstream.yml
251251
permissions:
252252
contents: read
253253
id-token: write
254-
defaults:
255-
run:
256-
working-directory: node
257-
steps:
258-
- uses: actions/checkout@v4
259-
# Setup .npmrc file to publish to npm
260-
- uses: actions/setup-node@v4
261-
with:
262-
node-version: '20.x'
263-
registry-url: 'https://registry.npmjs.org'
264-
- run: npm ci
265-
- run: npm run build -- --tag ${GITHUB_REF#refs/tags/}
266-
- run: npm publish --provenance --access public
267-
env:
268-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
254+
with:
255+
tag: ${{ github.ref_name }}
256+
secrets: inherit

.github/workflows/test-python.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
13+
cancel-in-progress: true
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
jobs:
20+
test:
21+
name: Test
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v5
27+
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v6
30+
31+
- name: Static analysis
32+
run: uvx ruff check src
33+
34+
- name: Formatting
35+
run: uvx ruff format --check --diff src

.gitignore

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# Global files
12
.DS_Store
2-
/target
3-
**/node_modules
4-
node/bin/*/
3+
4+
# Root directories
5+
/target/
6+
7+
# Python
8+
__pycache__/
9+
/python/.ruff_cache/
10+
*.pyc
11+
12+
# Node.js
13+
node_modules/
14+
/node/bin/*/

python/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# DotSlash: simplified executable deployment
2+
3+
[![CI - Test](https://github.com/facebook/dotslash/actions/workflows/test-python.yml/badge.svg)](https://github.com/facebook/dotslash/actions/workflows/test-python.yml)
4+
[![PyPI - Version](https://img.shields.io/pypi/v/dotslash.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.org/project/dotslash/)
5+
[![PyPI - Downloads](https://img.shields.io/pypi/dm/dotslash.svg?color=blue&label=Downloads&logo=pypi&logoColor=gold)](https://pypi.org/project/dotslash/)
6+
[![Built by Hatch](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pypa/hatch/master/docs/assets/badge/v0.json)](https://github.com/pypa/hatch)
7+
[![Ruff linting/formatting](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
8+
9+
-----
10+
11+
[DotSlash](https://dotslash-cli.com/docs/) (`dotslash`) is a command-line tool that lets you represent a set of platform-specific, heavyweight executables with an equivalent small, easy-to-read text file. In turn, this makes it efficient to store executables in source control without hurting repository size. This paves the way for checking build toolchains and other tools directly into the repo, reducing dependencies on the host environment and thereby facilitating reproducible builds.
12+
13+
The `dotslash` package allows you to use DotSlash in your Python projects without having to install DotSlash globally.
14+
15+
***Table of Contents***
16+
17+
- [Using as a library](#using-as-a-library)
18+
- [Using as a command-line tool](#using-as-a-command-line-tool)
19+
- [Building from source](#building-from-source)
20+
- [License](#license)
21+
22+
## Using as a library
23+
24+
The `dotslash.locate` function returns the path to the DotSlash binary that was installed by this package.
25+
26+
```pycon
27+
>>> import dotslash
28+
>>> dotslash.locate()
29+
'/root/.local/bin/dotslash'
30+
```
31+
32+
## Using as a command-line tool
33+
34+
The installed DotSlash binary can be invoked directly by running the `dotslash` module as a script.
35+
36+
```
37+
python -m dotslash path/to/dotslash-file.json
38+
```
39+
40+
## Building from source
41+
42+
When building or installing from this directory, the `DOTSLASH_VERSION` environment variable must be set to the version of DotSlash to use. A preceding `v` is accepted but not required.
43+
44+
```
45+
DOTSLASH_VERSION=0.5.8 python -m build
46+
```
47+
48+
This will use the binaries from DotSlash's [GitHub releases](https://github.com/facebook/dotslash/releases). If there is a directory of GitHub release assets, you can use that directly with the `DOTSLASH_SOURCE` environment variable.
49+
50+
```
51+
DOTSLASH_VERSION=0.5.8 DOTSLASH_SOURCE=path/to/dotslash-assets python -m build
52+
```
53+
54+
The DotSlash source is set to `release` by default.
55+
56+
## License
57+
58+
DotSlash is licensed under both the MIT license and Apache-2.0 license; the exact terms can be found in the [LICENSE-MIT](https://github.com/facebook/dotslash/blob/main/LICENSE-MIT) and [LICENSE-APACHE](https://github.com/facebook/dotslash/blob/main/LICENSE-APACHE) files, respectively.

0 commit comments

Comments
 (0)