full-oyster-41619
08/17/2020, 3:02 PMhundreds-father-404
08/17/2020, 3:25 PMfull-oyster-41619
08/17/2020, 3:59 PMhundreds-father-404
08/17/2020, 4:14 PMhundreds-father-404
08/17/2020, 4:14 PMfull-oyster-41619
08/17/2020, 5:05 PMhundreds-father-404
08/17/2020, 5:05 PMfull-oyster-41619
08/17/2020, 6:15 PMhundreds-father-404
08/17/2020, 7:18 PMmacros.py
file, and it sounds like you want something more automated.
To clarify, do you want the version to automatically bump every time that you run setup-py
? Note that setup-py
only builds the distribution, it won’t actually publish it like those JVM docs on the publish
goal do.full-oyster-41619
08/18/2020, 6:26 AMuse_scm_version: True
) , but this is not a good fit for mono repo (I will have a one version fit's all scenario, which has multiple disadvantages, like building unneeded libraries and loosing semanting versioning per project)hundreds-father-404
08/18/2020, 7:06 AMcustom-setup-py
that behaves really similarly to the built in setup-py
, but will update the version
. Maybe you add some options to decide what to do, eg to override the version to a certain value.full-oyster-41619
08/18/2020, 10:41 AM./pants setup-py <lib> -- sdist
, but add a way to define a function that calculates the version. this function can something like f(lib_name) -> lib_version
. This will give the users the flexibility to bring their own version algorithm. The macros example that you showed presents a similar scenario, but from what I've read pants cannot use imports inside the macro and because of this you are very limited in the versioning algorithm functionality. maybe there is another way of doing this, like using a plugin (didn't deep dive into that yet).
2. Add --transitive
to setup-py
goal (./pants setup-py --transitive <lib> -- sdist
. This will use the same versioning mechanism described above, but will build also the transitive libraries of the specified library. Libraries could have different versioning functions implemented. This will be useful when you have to make a change in a child library and want to build all parent libraries. Pushing will become very easy, because you could use twine to upload all the dist dir content.
For example, one implementation of the function that generates the version for a library, can be the one that was described in the java publish scenario
uses Semantic Versioning ("semver") for versioning. Versions are dotted number triples (e.g., 2.5.6); when Pants bumps a version, it specifically bumps the patch number part. Thus, if the current version is 2.5.6, Pants bumps to 2.5.7. To publish a minor or major version instead of a patch, you override the version number on the command line.
The pushdb: To "remember" version numbers, Pants uses the pushdb. The pushdb is a text file under source control. It lists artifacts with their current version numbers and SHAs. When you publish artifacts, pants edits this file and pushes it to the origin.
another implementation might be a function that returns the version used in scm (similar to use_scm_version: True
functionality in setup-py)full-oyster-41619
08/20/2020, 11:27 AM%(buildroot)
used in pants.toml
python_library(
name = "my-lib",
sources = ['**/*.py'],
provides=scm_setup_py(
name="my_lib",
description="my-lib",
path="%(libpath)" # similat to %(buildroot) in pants.toml
)
)
and the path would be taken when you run ./pants setup-py <lib-path>/<lib-name>
I could achieve this manually using
python_library(
name = "my-lib",
sources = ['**/*.py'],
provides=scm_setup_py(
name="my_lib",
description="my-lib",
path="src/python/my_lib"
)
)
but I want somehow to retrieve the path dinamically from pants code.
My end goal is to create a versioning function like this
def scm_setup_py(name: str, path: str , **kwargs) -> PythonArtifact:
version = get_version_using_git_tag(path)
return PythonArtifact(name=name, version=version, **kwargs)