Skip to content

Commit a138926

Browse files
authored
Merge pull request #358 from astrofrog/working-directory
Add the ability to specify a custom working directory for tox and custom build directory for publish
2 parents f2498e9 + 293b81b commit a138926

File tree

19 files changed

+184
-1
lines changed

19 files changed

+184
-1
lines changed

.github/workflows/publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ on:
101101
required: false
102102
default: ''
103103
type: string
104+
working-directory:
105+
description: The working directory containing the package to build, relative to the repository root
106+
required: false
107+
default: '.'
108+
type: string
104109
secrets:
105110
pypi_token:
106111
required: false
@@ -207,6 +212,7 @@ jobs:
207212
uses: pypa/cibuildwheel@298ed2fb2c105540f5ed055e8a6ad78d82dd3a7e # v3.3.1
208213
with:
209214
output-dir: dist
215+
package-dir: ${{ inputs.working-directory }}
210216
extras: uv
211217
env:
212218
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
@@ -256,6 +262,7 @@ jobs:
256262
test_command: ${{ inputs.test_command }}
257263
pure_python_wheel: false
258264
python-version: '3.12'
265+
source-directory: ${{ inputs.working-directory }}
259266
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
260267
if: |
261268
needs.targets.outputs.upload_to_pypi == 'true' || inputs.upload_to_anaconda || inputs.save_artifacts

.github/workflows/publish_pure_python.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ on:
8888
required: false
8989
default: ''
9090
type: string
91+
working-directory:
92+
description: The working directory containing the package to build, relative to the repository root
93+
required: false
94+
default: '.'
95+
type: string
9196
secrets:
9297
pypi_token:
9398
required: false
@@ -133,6 +138,7 @@ jobs:
133138
test_command: ${{ inputs.test_command }}
134139
python-version: ${{ inputs.python-version }}
135140
pure_python_wheel: true
141+
source-directory: ${{ inputs.working-directory }}
136142
- id: set-upload
137143
run: |
138144
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];

.github/workflows/test_publish.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
paths:
55
- .github/workflows/publish.yml
66
- .github/workflows/test_publish.yml
7+
- packages/subpackage_c/**
78
pull_request:
89
paths:
910
- .github/workflows/publish.yml
1011
- .github/workflows/test_publish.yml
12+
- packages/subpackage_c/**
1113

1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.ref }}
@@ -51,6 +53,16 @@ jobs:
5153
test_command: pytest --pyargs test_package
5254
targets: ''
5355

56+
release_working_directory:
57+
uses: ./.github/workflows/publish.yml
58+
with:
59+
working-directory: packages/subpackage_c
60+
test_command: python -c "from subpackage_c import example_func; assert example_func() == 42"
61+
targets: |
62+
- linux
63+
upload_to_pypi: false
64+
timeout-minutes: 30
65+
5466
test-upload-external:
5567
name: Use built dists and test upload
5668
runs-on: ubuntu-latest

.github/workflows/test_publish_pure_python.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
paths:
55
- .github/workflows/publish_pure_python.yml
66
- .github/workflows/test_publish_pure_python.yml
7+
- packages/subpackage/**
78
pull_request:
89
paths:
910
- .github/workflows/publish_pure_python.yml
1011
- .github/workflows/test_publish_pure_python.yml
12+
- packages/subpackage/**
1113

1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.ref }}
@@ -30,6 +32,14 @@ jobs:
3032
env: |
3133
CUSTOM_VAR: custom value
3234
35+
release_working_directory:
36+
uses: ./.github/workflows/publish_pure_python.yml
37+
with:
38+
working-directory: packages/subpackage
39+
test_extras: test
40+
test_command: pytest --pyargs subpackage
41+
upload_to_pypi: false
42+
timeout-minutes: 5
3343

3444
test-upload-external:
3545
name: Use built dists and test upload

.github/workflows/test_tox.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on:
66
- .github/workflows/test_tox.yml
77
- pyproject.toml
88
- tox.ini
9+
- packages/subpackage/**
910
pull_request:
1011
paths:
1112
- .github/workflows/tox.yml
1213
- .github/workflows/test_tox.yml
1314
- pyproject.toml
1415
- tox.ini
16+
- packages/subpackage/**
1517

1618
concurrency:
1719
group: ${{ github.workflow }}-${{ github.ref }}
@@ -204,3 +206,10 @@ jobs:
204206
- linux: py313t-linux
205207
- macos: py313t-macos
206208
- windows: py313t-windows
209+
210+
test_working_directory:
211+
uses: ./.github/workflows/tox.yml
212+
with:
213+
working-directory: packages/subpackage
214+
envs: |
215+
- linux: py312

.github/workflows/tox.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ on:
107107
required: false
108108
default: ''
109109
type: string
110+
working-directory:
111+
description: The working directory for running tox, relative to the repository root
112+
required: false
113+
default: '.'
114+
type: string
110115
secrets:
111116
CODECOV_TOKEN:
112117
description: Codecov upload token
@@ -153,6 +158,7 @@ jobs:
153158
defaults:
154159
run:
155160
shell: bash -l {0}
161+
working-directory: ${{ inputs.working-directory }}
156162
steps:
157163

158164
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ MANIFEST
3434
*.manifest
3535
*.spec
3636
*.c
37+
# Exception for test package C extension
38+
!packages/subpackage_c/subpackage_c/_example.c
3739

3840
# Installer logs
3941
pip-log.txt

docs/source/publish.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,25 @@ submodules
224224

225225
Whether to checkout submodules. Default is ``true``.
226226

227+
working-directory
228+
^^^^^^^^^^^^^^^^^
229+
230+
The working directory containing the package to build, relative to the
231+
repository root. Default is ``.`` (the repository root).
232+
233+
This is useful when your package is located in a subdirectory of the
234+
repository, such as in monorepos where multiple packages exist in the
235+
same repository, or when using a non-standard project layout.
236+
237+
.. code:: yaml
238+
239+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1
240+
with:
241+
working-directory: packages/my-package
242+
test_command: pytest --pyargs my_package
243+
secrets:
244+
pypi_token: ${{ secrets.pypi_token }}
245+
227246
Secrets
228247
~~~~~~~
229248

docs/source/publish_pure_python.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ submodules
141141

142142
Whether to checkout submodules. Default is ``true``.
143143

144+
working-directory
145+
^^^^^^^^^^^^^^^^^
146+
147+
The working directory containing the package to build, relative to the
148+
repository root. Default is ``.`` (the repository root).
149+
150+
This is useful when your package is located in a subdirectory of the
151+
repository, such as in monorepos where multiple packages exist in the
152+
same repository, or when using a non-standard project layout.
153+
154+
.. code:: yaml
155+
156+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
157+
with:
158+
working-directory: packages/my-package
159+
test_command: pytest --pyargs my_package
160+
secrets:
161+
pypi_token: ${{ secrets.pypi_token }}
162+
144163
save_artifacts
145164
^^^^^^^^^^^^^^
146165

docs/source/tox.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Inputs
3131

3232
A specification of tox environments must be passed to the ``envs``
3333
input. There are a number of other inputs. All of these inputs (except
34-
``submodules``) can also be specified under each tox environment to
34+
``submodules`` and ``working-directory``) can also be specified under each tox environment to
3535
overwrite the global value.
3636

3737
In the following example ``test1`` will pass ``--arg-local`` to pytest,
@@ -434,6 +434,24 @@ submodules
434434

435435
Whether to checkout submodules. Default is ``true``.
436436

437+
working-directory
438+
^^^^^^^^^^^^^^^^^
439+
440+
The working directory for running tox, relative to the repository root.
441+
Default is ``.`` (the repository root).
442+
443+
This is useful when your package is located in a subdirectory of the
444+
repository, such as in monorepos where multiple packages exist in the
445+
same repository, or when using a non-standard project layout.
446+
447+
.. code:: yaml
448+
449+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
450+
with:
451+
working-directory: packages/my-package
452+
envs: |
453+
- linux: py312
454+
437455
Secrets
438456
~~~~~~~
439457

0 commit comments

Comments
 (0)