|
1 | | -""" Define distribution parameters for nibabel, including package version |
| 1 | +""" Define long_description parameter |
2 | 2 |
|
3 | | -This file contains defines parameters for nibabel that we use to fill settings |
4 | | -in setup.py, the nibabel top-level docstring, and for building the docs. In |
5 | | -setup.py in particular, we exec this file, so it cannot import nibabel. |
| 3 | +This parameter is used to fill settings in setup.py, the nibabel top-level |
| 4 | +docstring, and in building the docs. |
| 5 | +We exec this file in several places, so it cannot import nibabel or use |
| 6 | +relative imports. |
6 | 7 | """ |
7 | 8 |
|
8 | | -import re |
9 | | -from distutils.version import StrictVersion |
10 | | - |
11 | | -from ._version import get_versions |
12 | | -__version__ = get_versions()['version'] |
13 | | -del get_versions |
14 | | - |
15 | | - |
16 | | -def _parse_version(version_str): |
17 | | - """ Parse version string `version_str` in our format |
18 | | - """ |
19 | | - match = re.match(r'([0-9.]*\d)(.*)', version_str) |
20 | | - if match is None: |
21 | | - raise ValueError('Invalid version ' + version_str) |
22 | | - return match.groups() |
23 | | - |
24 | | - |
25 | | -def _cmp(a, b): |
26 | | - """ Implementation of ``cmp`` for Python 3 |
27 | | - """ |
28 | | - return (a > b) - (a < b) |
29 | | - |
30 | | - |
31 | | -def cmp_pkg_version(version_str, pkg_version_str=__version__): |
32 | | - """ Compare `version_str` to current package version |
33 | | -
|
34 | | - To be valid, a version must have a numerical major version followed by a |
35 | | - dot, followed by a numerical minor version. It may optionally be followed |
36 | | - by a dot and a numerical micro version, and / or by an "extra" string. |
37 | | - *Any* extra string labels the version as pre-release, so `1.2.0somestring` |
38 | | - compares as prior to (pre-release for) `1.2.0`, where `somestring` can be |
39 | | - any string. |
40 | | -
|
41 | | - Parameters |
42 | | - ---------- |
43 | | - version_str : str |
44 | | - Version string to compare to current package version |
45 | | - pkg_version_str : str, optional |
46 | | - Version of our package. Optional, set fom ``__version__`` by default. |
47 | | -
|
48 | | - Returns |
49 | | - ------- |
50 | | - version_cmp : int |
51 | | - 1 if `version_str` is a later version than `pkg_version_str`, 0 if |
52 | | - same, -1 if earlier. |
53 | | -
|
54 | | - Examples |
55 | | - -------- |
56 | | - >>> cmp_pkg_version('1.2.1', '1.2.0') |
57 | | - 1 |
58 | | - >>> cmp_pkg_version('1.2.0dev', '1.2.0') |
59 | | - -1 |
60 | | - """ |
61 | | - version, extra = _parse_version(version_str) |
62 | | - pkg_version, pkg_extra = _parse_version(pkg_version_str) |
63 | | - if version != pkg_version: |
64 | | - return _cmp(StrictVersion(version), StrictVersion(pkg_version)) |
65 | | - return (0 if extra == pkg_extra |
66 | | - else 1 if extra == '' |
67 | | - else -1 if pkg_extra == '' |
68 | | - else _cmp(extra, pkg_extra)) |
69 | | - |
70 | | - |
71 | 9 | # Note: this long_description is the canonical place to edit this text. |
72 | 10 | # It also appears in README.rst, but it should get there by running |
73 | 11 | # ``tools/refresh_readme.py`` which pulls in this version. |
@@ -157,5 +95,3 @@ def cmp_pkg_version(version_str, pkg_version_str=__version__): |
157 | 95 | .. _zenodo: https://zenodo.org |
158 | 96 | .. _Digital Object Identifier: https://en.wikipedia.org/wiki/Digital_object_identifier |
159 | 97 | """ |
160 | | - |
161 | | -VERSION = __version__ |
0 commit comments