Skip to content

Commit

Permalink
Always run setuptools_scm in the local environment (#21188)
Browse files Browse the repository at this point in the history
It requires access to local git state, which is not going
to be available in other environments.
  • Loading branch information
benjyw authored Jul 24, 2024
1 parent a46b4a8 commit 26db7ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/notes/2.23.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ The docs for the `check` goal have been updated to state that third-party type s

Deprecate the `--export-py-hermetic-scripts` option in favor of the new `--export-py-non-hermetic-scripts-in-resolve` option which allows configuring the hermetic scripts logic on a per-resolve basis.

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.

#### Terraform

The default version of terraform has been updated from 1.7.1 to 1.9.0.
Expand Down
29 changes: 18 additions & 11 deletions src/python/pants/backend/python/util_rules/vcs_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
)
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.util_rules.stripped_source_files import StrippedFileName, StrippedFileNameRequest
from pants.engine.environment import ChosenLocalEnvironmentName, EnvironmentName
from pants.engine.fs import CreateDigest, FileContent
from pants.engine.internals.native_engine import Digest, Snapshot
from pants.engine.internals.selectors import Get, MultiGet
from pants.engine.process import ProcessCacheScope, ProcessResult
from pants.engine.rules import collect_rules, rule
from pants.engine.intrinsics import process_request_to_process_result
from pants.engine.process import ProcessCacheScope
from pants.engine.rules import collect_rules, implicitly, rule
from pants.engine.target import AllTargets, GeneratedSources, GenerateSourcesRequest, Targets
from pants.engine.unions import UnionRule
from pants.util.logging import LogLevel
Expand All @@ -57,6 +59,7 @@ class GeneratePythonFromSetuptoolsSCMRequest(GenerateSourcesRequest):
async def generate_python_from_setuptools_scm(
request: GeneratePythonFromSetuptoolsSCMRequest,
setuptools_scm: SetuptoolsSCM,
local_environment_name: ChosenLocalEnvironmentName,
) -> GeneratedSources:
# 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
Expand Down Expand Up @@ -102,15 +105,19 @@ async def generate_python_from_setuptools_scm(

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

result = await Get(
ProcessResult,
VenvPexProcess(
setuptools_scm_pex,
argv=argv,
input_digest=input_digest,
description=f"Run setuptools_scm for {request.protocol_target.address.spec}",
level=LogLevel.INFO,
cache_scope=ProcessCacheScope.PER_SESSION,
result = await process_request_to_process_result(
**implicitly(
{
VenvPexProcess(
setuptools_scm_pex,
argv=argv,
input_digest=input_digest,
description=f"Run setuptools_scm for {request.protocol_target.address.spec}",
level=LogLevel.INFO,
cache_scope=ProcessCacheScope.PER_SESSION,
): VenvPexProcess,
local_environment_name.val: EnvironmentName,
}
),
)
version = result.stdout.decode().strip()
Expand Down

0 comments on commit 26db7ea

Please sign in to comment.