Skip to content

Commit

Permalink
fix(ZNTA-929) zanata-python-client failed to retrieve version in non-…
Browse files Browse the repository at this point in the history
…git environment (#45)

* fix(ZNTA-929)
Use git-describe when in git environment, otherwise use VERSION-FILE

* chore(style): fix style

* Update according review comments
  • Loading branch information
definite committed Apr 14, 2016
1 parent 11b74f6 commit abbb510
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build/
.fliesrc
*~
VERSION-FILE
MANIFEST.in
dist/
*.egg-info/
.idea/
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
* Web Apr 13 2016 Sundeep Anand <[email protected]> - 1.5.0
* Thu Apr 14 2016 Sundeep Anand <[email protected]> - 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 <[email protected]> - 1.4.2
Expand Down
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include zanataclient/VERSION-FILE
include CHANGELOG
include COPYING
include COPYING.LESSER
include zanata.ini
include zanata_example.xml
46 changes: 14 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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"],
Expand Down
34 changes: 23 additions & 11 deletions zanataclient/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit abbb510

Please sign in to comment.