Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ on:
required: false
default: ''
type: string
working-directory:
description: The working directory containing the package to build, relative to the repository root
required: false
default: '.'
type: string
secrets:
pypi_token:
required: false
Expand Down Expand Up @@ -207,6 +212,7 @@ jobs:
uses: pypa/cibuildwheel@298ed2fb2c105540f5ed055e8a6ad78d82dd3a7e # v3.3.1
with:
output-dir: dist
package-dir: ${{ inputs.working-directory }}
extras: uv
env:
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
Expand Down Expand Up @@ -256,6 +262,7 @@ jobs:
test_command: ${{ inputs.test_command }}
pure_python_wheel: false
python-version: '3.12'
source-directory: ${{ inputs.working-directory }}
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: |
needs.targets.outputs.upload_to_pypi == 'true' || inputs.upload_to_anaconda || inputs.save_artifacts
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/publish_pure_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ on:
required: false
default: ''
type: string
working-directory:
description: The working directory containing the package to build, relative to the repository root
required: false
default: '.'
type: string
secrets:
pypi_token:
required: false
Expand Down Expand Up @@ -133,6 +138,7 @@ jobs:
test_command: ${{ inputs.test_command }}
python-version: ${{ inputs.python-version }}
pure_python_wheel: true
source-directory: ${{ inputs.working-directory }}
- id: set-upload
run: |
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
paths:
- .github/workflows/publish.yml
- .github/workflows/test_publish.yml
- packages/subpackage_c/**
pull_request:
paths:
- .github/workflows/publish.yml
- .github/workflows/test_publish.yml
- packages/subpackage_c/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -51,6 +53,16 @@ jobs:
test_command: pytest --pyargs test_package
targets: ''

release_working_directory:
uses: ./.github/workflows/publish.yml
with:
working-directory: packages/subpackage_c
test_command: python -c "from subpackage_c import example_func; assert example_func() == 42"
targets: |
- linux
upload_to_pypi: false
timeout-minutes: 30

test-upload-external:
name: Use built dists and test upload
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test_publish_pure_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
paths:
- .github/workflows/publish_pure_python.yml
- .github/workflows/test_publish_pure_python.yml
- packages/subpackage/**
pull_request:
paths:
- .github/workflows/publish_pure_python.yml
- .github/workflows/test_publish_pure_python.yml
- packages/subpackage/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -30,6 +32,14 @@ jobs:
env: |
CUSTOM_VAR: custom value

release_working_directory:
uses: ./.github/workflows/publish_pure_python.yml
with:
working-directory: packages/subpackage
test_extras: test
test_command: pytest --pyargs subpackage
upload_to_pypi: false
timeout-minutes: 5

test-upload-external:
name: Use built dists and test upload
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/test_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
- .github/workflows/test_tox.yml
- pyproject.toml
- tox.ini
- packages/subpackage/**
pull_request:
paths:
- .github/workflows/tox.yml
- .github/workflows/test_tox.yml
- pyproject.toml
- tox.ini
- packages/subpackage/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -204,3 +206,10 @@ jobs:
- linux: py313t-linux
- macos: py313t-macos
- windows: py313t-windows

test_working_directory:
uses: ./.github/workflows/tox.yml
with:
working-directory: packages/subpackage
envs: |
- linux: py312
6 changes: 6 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ on:
required: false
default: ''
type: string
working-directory:
description: The working directory for running tox, relative to the repository root
required: false
default: '.'
type: string
secrets:
CODECOV_TOKEN:
description: Codecov upload token
Expand Down Expand Up @@ -153,6 +158,7 @@ jobs:
defaults:
run:
shell: bash -l {0}
working-directory: ${{ inputs.working-directory }}
steps:

- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ MANIFEST
*.manifest
*.spec
*.c
# Exception for test package C extension
!packages/subpackage_c/subpackage_c/_example.c

# Installer logs
pip-log.txt
Expand Down
19 changes: 19 additions & 0 deletions docs/source/publish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,25 @@ submodules

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

working-directory
^^^^^^^^^^^^^^^^^

The working directory containing the package to build, relative to the
repository root. Default is ``.`` (the repository root).

This is useful when your package is located in a subdirectory of the
repository, such as in monorepos where multiple packages exist in the
same repository, or when using a non-standard project layout.

.. code:: yaml
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1
with:
working-directory: packages/my-package
test_command: pytest --pyargs my_package
secrets:
pypi_token: ${{ secrets.pypi_token }}
Secrets
~~~~~~~

Expand Down
19 changes: 19 additions & 0 deletions docs/source/publish_pure_python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ submodules

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

working-directory
^^^^^^^^^^^^^^^^^

The working directory containing the package to build, relative to the
repository root. Default is ``.`` (the repository root).

This is useful when your package is located in a subdirectory of the
repository, such as in monorepos where multiple packages exist in the
same repository, or when using a non-standard project layout.

.. code:: yaml

uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
working-directory: packages/my-package
test_command: pytest --pyargs my_package
secrets:
pypi_token: ${{ secrets.pypi_token }}

save_artifacts
^^^^^^^^^^^^^^

Expand Down
20 changes: 19 additions & 1 deletion docs/source/tox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Inputs

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

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

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

working-directory
^^^^^^^^^^^^^^^^^

The working directory for running tox, relative to the repository root.
Default is ``.`` (the repository root).

This is useful when your package is located in a subdirectory of the
repository, such as in monorepos where multiple packages exist in the
same repository, or when using a non-standard project layout.

.. code:: yaml

uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
working-directory: packages/my-package
envs: |
- linux: py312

Secrets
~~~~~~~

Expand Down
19 changes: 19 additions & 0 deletions packages/subpackage/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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}
1 change: 1 addition & 0 deletions packages/subpackage/subpackage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Empty file.
3 changes: 3 additions & 0 deletions packages/subpackage/subpackage/tests/test_subpackage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_import():
import subpackage
assert subpackage.__version__ == "0.1.0"
6 changes: 6 additions & 0 deletions packages/subpackage/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tox]
envlist = py312

[testenv]
deps = pytest
commands = pytest {posargs}
10 changes: 10 additions & 0 deletions packages/subpackage_c/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"

[project]
name = "subpackage_c"
version = "0.1.0"

[project.optional-dependencies]
test = ["pytest"]
8 changes: 8 additions & 0 deletions packages/subpackage_c/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from setuptools import Extension, find_packages, setup

setup(
packages=find_packages(),
ext_modules=[
Extension("subpackage_c._example", ["subpackage_c/_example.c"]),
],
)
5 changes: 5 additions & 0 deletions packages/subpackage_c/subpackage_c/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__version__ = "0.1.0"

from ._example import example_func

__all__ = ["example_func"]
23 changes: 23 additions & 0 deletions packages/subpackage_c/subpackage_c/_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

static PyObject* example_func(PyObject* self, PyObject* args) {
return PyLong_FromLong(42);
}

static PyMethodDef ExampleMethods[] = {
{"example_func", example_func, METH_NOARGS, "Return 42"},
{NULL, NULL, 0, NULL}
};

static struct PyModuleDef examplemodule = {
PyModuleDef_HEAD_INIT,
"_example",
NULL,
-1,
ExampleMethods
};

PyMODINIT_FUNC PyInit__example(void) {
return PyModule_Create(&examplemodule);
}
Loading