Share Python libraries

The recommended workflow for sharing code across multiple Transforms Python repositories is publishing a Python library package—specifically, a Conda ↗ library. Publishing Python libraries is supported in Transforms Python 1.23.1+.

Publishing a Python Library

Here are the required steps for publishing a Python library:

  1. Create a new repository that will contain the Python code for your shared library.

  2. Name your repository. Your library will be named after the repository name when initialized. Other code repositories will use this name to discover and use your library. You can rename it later by accessing the gradle.properties file and editing the condaPackageName parameter (this file is hidden, so you may need to select "Show hidden files" in the file editor first).

Library naming

Note that the condaPackageName can only contain ASCII lowercase letters, numbers, or hyphens. Any sequence of non-alphanumeric/non-hyphen characters will be replaced by a single hyphen (for example my_library repo will be published as my-library-repo, and Foobar _baz$$$ will be published as foobar-baz-).

  1. Click the Create button in the Python Library template section.

  2. Create a package: Any folder in your library containing an __init__.py file will be published as a package. Your repository will be initialized with such a folder - rename it and add additional packages if needed.

  3. Create modules: Within your package folder, you can add Python files that contain your code. These modules will later be imported by other repositories.

Diagram of mapping between Artifact repository and Transforms repository

  1. Tag your repository: When you are ready to make a release, navigate to the "Branches" tab, select "Tags" and create a new tag. By default, your Python library will only get published for commits that are tagged. To change this default behavior, you must modify the build.gradle file.

python-package-tagging

Warning

Note that tag names must conform to SLS versioning, as specified in the SLS Versions documentation ↗.

  1. Your library version will be published once the checks finish successfully. You can view the status of checks in the Tags list and in the Checks tab of your repository.

By default, changes to your library will only be published when you create a tag. You can create a tag for the current state of one of your branches, or for a specific commit. Once checks pass your library will be published and users will be able to upgrade to the newest version.

Consuming repositories do not automatically upgrade to use the newest version when a new version is published. To manually upgrade your repository to use the newest version, see the documentation on discovering and using Python libraries and on Conda lock files for re-resolving the Conda environment.

  1. Ensure that you give permissions to your library consumers. By default, users should have "Viewer" role on your shared repository. Add a reference to the library repository under the transform repository settings Artifacts tab.

Screenshot of the repository settings Artifacts tab

Your library at this point should be available for other apps and repositories to consume. Read more about discovering and using Python packages.