I\'m trying to reorganize my python package versioning so I only have to update the version in one place, preferably a python module or a text file. For all the places I nee
As of conda-build-3.16.1
(Nov-2018) here is what works to programmatically setup version
inside the conda recipe.
The examples are a part of meta.yaml
that you pass to conda-build
, as explained here.
setup.py
's version:This recipe is perfect if you build a python package, since setup.py
needs it anyway, so you must have figured that one out already.
{% set data = load_setup_py_data() %}
package:
name: mypackage
version: {{ data.get('version') }}
note that sometimes you have to tell the conda recipe explicitly where to find it, if it's not in the same dir as setup.py
:
{% set data = load_setup_py_data(setup_file='../setup.py', from_recipe_dir=True) %}
and now proceed with:
$ conda-build conda-recipe
This recipe is good if your project is tagged in git, and you use a tag format that conda accepts as a valid version number (e.g. 2.5.1
or v2.5.1
).
package:
name: hub
version: {{ GIT_DESCRIBE_TAG }}
and now proceed with:
$ conda-build conda-recipe
This one is useful for non-python conda packages, where the version comes from a variety of different places, and you can perfect its value - e.g. convert v2.5.1
into 2.5.1
.
package:
name: mypkg
version: {{ environ.get('MYPKG_VERSION', '') }}
Then create an executable script that fetches the version, let's call it script-to-get-mypkg-version
and now proceed with loading the env var that will set the version:
$ MYPKG_VERSION=`script-to-get-mypkg-version` conda-build conda-recipe
Depending on the conda-build version, you may have to use os.environ.get
instead of environ.get
. The docs use the latter.
Note that if this used to work in the past, as described in one of the answers from 2016, it doesn't work now.
package:
name: mypkg
build:
script_env:
- VERSION
$ VERSION=`script-to-get-mypkg-version` conda-build conda-recipe
conda-build
ignores env var VERSION
in this case.
source.