I am trying to identify how to provide the value o...
# general
c
I am trying to identify how to provide the value of the "version" field on one or more of the wheel files were are generating. This value would eventually be provided from our build system (currently gitlab). Is there a way to pass this into a given invocation of pants. In other words:
Copy code
python_distribution(
    name="tools_dist",
    dependencies=[
        "tools:tool_files",
        "tools:tools_pyproject",
        "tools/src:tools_lib",
        "shared:shared_dist",
    ],
    provides=python_artifact(
        name="awesome_tools",
        version = "$WANT_THIS_TO_BE_SOME_MAGIC_VARIABLE_SET_AT_PANTS_RUN_TIME",
        authors = "Ryan",
        authorEmail = "<mailto:rmahoney@aledade.com|rmahoney@aledade.com>",
        readme = "README.md"
    ),
    sdist=False, # Do NOT generate an sdist (as a result only a wheel is generated)
)
โœ… 1
I did just experiment around with the
vcs_version
target (https://www.pantsbuild.org/docs/generating-version-tags), which might work for what I need given enough force, but I'm not sure how to pull the generated value in that file out to be referenced within the
version
field above
Looks like from some other threads above (https://pantsbuild.slack.com/archives/C046T6T9U/p1657564978053719) that this may be what to look into?: https://www.pantsbuild.org/docs/plugins-setup-py
c
Is there a way to pass this into a given invocation of pants.
You may leverage environment variable for this:
Copy code
...
    python_artifact(
        name="awesome_tools",
        version = env("SOME_VERSION", "0.0.0"), # the 0.0.0 part is an optional default in case the env var is undefined.
        ...
then:
Copy code
# SOME_VERSION=1.2.3 pants package ...
itโ€™s in pants 2.16 which will be out in a stable release any day now
c
Oh thank you! that is WAY easier.
that is EXACTLY what I was looking for.
c
sweet
c
I'll role my version up to rc4 and go my merry way!
๐Ÿ‘ 1
f
+1 to that, the env() tool will be amazing, canโ€™t wait to use it!
โค๏ธ 1
q
hi @cool-account-59189 I have been following your attempts of using vcs_version and the env in the python_artifact. Did you managed to inject it ? I am not able to figure it out by myself, so any help would be welcome ๐Ÿ™
c
hiya, yup hold on I'll paste in what we ended up doing:
๐Ÿป 1
This is using the 2.16:
Copy code
files(name="tools_additional_files_needed_for_wheel", sources=["README.md"])

python_distribution(
    name="tools_dist",
    dependencies=[
        "tools:tools_additional_files_needed_for_wheel",
        "tools/src:tools_lib",
        "shared:shared_dist",
    ],
    provides=python_artifact(
        name="awesome_tools",
        version=env("AWESOME_PROJECT_SPECIFIC_WHEEL_BUILD_VERSION", "0.1.0"),
        author="Awesome",
        author_email="<mailto:support@awesome.com|support@awesome.com>",
        long_description_content_type="text/markdown",
    ),
    long_description_path="README.md",
    sdist=False,  # Do NOT generate an sdist (as a result only a wheel is generated)
)
not a pants expert by any means...so some of the other nonsense may be sub-optimal/dumb...the but env thing works great!
we just run then as:
AWESOME_PROJECT_SPECIFIC_WHEEL_BUILD_VERSION=0.133.0 pants package ::
(more or less)
q
I see, this is similar of what I came up after reading your threads. As I have many artifacts and projects, I expose the versions in file in the rood of the monorepo: VERSIONS.env
Copy code
export AWESOME_PROJECT_SPECIFIC_WHEEL_BUILD_VERSION=0.0.1
export AWESOME_PROJECT_2_SPECIFIC_WHEEL_BUILD_VERSION=0.0.1
and then in each BUILD file:
Copy code
provides=python_artifact(
        name="awesome_tools",
        version=env("AWESOME_PROJECT_SPECIFIC_WHEEL_BUILD_VERSION", "0.1.0"),
        author="Awesome",
        author_email="<mailto:support@awesome.com|support@awesome.com>",
        long_description_content_type="text/markdown",
    ),
Copy code
provides=python_artifact(
        name="awesome_tools",
        version=env("AWESOME_PROJECT_SPECIFIC_2_WHEEL_BUILD_VERSION", "0.1.0"),
        author="Awesome",
        author_email="<mailto:support@awesome.com|support@awesome.com>",
        long_description_content_type="text/markdown",
    ),
So i generate the packages as
source VERSIONS.env && pants package ::
This helps me to maintain all the versions explicit in one entrypoint, but it forces our team to manually bump versions by hand before merging and deploying, which is prone to errors. That's why I was interested in still injecting the
vcs_version
, but I think it is still not possible, and also I wonder if it would just update all versions at once with the last commit / tag (unless I do the --changed-since=origin/main, or something)...not sure what is going to be the optimal solution to us. If I manage to automatize it or create a plugin worth to share I will keep you updated ! many thanks @cool-account-59189 !
c
So in our build environment (gitlab) the value of that environment variable is set to something like:
Copy code
AWESOME_PROJECT_SPECIFIC_2_WHEEL_BUILD_VERSION=1.1.${CI_PIPELINE_IID}
so no babysitting required (unless/until we bump the major.minor versions)
๐Ÿš€ 1
q
OH WOW !!!! that is actually an approach I totally missed as I was just with tunnel vision around the vcs_version !! You just made my day !!
๐Ÿ‘ 1
thanks !!