Skip to content

Commit

Permalink
Support MYPY_VERSION for overriding version
Browse files Browse the repository at this point in the history
  • Loading branch information
jhance committed Mar 11, 2022
1 parent 0d38613 commit 3a5b2a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions mypy/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
# - Release versions have the form "0.NNN".
# - Dev versions have the form "0.NNN+dev" (PLUS sign to conform to PEP 440).
# - For 1.0 we'll switch back to 1.2.3 form.
__version__ = '0.950+dev'
base_version = __version__
base_version = '0.950+dev'
# Overridden by setup.py
__version__ = base_version

mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
if __version__.endswith('+dev') and git.is_git_repo(mypy_dir) and git.have_git():
__version__ += '.' + git.git_revision(mypy_dir).decode('utf-8')
if git.is_dirty(mypy_dir):
__version__ += '.dirty'
del mypy_dir

def setup_compute_version() -> str:
# We allow an environment variable to override version, but we should probably
# enforce that it is consistent with the existing version minus additional information.
if "MYPY_VERSION" in os.environ:
assert os.environ["MYPY_VERSION"].startswith(base_version)
return os.environ["MYPY_VERSION"]

mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
if base_version.endswith('+dev') and git.is_git_repo(mypy_dir) and git.have_git():
version = base_version + '.' + git.git_revision(mypy_dir).decode('utf-8')
if git.is_dirty(mypy_dir):
return version + ".dirty"
return version
return base_version
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# alternative forms of installing, as suggested by README.md).
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
from mypy.version import __version__ as version
from mypy.version import setup_compute_version

description = 'Optional static typing for Python'
long_description = '''
Expand All @@ -32,6 +32,8 @@
types.
'''.lstrip()

version = setup_compute_version()


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

0 comments on commit 3a5b2a9

Please sign in to comment.