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
Empty file.
778 changes: 778 additions & 0 deletions .github/test_projects/extras-and-dependency-groups/poetry.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[tool.poetry]
name = "extras-and-dependency-groups"
version = "0.1.0"
description = "Tests actions/analyze-project with a project that has extras and dependency groups"
authors = ["Joel Dixon <joel.dixon@ni.com>"]
readme = "README.md"
packages = [{include = "test_project", from = "src"}]

[tool.poetry.dependencies]
ni-python-styleguide = ">=0.4.7"
python = "^3.9"
requests = "^2.28.0"
# Optional dependencies for extras
colorama = {version = "^0.4.0", optional = true}
tomli = {version = "^2.0.0", optional = true}

[tool.poetry.extras]
# Small utility packages for testing extras
colors = ["colorama"]
serialization = ["tomli"]

[tool.poetry.group.dev.dependencies]
# Small packages for testing dependency groups
pytest = "^7.0.0"

[tool.poetry.group.docs.dependencies]
# Small documentation-related packages
markdown = "^3.4.0"

[tool.poetry.group.utils.dependencies]
# Small utility packages
click = "^8.0.0"

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Docstring required."""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module docstring."""
41 changes: 41 additions & 0 deletions .github/workflows/test_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ jobs:
name: Test analyze-project
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # If there are failures, sometimes it is instructive to see which combinations passed
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11]
Expand Down Expand Up @@ -269,6 +270,46 @@ jobs:
uses: ./analyze-project
with:
project-directory: ${{ github.workspace }}/.github/test_projects/only-ni-python-styleguide
- name: Analyze extras-and-dependency-groups project
uses: ./analyze-project
with:
project-directory: ${{ github.workspace }}/.github/test_projects/extras-and-dependency-groups
install-args: "--extras 'colors serialization' --with dev,docs,utils"
- name: Check for expected dependencies
run: |
echo "Checking for expected packages from extras and dependency groups..."
pip_list=$(poetry run pip list)
echo "Installed packages:"
echo "$pip_list"

# Check for extras packages
if ! echo "$pip_list" | grep -i "colorama"; then
echo "::error title=Test Failure::colorama (from colors extra) not found in pip list"
exit 1
fi
if ! echo "$pip_list" | grep -i "tomli"; then
echo "::error title=Test Failure::tomli (from serialization extra) not found in pip list"
exit 1
fi

# Check for dependency group packages
if ! echo "$pip_list" | grep -i "pytest"; then
echo "::error title=Test Failure::pytest (from dev group) not found in pip list"
exit 1
fi
if ! echo "$pip_list" | grep -i "markdown"; then
echo "::error title=Test Failure::markdown (from docs group) not found in pip list"
exit 1
fi
if ! echo "$pip_list" | grep -i "click"; then
echo "::error title=Test Failure::click (from utils group) not found in pip list"
exit 1
fi

echo "All expected packages found!"
working-directory: ${{ github.workspace }}/.github/test_projects/extras-and-dependency-groups
shell: bash


test_analyze_project_cache_hit:
name: Test analyze-project (cache hit)
Expand Down
11 changes: 7 additions & 4 deletions analyze-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ file associated with the Python project you are analyzing.
project-directory: ${{ github.workspace }}/packages/myproject
```

### `extras`
### `install-args`

If there are extras you need to install from your pyproject.toml, specify a space-separated list
of extra groups to install. For example,
If there are extra command-line arguments you need to install from your
pyproject.toml, specify them with this input. You can specify any arguments that
work with `poetry install` including `--extras` and `--with`. These
`install-args` will be appended to the basic command line which is `poetry
install -v`. For example,

```yaml
- uses: ni/python-actions/analyze-project@v0
with:
project-directory: ${{ github.workspace }}/packages/myproject
extras: 'docs drivers'
install-args: "--extras 'colors serialization' --with dev,docs,utils"
```
21 changes: 12 additions & 9 deletions analyze-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ inputs:
project-directory:
description: Path to the directory containing pyproject.toml.
default: ${{ github.workspace }}
extras:
# E.g. "docs drivers"
description: 'List of Poetry extras to install (separated by spaces)'
install-args:
# E.g. "--extras 'drivers addons' --with examples,docs"
description: 'Extra arguments. Install command will be "poetry install <install-args>".'
default: ''
required: false
type: string
Expand All @@ -38,18 +38,21 @@ runs:
- name: Check for lock changes
run: poetry check --lock -C "${{ inputs.project-directory }}"
shell: bash
- name: Generate install args hash
id: install_args_hash
run: |
install_args_hash=$(echo "${{ inputs.install-args }}" | sha256sum | cut -d ' ' -f1)
echo "hash=$install_args_hash" >> "$GITHUB_OUTPUT"
shell: bash
- name: Cache virtualenv
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: ${{ steps.get_project_info.outputs.venv-path }}
key: ${{ steps.get_project_info.outputs.name }}-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}
key: ${{ steps.get_project_info.outputs.name }}-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}-${{ steps.install_args_hash.outputs.hash }}
- name: Install ${{ steps.get_project_info.outputs.name }}
run: |
if [ -n "${{ inputs.extras }}" ]; then
poetry install -v --extras '${{ inputs.extras }}'
else
poetry install -v
fi
install_cmd="poetry install -v ${{ inputs.install-args }}"
eval $install_cmd
working-directory: ${{ inputs.project-directory }}
shell: bash
- name: Lint
Expand Down
Loading