From e07fe3868badb97eb5804e7a71c1ad601e7d775a Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 2 Nov 2016 14:29:37 -0700 Subject: [PATCH 1/3] Show full version in -V when run directly from git repo --- mypy/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/main.py b/mypy/main.py index 19656e189e365..a56a2b3c249c3 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -139,8 +139,12 @@ def process_options(args: List[str], # parsed into the separate special_opts namespace object. parser.add_argument('-v', '--verbose', action='count', dest='verbosity', help="more verbose messages") + full_version = __version__ + if git.is_git_repo('.') and git.have_git(): + full_version += '-' + git.git_revision('.').decode('utf-8') + parser.add_argument('-V', '--version', action='version', - version='%(prog)s ' + __version__) + version='%(prog)s ' + full_version) parser.add_argument('--python-version', type=parse_version, metavar='x.y', help='use Python x.y') parser.add_argument('--platform', action='store', metavar='PLATFORM', From e605922fb45bf35a2347c032b501074237aecd53 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 2 Nov 2016 17:39:52 -0700 Subject: [PATCH 2/3] Use parent of mypy package, not current directory, as potential git repo --- mypy/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index a56a2b3c249c3..caa0a69bc1cbc 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -140,9 +140,9 @@ def process_options(args: List[str], parser.add_argument('-v', '--verbose', action='count', dest='verbosity', help="more verbose messages") full_version = __version__ - if git.is_git_repo('.') and git.have_git(): - full_version += '-' + git.git_revision('.').decode('utf-8') - + mypy_dir = os.path.dirname(os.path.dirname(__file__)) + if git.is_git_repo(mypy_dir) and git.have_git(): + full_version += '-' + git.git_revision(mypy_dir).decode('utf-8') parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + full_version) parser.add_argument('--python-version', type=parse_version, metavar='x.y', From f44f0d2e5ec179254c5ddd2044c9905d55c0486b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 3 Nov 2016 10:15:39 -0700 Subject: [PATCH 3/3] Move the git magic into version.py so everyone benefits --- mypy/main.py | 6 +----- mypy/version.py | 10 ++++++++++ setup.py | 15 +-------------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index caa0a69bc1cbc..19656e189e365 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -139,12 +139,8 @@ def process_options(args: List[str], # parsed into the separate special_opts namespace object. parser.add_argument('-v', '--verbose', action='count', dest='verbosity', help="more verbose messages") - full_version = __version__ - mypy_dir = os.path.dirname(os.path.dirname(__file__)) - if git.is_git_repo(mypy_dir) and git.have_git(): - full_version += '-' + git.git_revision(mypy_dir).decode('utf-8') parser.add_argument('-V', '--version', action='version', - version='%(prog)s ' + full_version) + version='%(prog)s ' + __version__) parser.add_argument('--python-version', type=parse_version, metavar='x.y', help='use Python x.y') parser.add_argument('--platform', action='store', metavar='PLATFORM', diff --git a/mypy/version.py b/mypy/version.py index 9c836b031cb52..091e99bec7f55 100644 --- a/mypy/version.py +++ b/mypy/version.py @@ -1 +1,11 @@ +import os +from mypy import git + __version__ = '0.4.6-dev' + +mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +if 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 diff --git a/setup.py b/setup.py index 3733f72800c62..f9c249fb7b984 100644 --- a/setup.py +++ b/setup.py @@ -31,19 +31,6 @@ '''.lstrip() -def cache_version_id(): - """Returns the version id to use for the incremental hash. - - If setup.py is run from a git repo, the git commit hash will be - included if possible. If not, then this function will fall back to - using the default version id from mypy/version.py.""" - if git.is_git_repo('.') and git.have_git(): - return __version__ + '-' + git.git_revision('.').decode('utf-8') - else: - # Default fallback - return __version__ - - def find_data_files(base, globs): """Find all interesting data files, for setup(data_files=) @@ -71,7 +58,7 @@ def pin_version(self): path = os.path.join(self.build_lib, 'mypy') self.mkpath(path) with open(os.path.join(path, 'version.py'), 'w') as stream: - stream.write('__version__ = "{}"\n'.format(cache_version_id())) + stream.write('__version__ = "{}"\n'.format(version)) def run(self): self.execute(self.pin_version, ())