Skip to content

Commit d08837a

Browse files
authored
setup-poetry: Hide Poetry installation from tools that search the workspace for Python files (#34)
* tests: Test analyze-project in root of repo * tests: Don't create ./minimal * tests: cp -av needs bash * tests: Add quotes * tests: Move quotes * setup-poetry: Store the Poetry cache in the "pipeline directory" not the workspace directory * tests: Split out repo_root test project * tests: Fix workflow syntax * setup-poetry: Normalize path * setup-poetry: Only normalize the part of the path that exists
1 parent 36f9be5 commit d08837a

File tree

7 files changed

+680
-11
lines changed

7 files changed

+680
-11
lines changed

.github/test_projects/repo_root/README.md

Whitespace-only changes.

.github/test_projects/repo_root/poetry.lock

Lines changed: 597 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[project]
2+
name = "test-project"
3+
version = "0.1.0"
4+
description = ""
5+
authors = [
6+
{name = "Joel Dixon",email = "[email protected]"}
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.9,<4.0"
10+
dynamic = ["dependencies"]
11+
12+
[tool.poetry]
13+
packages = [{include = "test_project", from = "src"}]
14+
15+
[tool.poetry.group.lint.dependencies]
16+
ni-python-styleguide = ">=0.4.1"
17+
mypy = ">=1.0"
18+
pyright = { version = ">=1.1.400", extras = ["nodejs"] }
19+
20+
[tool.ni-python-styleguide]
21+
extend_exclude = "update-project-version"
22+
23+
[tool.mypy]
24+
mypy_path = "."
25+
files = "."
26+
namespace_packages = true
27+
strict = true
28+
explicit_package_bases = true
29+
exclude = "update-project-version"
30+
31+
[tool.pyright]
32+
include = ["src/", "tests/"]
33+
exclude = ["update-project-version"]
34+
35+
[build-system]
36+
requires = ["poetry-core>=2.0.0,<3.0.0"]
37+
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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,33 @@ jobs:
228228
python-version: ${{ matrix.python-version }}
229229
- name: Set up Poetry
230230
uses: ./setup-poetry
231-
- name: Analyze Python Project
231+
- name: Analyze Python project
232232
uses: ./analyze-project
233233
with:
234234
project-directory: ${{ github.workspace }}/.github/test_projects/minimal
235235

236+
test_analyze_project_repo_root:
237+
name: Test analyze-project (repo root)
238+
runs-on: ${{ matrix.os }}
239+
strategy:
240+
matrix:
241+
os: [windows-latest, ubuntu-latest, macos-latest]
242+
python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11]
243+
steps:
244+
- name: Check out repo
245+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
246+
- name: Set up Python
247+
uses: ./setup-python
248+
with:
249+
python-version: ${{ matrix.python-version }}
250+
- name: Set up Poetry
251+
uses: ./setup-poetry
252+
- name: Copy Python project to root
253+
run: cp -av "${{ github.workspace }}/.github/test_projects/repo_root"/* "${{ github.workspace }}"
254+
shell: bash
255+
- name: Analyze Python project
256+
uses: ./analyze-project
257+
236258
# This job is intended to combine the test results so we don't have to list
237259
# each matrix combination in the required status check settings. There are a
238260
# lot of corner cases that make this harder than it should be; see See
@@ -248,6 +270,7 @@ jobs:
248270
test_check_project_version,
249271
test_update_project_version,
250272
test_analyze_project,
273+
test_analyze_project_repo_root,
251274
]
252275
if: ${{ !cancelled() }}
253276
steps:

setup-poetry/action.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,30 @@ runs:
2727
- name: Set paths (Linux/Mac)
2828
if: runner.os != 'Windows'
2929
run: |
30-
echo "POETRY_BIN_DIR=$GITHUB_WORKSPACE/.cache/poetry/bin" >> "$GITHUB_ENV"
31-
echo "POETRY_CONFIG_DIR=$GITHUB_WORKSPACE/.cache/poetry/config" >> "$GITHUB_ENV"
32-
echo "POETRY_HOME=$GITHUB_WORKSPACE/.cache/poetry/home" >> "$GITHUB_ENV"
33-
echo "POETRY_HOME_BIN=$GITHUB_WORKSPACE/.cache/poetry/home/bin" >> "$GITHUB_ENV"
34-
echo "$GITHUB_WORKSPACE/.cache/poetry/bin" >> "$GITHUB_PATH"
30+
# Use the "pipeline directory" so that tools that search the workspace
31+
# directory for Python files will not find the Poetry cache. Use
32+
# realpath to normalize the "../".
33+
PIPELINE_DIR="$(realpath $GITHUB_WORKSPACE/..)"
34+
POETRY_ROOT="$PIPELINE_DIR/.cache/poetry"
35+
echo "POETRY_BIN_DIR=$POETRY_ROOT/bin" >> "$GITHUB_ENV"
36+
echo "POETRY_CONFIG_DIR=$POETRY_ROOT/config" >> "$GITHUB_ENV"
37+
echo "POETRY_HOME=$POETRY_ROOT/home" >> "$GITHUB_ENV"
38+
echo "POETRY_HOME_BIN=$POETRY_ROOT/home/bin" >> "$GITHUB_ENV"
39+
echo "$POETRY_ROOT/bin" >> "$GITHUB_PATH"
3540
shell: bash
3641
- name: Set paths (Windows)
3742
if: runner.os == 'Windows'
3843
run: |
39-
Add-Content $env:GITHUB_ENV "POETRY_BIN_DIR=$env:GITHUB_WORKSPACE\.cache\poetry\bin"
40-
Add-Content $env:GITHUB_ENV "POETRY_CONFIG_DIR=$env:GITHUB_WORKSPACE\.cache\poetry\config"
41-
Add-Content $env:GITHUB_ENV "POETRY_HOME=$env:GITHUB_WORKSPACE\.cache\poetry\home"
42-
Add-Content $env:GITHUB_ENV "POETRY_HOME_BIN=$env:GITHUB_WORKSPACE\.cache\poetry\home\Scripts"
43-
Add-Content $env:GITHUB_PATH "$env:GITHUB_WORKSPACE\.cache\poetry\bin"
44+
# Use the "pipeline directory" so that tools that search the workspace
45+
# directory for Python files will not find the Poetry cache. Use
46+
# Resolve-Path to normalize the "../".
47+
$PIPELINE_DIR = (Resolve-Path -Path "$env:GITHUB_WORKSPACE\..").Path
48+
$POETRY_ROOT = "$PIPELINE_DIR\.cache\poetry"
49+
Add-Content $env:GITHUB_ENV "POETRY_BIN_DIR=$POETRY_ROOT\bin"
50+
Add-Content $env:GITHUB_ENV "POETRY_CONFIG_DIR=$POETRY_ROOT\config"
51+
Add-Content $env:GITHUB_ENV "POETRY_HOME=$POETRY_ROOT\home"
52+
Add-Content $env:GITHUB_ENV "POETRY_HOME_BIN=$POETRY_ROOT\home\Scripts"
53+
Add-Content $env:GITHUB_PATH "$POETRY_ROOT\bin"
4454
shell: pwsh
4555
- name: Copy paths from $GITHUB_ENV to $GITHUB_OUTPUT
4656
id: copy-paths

0 commit comments

Comments
 (0)