diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml index 03f837f..ed3a72c 100644 --- a/.github/workflows/test_action.yml +++ b/.github/workflows/test_action.yml @@ -44,3 +44,17 @@ jobs: pure_python_wheel: true test_extras: recommended test_command: python -c 'import test_package' + + custom_source_directory: + name: Test action (custom source-directory) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + - id: build + uses: ./ + with: + source-directory: packages/subpackage + pure_python_wheel: true + test_extras: test + test_command: pytest --pyargs subpackage diff --git a/README.md b/README.md index 50d852c..20ce577 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,26 @@ jobs: test_command: pytest --pyargs test_package ``` +## Custom source directory + +By default, the action builds from the repository root. If your package is in a +subdirectory (e.g., in a monorepo or non-standard project layout), use the +`source-directory` input: + +```yaml +jobs: + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - id: build + uses: OpenAstronomy/build-python-dist@v1 + with: + source-directory: packages/my-package + test_command: pytest --pyargs my_package +``` + ## Custom Python version 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, diff --git a/action.yml b/action.yml index 608d9e7..4b24975 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,11 @@ inputs: required: false default: '3.x' type: string + source-directory: + description: The directory containing the package to build, relative to the repository root + required: false + default: '.' + type: string runs: using: "composite" steps: @@ -47,7 +52,7 @@ runs: - name: Build source distribution shell: bash - run: python -m build --sdist . + run: python -m build --sdist --outdir dist ${{ inputs.source-directory }} - name: Create and activate a virtual environment shell: bash @@ -80,7 +85,7 @@ runs: - name: Build pure Python wheel distribution shell: bash - run: python -m build --wheel . + run: python -m build --wheel --outdir dist ${{ inputs.source-directory }} if: ${{ inputs.pure_python_wheel == 'true' }} - name: Verify that one pure Python wheel was built diff --git a/packages/subpackage/pyproject.toml b/packages/subpackage/pyproject.toml new file mode 100644 index 0000000..de91142 --- /dev/null +++ b/packages/subpackage/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "subpackage" +version = "0.1.0" + +[project.optional-dependencies] +test = ["pytest"] + +[dependency-groups] +test = ["pytest>=8.0.0"] + +[tool.setuptools] +include-package-data = false + +[tool.setuptools.packages] +find = {namespaces = false} diff --git a/packages/subpackage/subpackage/__init__.py b/packages/subpackage/subpackage/__init__.py new file mode 100644 index 0000000..3dc1f76 --- /dev/null +++ b/packages/subpackage/subpackage/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/packages/subpackage/subpackage/tests/__init__.py b/packages/subpackage/subpackage/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/packages/subpackage/subpackage/tests/test_subpackage.py b/packages/subpackage/subpackage/tests/test_subpackage.py new file mode 100644 index 0000000..68ada71 --- /dev/null +++ b/packages/subpackage/subpackage/tests/test_subpackage.py @@ -0,0 +1,3 @@ +def test_import(): + import subpackage + assert subpackage.__version__ == "0.1.0"