Q: what is the cleanest way to "lift" the VERSION ...
# general
f
Q: what is the cleanest way to "lift" the VERSION out of a txt file (VERSION) , which is in the same directory as the BUILD file, and feed it down, into a target as one or more of the parameters ? I have solved this • for publishing wheels - by a custom plugin, that creates the
python_artifact( )
to the wheel target... but this was clunky • for docker images, by setting the "environment" variable on the outside when package / publishing the image, but lifting the value in through the ENV_VAR (as a tag) - but again - this seems clunky .. Is there a target that can read a file, and provide the contents of that file as a {replacement} variable, or as the setting to command (say arg to a
run_shell_command
or
shell_command
or
adhoc_...
?
i currently have
Copy code
# BUILD
version_and_changelog()

# other targets ...
which provides a special target,
pants run path/to/target:bump_version
,
pants run path/to/target:gen_changelog
but I am after a more universal way of reading the "`VERSION` " file than piece-meal for each target
c
I'm not aware of any "non-clunky" way for this yet.. I would probably do something like this to get it across as widely as possible:
Copy code
# .pants.bootstrap
MY_VERSION=$(cat src/path/to/VERSION)
export MY_VERSION
Copy code
# macros.py
MY_VERSION = env("MY_VERSION")
Copy code
# pants.toml
[GLOBAL]
build_file_prelude_globs = ["macros.py"]
Copy code
# some/BUILD

some_target(version=MY_VERSION, ...)
or, as default:
Copy code
__defaults__({docker_image: dict(image_tags=[MY_VERSION])})
f
Sorry @curved-television-6568 - my bad, As this is a monorepo, with many products the extra detail is that there are "many" VERSION files (right next to the BUILD file that publishes a main artifact)
Copy code
./apps/arc/VERSION
./apps/devolver/VERSION
./apps/log_manager/VERSION
./lib/finder_2000/VERSION
./lib/knohh/VERSION
./tools/containers/cicd-general/VERSION
./tools/python/acme_cicd/VERSION
./tools/python/acme_cicd/VERSION
There are two modes of operation ; •
pants run ... :bump_version
and •
pants package publish //
I am trying to avoid
find . -name VERSION -exec dirname {} \; | xargs -Ixx sh -c 'VERSION=$(cat xx/VERSION) pants package publish //xx::'
or other crazy incantations šŸ™‚ also.. if I can be getting "pants" to lift the version and use it inside it's packaging mechanism, then I will be able to take advantage of more native pants filtering mechanisms like
changed-since
and
changed-dependents
Copy code
pants_command = f"""pants --level=error
                   --filter-target-type=archive,docker_image,pex_binary,python_distribution
                   --changed-since={last_commit.id}
                   --changed-dependents=transitive
                   --filter-address-regex={filter_regex} list"""
f
What stops there being a general plugin that reads a file and provides the content ? Generally usable across all targets wherever a string is needed, and could be used in a property="{variable_replacement}-xyz" style ? Is there technical or architectural barriers or challenges the prohibit this ? I wrote a python_artifact(...) extension type plugin that reads the VERSION and the README to the long description, ( was dynamic VERSION AND CHANGELOG when I wrote it, and it was complex - but works) My goal is a pipeline universal way to feed the version into everywhere I need it (adhoc for rust builds, docker, python etc)
But thay extension was only extending the python artefact target, now we need an all places variant :-)
c
I think this is just a feature that has not been high enough on anyones prio list yet..
šŸ‘ 1
f
@curved-television-6568 I will put that together in the next few days and see where I land šŸ˜„ this will be my plugin attempt #2 - so I will likely need some assistance (ep)
šŸ‘ 1
p
I would be excited to copy whatever comes out of this, I have a need to improve the versioning situation I have which just involves a lot of hardcoded pants hashes
šŸ‘ 1