Skip to content

Commit

Permalink
some cleanup of Jack's get_python_version code
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Apr 17, 2010
1 parent f1e2a40 commit 33d19eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/build-quixote
Expand Up @@ -11,7 +11,8 @@ python_exe = options.python_executable

repo_url = 'git://quixote.ca/quixote'

tags = [get_python_version(python_exe)] + options.tagset
python_ver = 'python' + get_python_version(python_exe)
tags = [python_ver] + options.tagset
name = 'quixote'

server_url = options.server_url
Expand Down
20 changes: 14 additions & 6 deletions client/pony_client.py
Expand Up @@ -888,13 +888,21 @@ def __str__(self):
return repr(self.python_exe + " not found on system.")


def get_python_version(python_exe):
result = subprocess.Popen(python_exe + " -c \"import sys \nprint" \
" str(sys.version_info[0]) + '.' + str(sys.version_info[1])\"", shell=True, \
stdout=subprocess.PIPE).communicate()
if result[0] == '':
def get_python_version(python_exe='python'):
"""
Return the major.minor number for the given Python executable.
"""

cmd = python_exe + " -c \"import sys \nprint" \
" str(sys.version_info[0]) + '.' + str(sys.version_info[1])\""

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
(stdout, stderr) = p.communicate()

if not stdout:
raise PythonVersionNotFound(python_exe)
return "python" + str(result[0][:-1])

return stdout.strip()

###

Expand Down
9 changes: 9 additions & 0 deletions client/test_client/__init__.py
@@ -1,4 +1,13 @@
import sys
import pony_client

def setup():
pony_client.set_log_level(pony_client.DEBUG_LEVEL)

def test_python_version():
my_version = "%d.%d" % (sys.version_info[:2])

reported_version = pony_client.get_python_version(sys.executable)
reported_version = reported_version

assert my_version == reported_version, (my_version, reported_version)

0 comments on commit 33d19eb

Please sign in to comment.