@@ -18,7 +18,6 @@ To use setuptools_scm just modify your project's setup.py file like this:
18181. Add :code: `'setuptools_scm' ` to the :code: `setup_requires ` parameter
19192. Add the :code: `use_scm_version ` parameter and set it to ``True ``
2020
21-
2221 E.g.:
2322
2423 .. code :: python
@@ -31,18 +30,47 @@ To use setuptools_scm just modify your project's setup.py file like this:
3130 ... ,
3231 )
3332
33+ Arguments to ``get_version() `` (see below) may be passed as a
34+ dictionary to ``use_scm_version ``. For example:
35+
36+ .. code :: python
37+
38+ from setuptools import setup
39+ setup(
40+ ... ,
41+ use_scm_version = {" root" : " .." , " relative_to" : __file__ },
42+ setup_requires = [' setuptools_scm' ],
43+ ... ,
44+ )
45+
46+
47+ 3. Access the version number in your package via :code: `pkg_resources `
48+
49+ E.g. (`PEP-0396 <https://www.python.org/dev/peps/pep-0396 >`_):
50+
51+ .. code :: python
52+
53+ from pkg_resources import get_distribution, DistributionNotFound
54+ try :
55+ __version__ = get_distribution(__name__ ).version
56+ except DistributionNotFound:
57+ # package is not installed
58+ pass
59+
3460
3561 Programmatic usage
3662------------------
3763
38- In order to use setuptools_scm from code
39- that one directory deeper than the project's root, you can use:
64+ In order to use `` setuptools_scm `` from code that one directory deeper
65+ than the project's root, you can use:
4066
4167.. code :: python
4268
4369 from setuptools_scm import get_version
4470 version = get_version(root = ' ..' , relative_to = __file__ )
4571
72+ See `setup.py Usage `_ above for how to use this within setup.py.
73+
4674
4775Usage from sphinx
4876-----------------
@@ -53,8 +81,8 @@ instead use ``pkg_resources`` after editable/real installation:
5381.. code :: python
5482
5583 from pkg_resources import get_distribution
56- release = pkg_resources (' myproject' ).version
57- # for the example take major/minor
84+ release = get_distribution (' myproject' ).version
85+ # for example take major/minor
5886 version = ' .' .join(release.split(' .' )[:2 ])
5987
6088 The underlying reason is, that services like readthedocs sometimes change
0 commit comments