Skip to content

Commit f6f8738

Browse files
authored
Allow adding install-args to the poetry install command in analyze-project (#40)
* Allow dependency groups to be specified for install * Add test project for extras and dependency groups * Don't check base dependencies * Fix extras and poetry check --lock * Add install-args input instead of separate extras and dependency-groups inputs * Add hash of install-args to the cache key * Fix test where we were using 'extras' and 'dependency-groups' * Fix install command * Add single quotes around two space-delimited extras * Add fail-fast: false so all analyze-project tests complete even if one fails. Add an intentional failure to test this * Fix intentionally introduced error since the fail-fast: false worked * PR feedback from Brad
1 parent f42e2f2 commit f6f8738

File tree

8 files changed

+876
-13
lines changed

8 files changed

+876
-13
lines changed

.github/test_projects/extras-and-dependency-groups/README.md

Whitespace-only changes.

.github/test_projects/extras-and-dependency-groups/poetry.lock

Lines changed: 778 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[tool.poetry]
2+
name = "extras-and-dependency-groups"
3+
version = "0.1.0"
4+
description = "Tests actions/analyze-project with a project that has extras and dependency groups"
5+
authors = ["Joel Dixon <[email protected]>"]
6+
readme = "README.md"
7+
packages = [{include = "test_project", from = "src"}]
8+
9+
[tool.poetry.dependencies]
10+
ni-python-styleguide = ">=0.4.7"
11+
python = "^3.9"
12+
requests = "^2.28.0"
13+
# Optional dependencies for extras
14+
colorama = {version = "^0.4.0", optional = true}
15+
tomli = {version = "^2.0.0", optional = true}
16+
17+
[tool.poetry.extras]
18+
# Small utility packages for testing extras
19+
colors = ["colorama"]
20+
serialization = ["tomli"]
21+
22+
[tool.poetry.group.dev.dependencies]
23+
# Small packages for testing dependency groups
24+
pytest = "^7.0.0"
25+
26+
[tool.poetry.group.docs.dependencies]
27+
# Small documentation-related packages
28+
markdown = "^3.4.0"
29+
30+
[tool.poetry.group.utils.dependencies]
31+
# Small utility packages
32+
click = "^8.0.0"
33+
34+
[build-system]
35+
requires = ["poetry-core>=2.0.0,<3.0.0"]
36+
build-backend = "poetry.core.masonry.api"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Docstring required."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Module docstring."""

.github/workflows/test_actions.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ jobs:
216216
name: Test analyze-project
217217
runs-on: ${{ matrix.os }}
218218
strategy:
219+
fail-fast: false # If there are failures, sometimes it is instructive to see which combinations passed
219220
matrix:
220221
os: [windows-latest, ubuntu-latest, macos-latest]
221222
python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11]
@@ -269,6 +270,46 @@ jobs:
269270
uses: ./analyze-project
270271
with:
271272
project-directory: ${{ github.workspace }}/.github/test_projects/only-ni-python-styleguide
273+
- name: Analyze extras-and-dependency-groups project
274+
uses: ./analyze-project
275+
with:
276+
project-directory: ${{ github.workspace }}/.github/test_projects/extras-and-dependency-groups
277+
install-args: "--extras 'colors serialization' --with dev,docs,utils"
278+
- name: Check for expected dependencies
279+
run: |
280+
echo "Checking for expected packages from extras and dependency groups..."
281+
pip_list=$(poetry run pip list)
282+
echo "Installed packages:"
283+
echo "$pip_list"
284+
285+
# Check for extras packages
286+
if ! echo "$pip_list" | grep -i "colorama"; then
287+
echo "::error title=Test Failure::colorama (from colors extra) not found in pip list"
288+
exit 1
289+
fi
290+
if ! echo "$pip_list" | grep -i "tomli"; then
291+
echo "::error title=Test Failure::tomli (from serialization extra) not found in pip list"
292+
exit 1
293+
fi
294+
295+
# Check for dependency group packages
296+
if ! echo "$pip_list" | grep -i "pytest"; then
297+
echo "::error title=Test Failure::pytest (from dev group) not found in pip list"
298+
exit 1
299+
fi
300+
if ! echo "$pip_list" | grep -i "markdown"; then
301+
echo "::error title=Test Failure::markdown (from docs group) not found in pip list"
302+
exit 1
303+
fi
304+
if ! echo "$pip_list" | grep -i "click"; then
305+
echo "::error title=Test Failure::click (from utils group) not found in pip list"
306+
exit 1
307+
fi
308+
309+
echo "All expected packages found!"
310+
working-directory: ${{ github.workspace }}/.github/test_projects/extras-and-dependency-groups
311+
shell: bash
312+
272313

273314
test_analyze_project_cache_hit:
274315
name: Test analyze-project (cache hit)

analyze-project/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ file associated with the Python project you are analyzing.
3434
project-directory: ${{ github.workspace }}/packages/myproject
3535
```
3636

37-
### `extras`
37+
### `install-args`
3838

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

4245
```yaml
4346
- uses: ni/python-actions/analyze-project@v0
4447
with:
4548
project-directory: ${{ github.workspace }}/packages/myproject
46-
extras: 'docs drivers'
49+
install-args: "--extras 'colors serialization' --with dev,docs,utils"
4750
```

analyze-project/action.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ inputs:
99
project-directory:
1010
description: Path to the directory containing pyproject.toml.
1111
default: ${{ github.workspace }}
12-
extras:
13-
# E.g. "docs drivers"
14-
description: 'List of Poetry extras to install (separated by spaces)'
12+
install-args:
13+
# E.g. "--extras 'drivers addons' --with examples,docs"
14+
description: 'Extra arguments. Install command will be "poetry install <install-args>".'
1515
default: ''
1616
required: false
1717
type: string
@@ -38,18 +38,21 @@ runs:
3838
- name: Check for lock changes
3939
run: poetry check --lock -C "${{ inputs.project-directory }}"
4040
shell: bash
41+
- name: Generate install args hash
42+
id: install_args_hash
43+
run: |
44+
install_args_hash=$(echo "${{ inputs.install-args }}" | sha256sum | cut -d ' ' -f1)
45+
echo "hash=$install_args_hash" >> "$GITHUB_OUTPUT"
46+
shell: bash
4147
- name: Cache virtualenv
4248
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
4349
with:
4450
path: ${{ steps.get_project_info.outputs.venv-path }}
45-
key: ${{ steps.get_project_info.outputs.name }}-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}
51+
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 }}
4652
- name: Install ${{ steps.get_project_info.outputs.name }}
4753
run: |
48-
if [ -n "${{ inputs.extras }}" ]; then
49-
poetry install -v --extras '${{ inputs.extras }}'
50-
else
51-
poetry install -v
52-
fi
54+
install_cmd="poetry install -v ${{ inputs.install-args }}"
55+
eval $install_cmd
5356
working-directory: ${{ inputs.project-directory }}
5457
shell: bash
5558
- name: Lint

0 commit comments

Comments
 (0)