Skip to content

Commit

Permalink
Run all vcs versioning processes locally (cherrypick of #21353) (#21357)
Browse files Browse the repository at this point in the history
When using environments we must ensure we run VCS-related processes
in the local environment and not the inherited one, as a docker
environment will not have access to Git state.

In #21188 we made setuptools_scm itself run locally, but this was not
sufficient: this change makes sure we also run the pex building and
git binary discovery in the local environment.

Fixes #21178
  • Loading branch information
benjyw authored Aug 26, 2024
1 parent f6f9b2c commit 31e3041
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/notes/2.22.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ The `runtime` field of [`aws_python_lambda_layer`](https://www.pantsbuild.org/2.

Fix running python source files that have dashes in them (bug introduced in 2.20). For example: `pants run path/to/some-executable.py`

When using the `vcs_version` target, force `setuptools_scm` git operations to run in the local environment, so that the local git state is available to them.

#### Semgrep

The default version of `semgrep` used by the `pants.backends.experimental.tool.semgrep` backend is now version 1.72.0, upgraded from 1.46.0. This version requires Python 3.8 or greater.
Expand Down
13 changes: 11 additions & 2 deletions src/python/pants/backend/python/util_rules/vcs_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ async def generate_python_from_setuptools_scm(
# A MaybeGitWorktree is uncacheable, so this enclosing rule will run every time its result
# is needed, and the process invocation below caches at session scope, meaning this rule
# will always return a result based on the current underlying git state.
maybe_git_worktree = await Get(MaybeGitWorktree, GitWorktreeRequest())
maybe_git_worktree = await Get(
MaybeGitWorktree,
{GitWorktreeRequest(): GitWorktreeRequest, local_environment_name.val: EnvironmentName},
)
if not maybe_git_worktree.git_worktree:
raise VCSVersioningError(
softwrap(
Expand Down Expand Up @@ -100,7 +103,13 @@ async def generate_python_from_setuptools_scm(
),
)

setuptools_scm_pex_get = Get(VenvPex, PexRequest, setuptools_scm.to_pex_request())
setuptools_scm_pex_get = Get(
VenvPex,
{
setuptools_scm.to_pex_request(): PexRequest,
local_environment_name.val: EnvironmentName,
},
)
setuptools_scm_pex, input_digest = await MultiGet(setuptools_scm_pex_get, input_digest_get)

argv = ["--root", str(maybe_git_worktree.git_worktree.worktree), "--config", config_path]
Expand Down

0 comments on commit 31e3041

Please sign in to comment.