refined-addition-53644
11/30/2021, 9:42 AMversion
of a python package? Like for semantic versioning
./pants version minor <python_package>
curved-television-6568
11/30/2021, 9:43 AMrefined-addition-53644
11/30/2021, 9:43 AMpoetry
functionality here 😄curved-television-6568
11/30/2021, 9:44 AMrefined-addition-53644
11/30/2021, 9:49 AMcurved-television-6568
11/30/2021, 9:52 AMimport os
from os.path import expandvars
from typing import Any
from pants.backend.python.goals.setup_py import SetupKwargs, SetupKwargsRequest
from pants.engine.environment import Environment, EnvironmentRequest
from pants.engine.rules import Get, collect_rules, rule
from pants.engine.target import Target
from pants.engine.unions import UnionRule
SETUP_VARS = [
"APPLICATION",
"AUTHOR",
"AUTHOR_EMAIL",
"PROJECT_URL",
"VERSION_PYTHON",
]
class CustomSetupKwargsRequest(SetupKwargsRequest):
@classmethod
def is_applicable(cls, _: Target) -> bool:
# Apply to all targets
return True
def maybe_expand(key: str, val: Any) -> Any:
if not isinstance(val, str):
return val
maybe_expanded = expandvars(val)
if "$" in maybe_expanded:
raise ValueError(f"All environment variables not expanded in {key}: {maybe_expanded!r}")
return maybe_expanded
@rule
async def customize_setup_kwargs(request: CustomSetupKwargsRequest) -> SetupKwargs:
environ = await Get(Environment, EnvironmentRequest(SETUP_VARS))
os.environ.update(environ)
try:
return SetupKwargs(
{key: maybe_expand(key, val) for key, val in request.explicit_kwargs.items()},
address=request.target.address,
)
except ValueError as e:
raise ValueError(
f"Invalid distribution configuration for {request.target.address}\n\n" f"Error: {e}"
)
def rules():
return [
*collect_rules(),
UnionRule(SetupKwargsRequest, CustomSetupKwargsRequest),
]
python_distribution(
name="...",
provides=python_artifact(
name="...",
version="$VERSION_PYTHON",
),
...
happy-kitchen-89482
11/30/2021, 1:31 PMcurved-television-6568
11/30/2021, 1:47 PMpython_artifact
, so should be fine.happy-kitchen-89482
11/30/2021, 3:59 PMpoetry version
docscurved-television-6568
11/30/2021, 4:02 PMpyproject.toml
, but for us in the pants setting, I imagine it is the version
field on the python_artefact
of the python_distribution
that we want to tweak. Oh, unless you go with a handcrafted setup.py file… right, and then that could be tricky indeed. My bad.happy-kitchen-89482
11/30/2021, 5:49 PMenough-analyst-54434
11/30/2021, 5:49 PMhappy-kitchen-89482
11/30/2021, 5:49 PMcurved-television-6568
11/30/2021, 6:25 PMhappy-kitchen-89482
11/30/2021, 6:40 PMcurved-television-6568
11/30/2021, 7:10 PMhappy-kitchen-89482
11/30/2021, 7:56 PMcurved-television-6568
11/30/2021, 7:56 PMhappy-kitchen-89482
11/30/2021, 7:58 PMcurved-television-6568
12/01/2021, 8:29 AM