diff --git a/docs/notes/2.22.x.md b/docs/notes/2.22.x.md index badabeee894..7f6b5c8d3f3 100644 --- a/docs/notes/2.22.x.md +++ b/docs/notes/2.22.x.md @@ -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. diff --git a/src/python/pants/backend/python/util_rules/vcs_versioning.py b/src/python/pants/backend/python/util_rules/vcs_versioning.py index cd5d5505f1f..5c8396a666c 100644 --- a/src/python/pants/backend/python/util_rules/vcs_versioning.py +++ b/src/python/pants/backend/python/util_rules/vcs_versioning.py @@ -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( @@ -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]