diff --git a/.gitignore b/.gitignore index 52b3608..1769fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ build/ .fliesrc *~ VERSION-FILE -MANIFEST.in dist/ *.egg-info/ .idea/ diff --git a/CHANGELOG b/CHANGELOG index bc22345..137e0ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,10 @@ -* Web Apr 13 2016 Sundeep Anand - 1.5.0 +* Thu Apr 14 2016 Sundeep Anand - 1.5.0 - ZNTA-946 - zanata push StringIO fix - ZNTA-303 - podir projects handling - ZNTA-936 - redirection 301, 302 handling - ZNTA-934 - java-client compatible zanata.xml - ZNTA-927 - Project Status and Versions +- ZNTA-929 - zanata-python-client failed to retrieve version in non-git environment - Bug 1139950 - Flexible Translation file naming * Wed Jan 20 2016 Sundeep Anand - 1.4.2 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..277788c --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include zanataclient/VERSION-FILE +include CHANGELOG +include COPYING +include COPYING.LESSER +include zanata.ini +include zanata_example.xml diff --git a/setup.py b/setup.py index d62d78f..fec649b 100755 --- a/setup.py +++ b/setup.py @@ -13,37 +13,19 @@ def read(fname): def get_client_version(): - number = "" + version_number = "" + # Use the version in VERSION-FILE path = os.path.dirname(os.path.realpath(__file__)) - version_file = os.path.join(path, 'zanataclient/VERSION-FILE') - version_gen = os.path.join(path, 'VERSION-GEN') - - p = subprocess.Popen(version_gen, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) - output = p.stdout.readline() - number = output.rstrip()[len('version: '):] - - subprocess.Popen(""" - cat << EOF > MANIFEST.in - include zanataclient/VERSION-FILE - include CHANGELOG - include COPYING - include COPYING.LESSER - include zanata.ini -EOF - """, shell=True) - - if number == 'UNKNOWN': - try: - file = open(version_file, 'rb') - client_version = file.read() - file.close() - number = client_version[:-1][len('version: '):] - except IOError: - file = open(version_file, 'w') - file.write("version: UNKNOWN") - file.close - - return number + version_file = os.path.join(path, 'zanataclient', 'VERSION-FILE') + try: + version = open(version_file, 'rb') + client_version = version.read() + version.close() + version_number = client_version.rstrip().strip('version: ') + except IOError: + print("Please run VERSION-GEN or 'make install' to generate VERSION-FILE") + version_number = "UNKNOWN" + return version_number requirements = read('requirements.txt').splitlines() + [ 'setuptools', @@ -56,8 +38,8 @@ def get_client_version(): include_package_data=True, install_requires=requirements, description="Zanata Python Client.", - author='Jian Ni, Ding-Yi Chen, Anish Patil', - author_email='jni@redhat.com, dchen@redhat.com, apatil@redhat.com', + author='Jian Ni, Ding-Yi Chen, Anish Patil, Sundeep Anand', + author_email='dchen@redhat.com, apatil@redhat.com, suanand@redhat.com', license='LGPLv2+', platforms=["Linux"], scripts=["zanata", "flies"], diff --git a/zanataclient/command.py b/zanataclient/command.py index 56cdf8f..4fad387 100644 --- a/zanataclient/command.py +++ b/zanataclient/command.py @@ -24,9 +24,12 @@ # http://jimmyg.org/blog/2009/python-command-line-interface-%28cli%29-with-sub-commands.html # Copyright (C) 2009 James Gardner - http://jimmyg.org/ +from distutils import spawn import getopt import sys import os +import os.path +import subprocess class OptionConfigurationError(Exception): @@ -306,18 +309,27 @@ def handle_program( )) sys.exit(0) elif 'client_version' in program_options: - # Retrieve the version of client + # If running from git repo, then use "git describe" + # otherwise, use VERSION-FILE version_number = "" - path = os.path.dirname(os.path.realpath(__file__)) - version_file = os.path.join(path, 'VERSION-FILE') - try: - version = open(version_file, 'rb') - client_version = version.read() - version.close() - version_number = client_version.rstrip().strip('version: ') - except IOError: - print("Please run VERSION-GEN or 'make install' to generate VERSION-FILE") - version_number = "UNKNOWN" + git_config = os.path.join(os.path.dirname(sys.argv[0]), '.git', 'config') + git_executable = spawn.find_executable("git") + if os.path.isfile(git_config) and not (git_executable is None): + proc = subprocess.Popen(["git", "describe"], stdout=subprocess.PIPE) + (out, err) = proc.communicate() + version_number = out[1:-1] + else: + # Not from git, use VERSION-FILE + path = os.path.dirname(os.path.realpath(__file__)) + version_file = os.path.join(path, 'VERSION-FILE') + try: + version = open(version_file, 'rb') + client_version = version.read() + version.close() + version_number = client_version.rstrip().strip('version: ') + except IOError: + print("Please run VERSION-GEN or 'make install' to generate VERSION-FILE") + version_number = "UNKNOWN" print("zanata python client version: %s" % version_number) else: