Skip to content

Commit f5a076e

Browse files
committed
Added ability to specify source directory
1 parent 87ecd25 commit f5a076e

7 files changed

Lines changed: 64 additions & 2 deletions

File tree

.github/workflows/test_action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,17 @@ jobs:
4444
pure_python_wheel: true
4545
test_extras: recommended
4646
test_command: python -c 'import test_package'
47+
48+
custom_build_directory:
49+
name: Test action (source-directory)
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v6
54+
- id: build
55+
uses: ./
56+
with:
57+
source-directory: packages/subpackage
58+
pure_python_wheel: true
59+
test_extras: test
60+
test_command: pytest --pyargs subpackage

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ jobs:
6868
test_command: pytest --pyargs test_package
6969
```
7070
71+
## Custom source directory
72+
73+
By default, the action builds from the repository root. If your package is in a
74+
subdirectory (e.g., in a monorepo or non-standard project layout), use the
75+
`source-directory` input:
76+
77+
```yaml
78+
jobs:
79+
build_sdist:
80+
name: Build source distribution
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v2
84+
- id: build
85+
uses: OpenAstronomy/build-python-dist@v1
86+
with:
87+
source-directory: packages/my-package
88+
test_command: pytest --pyargs my_package
89+
```
90+
7191
## Custom Python version
7292

7393
By default, the [`actions/setup-python`](https://github.com/actions/setup-python) action will install the latest Python 3 version for building and testing, however, the `OpenAstronomy/build-python-dist` action accepts a `python-version` string input to select a specific version,

action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ inputs:
2929
required: false
3030
default: '3.x'
3131
type: string
32+
source-directory:
33+
description: The directory containing the package to build, relative to the repository root
34+
required: false
35+
default: '.'
36+
type: string
3237
runs:
3338
using: "composite"
3439
steps:
@@ -47,7 +52,7 @@ runs:
4752

4853
- name: Build source distribution
4954
shell: bash
50-
run: python -m build --sdist .
55+
run: python -m build --sdist --outdir dist ${{ inputs.source-directory }}
5156

5257
- name: Create and activate a virtual environment
5358
shell: bash
@@ -80,7 +85,7 @@ runs:
8085

8186
- name: Build pure Python wheel distribution
8287
shell: bash
83-
run: python -m build --wheel .
88+
run: python -m build --wheel --outdir dist ${{ inputs.source-directory }}
8489
if: ${{ inputs.pure_python_wheel == 'true' }}
8590

8691
- name: Verify that one pure Python wheel was built

packages/subpackage/pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build-system]
2+
requires = ["setuptools>=61.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "subpackage"
7+
version = "0.1.0"
8+
9+
[project.optional-dependencies]
10+
test = ["pytest"]
11+
12+
[dependency-groups]
13+
test = ["pytest>=8.0.0"]
14+
15+
[tool.setuptools]
16+
include-package-data = false
17+
18+
[tool.setuptools.packages]
19+
find = {namespaces = false}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

packages/subpackage/subpackage/tests/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test_import():
2+
import subpackage
3+
assert subpackage.__version__ == "0.1.0"

0 commit comments

Comments
 (0)