From b7eef37d2b237cef2f0885afb3e78220f208bc2d Mon Sep 17 00:00:00 2001 From: gordon Date: Thu, 17 Nov 2011 23:21:08 -0500 Subject: [PATCH 01/14] create a simple setup.py script so py2js can be installed with the standard python setup.py install approach --- setup.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..452bcc8 --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +from os import listdir,remove +from os.path import join +from setuptools import setup, find_packages + +DESCRIPTION = 'Python to JavaScript translator' +LONG_DESCRIPTION = None +try: + LONG_DESCRIPTION = open('README.rst').read() +except: + pass + +AUTHORS = None +try: + AUTHORS = open('AUTHORS').read() +except: + pass + +# create the py-builtins.js file +# NOTE: +# test runner expects +# for the py-builtins.js +# file to be available +# so it should not be +# removed by the installer +builtins_dir = 'library' +builtins_out = 'py-builtins.js' +with open(builtins_out,'wb') as f: + paths = [join(builtins_dir,path) for path in sorted(listdir(builtins_dir))] + for path in paths: + with open(path,'rb') as fp: + f.write(fp.read()) + +setup( + data_files = [('', [builtins_out])], + description=DESCRIPTION, + license="MIT", + long_description=LONG_DESCRIPTION, + name='py2js', + version='0.0.0', + packages=find_packages(), + platforms=['any'], + scripts=['pyjs.py'], + url='https://github.com/qsnake/py2js', +) \ No newline at end of file From ebfbec53fe71e1656797ffc190e44561b7a4054d Mon Sep 17 00:00:00 2001 From: gordon Date: Thu, 17 Nov 2011 23:29:16 -0500 Subject: [PATCH 02/14] update for compliance --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index bf93c3c..cb9d8c9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,5 +13,6 @@ People who contributed by sending at least one patch: Baniel Jonathan Fine Pablo Angulo + Gordon Pendleton Tests were taken from js4py written by Jonathan Fine. From 13d10b4e0f8d2354e448b90e95028ce95736d6c7 Mon Sep 17 00:00:00 2001 From: gordon Date: Thu, 17 Nov 2011 23:55:09 -0500 Subject: [PATCH 03/14] add required author information. from http://groups.google.com/group/py2js/msg/fe5b9df5b9273591 , Ondrej Certik should be listed as the main author for the setup script. --- setup.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 452bcc8..1dd2fe6 100644 --- a/setup.py +++ b/setup.py @@ -31,14 +31,16 @@ f.write(fp.read()) setup( + author = 'Ondrej Certik', + author_email = 'ondrej@certik.cz', data_files = [('', [builtins_out])], - description=DESCRIPTION, - license="MIT", - long_description=LONG_DESCRIPTION, - name='py2js', - version='0.0.0', - packages=find_packages(), - platforms=['any'], - scripts=['pyjs.py'], - url='https://github.com/qsnake/py2js', + description = DESCRIPTION, + license = 'MIT', + long_description = LONG_DESCRIPTION, + name = 'py2js', + version = '0.0.0', + packages = find_packages(), + platforms = ['any'], + scripts = ['pyjs.py'], + url = 'https://github.com/qsnake/py2js', ) \ No newline at end of file From c58ec0d600d5fd204c1baf564ec8b1611dd5d71b Mon Sep 17 00:00:00 2001 From: gordon Date: Fri, 18 Nov 2011 17:07:59 -0500 Subject: [PATCH 04/14] ignore generated files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 24d7c7f..5337c93 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ tests/*/*.err tests/*/*.py.js tests/*.err tests/*.out +build +dist +py2js.egg-info +VERSION \ No newline at end of file From 0a0e30da8123f3bcad01f5aaaab2ecc6952fdf60 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 00:02:25 -0500 Subject: [PATCH 05/14] provides version information using git describe --- _version.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 _version.py diff --git a/_version.py b/_version.py new file mode 100644 index 0000000..b8c70c2 --- /dev/null +++ b/_version.py @@ -0,0 +1,92 @@ +from os.path import join, dirname +from platform import system, version +from re import findall +from subprocess import Popen, PIPE + +version_file = join(dirname(__file__),'VERSION') + +class GITExecutable(object): + """ + Attempts to find git. + Returns the best guess + at the path for a git + executable. + """ + def __new__(self): + cmd = 'which' + if system() == 'Windows': + try: + major, minor = [int(x) for x in version().split('.',2)[0:2]] + # version number information + # http://msdn.microsoft.com/en-us/library/ms724834%28v=VS.85%29.aspx + if major > 6 or major == 6 and minor: + # Windows 7 brings the + # where command with + # functionality similar + # to which on unix. + cmd = 'where' + except: + pass + try: + p = Popen([cmd, 'git'], stdout=PIPE, stderr=PIPE) + p.stderr.close() + path = p.stdout.next().strip() + except: + path = None + return path or 'git' + +GIT_EXECUTABLE = GITExecutable() + +def get_version(): + file_version = get_file_version() + version = get_repo_version() or file_version + if version is None: + raise ValueError('Could not determine version.') + if version != file_version: + put_file_version(version) + return version + +def get_file_version(): + try: + with open(version_file, 'rb') as fp: + version = fp.next().strip() + except: + version = None + return version + +def put_file_version(version): + with open(version_file, 'wb') as fp: + fp.write(version) + +def get_repo_version(): + """ + Repo tags are assumed to be in the format: + vMajor.Minor + + Example: + v0.1 + + Function returns a version string of the form: + vMajor.Minor.PatchHash + + Example: + v0.1.1gc58ec0d + """ + try: + p = Popen([GIT_EXECUTABLE, 'describe'], stdout=PIPE, stderr=PIPE) + p.stderr.close() + parts = findall('[a-zA-Z0-9]+',p.stdout.next().strip()) + if parts: + version = "%s.%s" % (parts[0],parts[1]) + if len(parts) > 2: + version = "%s.%s%s" % (version,parts[2],parts[3]) + else: + version = "%s.0" % version + else: + raise ValueError('git describe did not return a valid version string.') + except: + version = None + return version + +if __name__ == '__main__': + print get_version() \ No newline at end of file From e20f5f901626a13738823897ca600569332e1561 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 00:03:53 -0500 Subject: [PATCH 06/14] supply version information using get_version() from _version.py --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1dd2fe6..0bcc277 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,9 @@ from os import listdir,remove from os.path import join from setuptools import setup, find_packages +from _version import get_version, version_file + +version = get_version() DESCRIPTION = 'Python to JavaScript translator' LONG_DESCRIPTION = None @@ -33,12 +36,12 @@ setup( author = 'Ondrej Certik', author_email = 'ondrej@certik.cz', - data_files = [('', [builtins_out])], + data_files = [('', [builtins_out]), ('py2js', [version_file, '_version.py'])], description = DESCRIPTION, license = 'MIT', long_description = LONG_DESCRIPTION, name = 'py2js', - version = '0.0.0', + version = version, packages = find_packages(), platforms = ['any'], scripts = ['pyjs.py'], From db38a0f178b7c973d69485402ff6b1b88a79507e Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 00:05:10 -0500 Subject: [PATCH 07/14] make version information easily available from inside the module --- py2js/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/py2js/__init__.py b/py2js/__init__.py index e9d5a16..bf889ae 100644 --- a/py2js/__init__.py +++ b/py2js/__init__.py @@ -3,6 +3,9 @@ import ast import inspect import formater +from _version import get_version + +__version__ = get_version() def scope(func): func.scope = True From 95ffef4ba33876dff6cb14d0c556a871671b1948 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 00:35:49 -0500 Subject: [PATCH 08/14] provide a manifest template so that "python setup.py sdist" will contain files required for installation that the default template omits --- MANIFEST.in | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..dd89c78 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include AUTHORS +include LICENSE +include README.rst +include library/* +include _version.py \ No newline at end of file From 61ea83faefdd8f4204768e52ff53578b3e699e52 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 12:00:19 -0500 Subject: [PATCH 09/14] provide a version info tuple so that the version string does not need to be manually parsed. --- _version.py | 27 ++++++++++++++++++++++++++- py2js/__init__.py | 3 ++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/_version.py b/_version.py index b8c70c2..0019960 100644 --- a/_version.py +++ b/_version.py @@ -1,6 +1,6 @@ from os.path import join, dirname from platform import system, version -from re import findall +from re import findall, match, IGNORECASE from subprocess import Popen, PIPE version_file = join(dirname(__file__),'VERSION') @@ -88,5 +88,30 @@ def get_repo_version(): version = None return version +def parse_version(version): + """ + input version string of the form: + 'vMajor.Minor.PatchHash' + like: + 'v0.1.5g95ffef4' + returns version_info tuple of the form: + (major,minor,patch,hash) + like: + (0, 1, 5, '95ffef4') + """ + matches = match( + 'v(?P[0-9]+)\.(?P[0-9]+)\.(?P[0-9]+)g(?P[a-z0-9]*)', + version, + IGNORECASE + ) + if matches: + major = int(matches.group('major')) + minor = int(matches.group('minor')) + patch = int(matches.group('patch')) + hash = matches.group('hash') + return (major,minor,patch,hash) + else: + raise ValueError("Version string, '%s' could not be parsed. It should be of the form: 'vMajor.Minor.PatchHash'." % version) + if __name__ == '__main__': print get_version() \ No newline at end of file diff --git a/py2js/__init__.py b/py2js/__init__.py index bf889ae..fadf60c 100644 --- a/py2js/__init__.py +++ b/py2js/__init__.py @@ -3,9 +3,10 @@ import ast import inspect import formater -from _version import get_version +from _version import get_version, parse_version __version__ = get_version() +__version_info__ = parse_version(__version__) def scope(func): func.scope = True From e8813d6389e9ed1e4f4a8f6cf237f19b54151f8d Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 12:09:27 -0500 Subject: [PATCH 10/14] parse version strings that do not have a commit hash... e.g. 'v0.1.0' --- _version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_version.py b/_version.py index 0019960..33cd441 100644 --- a/_version.py +++ b/_version.py @@ -100,7 +100,7 @@ def parse_version(version): (0, 1, 5, '95ffef4') """ matches = match( - 'v(?P[0-9]+)\.(?P[0-9]+)\.(?P[0-9]+)g(?P[a-z0-9]*)', + 'v(?P[0-9]+)\.(?P[0-9]+)\.(?P[0-9]+)(g(?P[a-z0-9]*))?', version, IGNORECASE ) @@ -108,7 +108,7 @@ def parse_version(version): major = int(matches.group('major')) minor = int(matches.group('minor')) patch = int(matches.group('patch')) - hash = matches.group('hash') + hash = matches.group('hash') or '' return (major,minor,patch,hash) else: raise ValueError("Version string, '%s' could not be parsed. It should be of the form: 'vMajor.Minor.PatchHash'." % version) From 5fa814a683aed7b2451a757cf44985c6c9d646f0 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 12:12:29 -0500 Subject: [PATCH 11/14] provide an example of the tuple returned from parse_version when the hash is not present in the version string --- _version.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_version.py b/_version.py index 33cd441..cda3694 100644 --- a/_version.py +++ b/_version.py @@ -94,10 +94,15 @@ def parse_version(version): 'vMajor.Minor.PatchHash' like: 'v0.1.5g95ffef4' + ------ or ------ + 'v0.1.0' + returns version_info tuple of the form: (major,minor,patch,hash) like: (0, 1, 5, '95ffef4') + -------- or -------- + (0, 1, 0, '') """ matches = match( 'v(?P[0-9]+)\.(?P[0-9]+)\.(?P[0-9]+)(g(?P[a-z0-9]*))?', From 5e165a84586a6d4de47552dad062d6076edb7c99 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 13:21:44 -0500 Subject: [PATCH 12/14] automatically install unittest2 for python version < (2,7) --- setup.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.py b/setup.py index 0bcc277..269bc34 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ from os import listdir,remove from os.path import join from setuptools import setup, find_packages +from sys import version_info from _version import get_version, version_file version = get_version() @@ -33,11 +34,18 @@ with open(path,'rb') as fp: f.write(fp.read()) +# require dependencies +if version_info < (2 , 7): + REQUIRES = ('unittest2',) +else: + REQUIRES = () + setup( author = 'Ondrej Certik', author_email = 'ondrej@certik.cz', data_files = [('', [builtins_out]), ('py2js', [version_file, '_version.py'])], description = DESCRIPTION, + install_requires=REQUIRES, license = 'MIT', long_description = LONG_DESCRIPTION, name = 'py2js', From a34aef90d0c46856c0777f8c6ed41023890f1330 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 13:40:54 -0500 Subject: [PATCH 13/14] include tests in the distribution tarball so that they can be tested after installation --- MANIFEST.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index dd89c78..2f3fb3b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,7 @@ include AUTHORS include LICENSE include README.rst include library/* -include _version.py \ No newline at end of file +include run_tests.py +include _version.py +recursive-include tests *.js *.py +recursive-exclude tests *.py.js \ No newline at end of file From 413795426694a6452ce95e159079f996cb3da584 Mon Sep 17 00:00:00 2001 From: gordon Date: Sat, 19 Nov 2011 15:18:49 -0500 Subject: [PATCH 14/14] write the Windows version comparison in a more readable manner --- _version.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_version.py b/_version.py index cda3694..bdf8fd2 100644 --- a/_version.py +++ b/_version.py @@ -19,7 +19,9 @@ def __new__(self): major, minor = [int(x) for x in version().split('.',2)[0:2]] # version number information # http://msdn.microsoft.com/en-us/library/ms724834%28v=VS.85%29.aspx - if major > 6 or major == 6 and minor: + # (6, 0) is Vista or Windows Server 2008 + # (6, 1) is Windows 7 or Server 2008 RC2 + if (major, minor) > (6, 0): # Windows 7 brings the # where command with # functionality similar