Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Consistent version number across package and setup

The version number is written in the psycopg2ct/__init__.py module.
It is read from there by setup.py, which appends a list of flags to it and
writes it into the _config module, from which the version string is imported
back into the package.

Currently the only flag used is "ctypes" so that the implementation can be
identified from the cpython one (which sports a version string such as
'2.4.4 (dt dec mx pq3 ext)').
  • Loading branch information...
commit 8a0fd71aa9237080fa56c3b50cfe03e8669a7fee 1 parent fca8ad6
@dvarrazzo authored
Showing with 22 additions and 3 deletions.
  1. +6 −1 psycopg2ct/__init__.py
  2. +16 −2 setup.py
View
7 psycopg2ct/__init__.py
@@ -10,7 +10,7 @@
from psycopg2ct._impl.exceptions import *
from psycopg2ct._impl.typecasts import BINARY, DATETIME, NUMBER, ROWID, STRING
-__version__ = '2.4'
+__version__ = '2.4.4'
apilevel = '2.0'
paramstyle = 'pyformat'
threadsafety = 2
@@ -19,6 +19,11 @@
_ext.register_adapter(tuple, _ext.SQL_IN)
_ext.register_adapter(type(None), _ext.NoneAdapter)
+# check for a more up-to-date version number generated at install time
+try:
+ from psycopg2ct._config import VERSION as __version__
+except ImportError:
+ pass
import re
View
18 setup.py
@@ -13,6 +13,19 @@
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
+# read the version number from the package
+f = open(os.path.join(os.path.dirname(__file__), 'psycopg2ct/__init__.py'))
+try:
+ for line in f:
+ if line.startswith('__version__'):
+ PSYCOPG_VERSION = line.split('=')[1].replace('"', '').replace("'", '').strip()
+ break
+ else:
+ raise ValueError('__version__ not found in psycopg2ct package')
+finally:
+ f.close()
+
+version_flags = ['ctypes']
class PostgresConfig:
@@ -224,7 +237,8 @@ def run(self):
with open(os.path.join(target_path, '_config.py'), 'w') as fh:
fh.write('# Auto-generated by setup.py\n')
- fh.write('PG_LIBRARY = "%s"\n' % self.libpq_path)
+ fh.write('VERSION = %r\n' % ('%s (%s)' % (PSYCOPG_VERSION, ' '.join(version_flags))))
+ fh.write('PG_LIBRARY = %r\n' % self.libpq_path)
fh.write('PG_VERSION = %s\n' % self.libpq_version)
_build_py.run(self)
@@ -240,7 +254,7 @@ def run(self):
author_email='michaelvantellingen@gmail.com',
license='LGPL',
url='http://github.com/mvantellingen/psycopg2-ctypes',
- version='0.3',
+ version='%s (%s)' % (PSYCOPG_VERSION, ' '.join(version_flags)),
cmdclass={
'build_py': build_py
},
Please sign in to comment.
Something went wrong with that request. Please try again.