Skip to content

Commit 3a5b2a9

Browse files
committed
Support MYPY_VERSION for overriding version
1 parent 0d38613 commit 3a5b2a9

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

mypy/version.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55
# - Release versions have the form "0.NNN".
66
# - Dev versions have the form "0.NNN+dev" (PLUS sign to conform to PEP 440).
77
# - For 1.0 we'll switch back to 1.2.3 form.
8-
__version__ = '0.950+dev'
9-
base_version = __version__
8+
base_version = '0.950+dev'
9+
# Overridden by setup.py
10+
__version__ = base_version
1011

11-
mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
12-
if __version__.endswith('+dev') and git.is_git_repo(mypy_dir) and git.have_git():
13-
__version__ += '.' + git.git_revision(mypy_dir).decode('utf-8')
14-
if git.is_dirty(mypy_dir):
15-
__version__ += '.dirty'
16-
del mypy_dir
12+
13+
def setup_compute_version() -> str:
14+
# We allow an environment variable to override version, but we should probably
15+
# enforce that it is consistent with the existing version minus additional information.
16+
if "MYPY_VERSION" in os.environ:
17+
assert os.environ["MYPY_VERSION"].startswith(base_version)
18+
return os.environ["MYPY_VERSION"]
19+
20+
mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
21+
if base_version.endswith('+dev') and git.is_git_repo(mypy_dir) and git.have_git():
22+
version = base_version + '.' + git.git_revision(mypy_dir).decode('utf-8')
23+
if git.is_dirty(mypy_dir):
24+
return version + ".dirty"
25+
return version
26+
return base_version

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# alternative forms of installing, as suggested by README.md).
1818
from setuptools import setup, find_packages
1919
from setuptools.command.build_py import build_py
20-
from mypy.version import __version__ as version
20+
from mypy.version import setup_compute_version
2121

2222
description = 'Optional static typing for Python'
2323
long_description = '''
@@ -32,6 +32,8 @@
3232
types.
3333
'''.lstrip()
3434

35+
version = setup_compute_version()
36+
3537

3638
def find_package_data(base, globs, root='mypy'):
3739
"""Find all interesting data files, for setup(package_data=)

0 commit comments

Comments
 (0)