powerful-eye-58407
10/09/2024, 3:18 PMgit status
to set version to "dev" when there are any changes... And that's the tricky bit - for git status
to work, I need whole repository content (also including .git dir). Can I achieve that using pants?
What I have so far is...powerful-eye-58407
10/09/2024, 3:20 PMsystem_binary(
name="git-binary",
binary_name="git",
fingerprint_args=["--version"],
)
adhoc_tool(
name="git-status",
runnable=":git-binary",
execution_dependencies=[
":git-repo-data" << .git files
# how do I include other repository content?
],
args=["status", "--porcelain"],
stdout="changelog.txt",
)
experimental_wrap_as_resources(
name="git-status-result",
inputs=[
":git-status",
],
)
files(
sources=[".git/**"],
name="git-repo-data",
)
and a wheel that depends on git-status-result
target.powerful-eye-58407
10/09/2024, 3:21 PMfiles
target that includes **
because it will mean that .py files that I have in the repo are included in both files
and python_sources
targets...powerful-eye-58407
10/09/2024, 3:24 PMdigest = await Get(Digest, PathGlobs(["**"]))
passed to Process
running git
and that works fine (I've followed https://www.pantsbuild.org/2.21/docs/writing-plugins/common-plugin-tasks/custom-python-artifact-kwargs to pass version to setup_kwargs_plugin
rule that way), but I have no idea how to write the version to a file from the setup_kwargs_plugin
rule level - I understand this can only be done from goal rule, but I don't want to create custom goal to package a wheel, it must be simpler than that 🙂powerful-eye-58407
10/09/2024, 3:25 PMpowerful-eye-58407
10/09/2024, 3:27 PM@rule
async def setup_kwargs_plugin(
request: PythonLibrarySetupKwargsRequest,
local_git_changes_result: LocalGitChangesResult,
latest_commit_hash_result: LatestCommitHashResult,
) -> SetupKwargs:
setup_kwargs = request.explicit_kwargs.copy()
if local_git_changes_result.has_local_changes:
setup_kwargs["version"] = "dev"
return SetupKwargs(setup_kwargs, address=request.target.address)
latest_commit_hash = latest_commit_hash_result.value
setup_kwargs["version"] = latest_commit_hash
return SetupKwargs(setup_kwargs, address=request.target.address)
# Q:
# how do I write setup_kwargs["version"] to version.py file in the sandbox?
powerful-eye-58407
10/11/2024, 10:11 AM