Fix version string updating and distutils 'mbcs' error

This commit is contained in:
Luke Campagnola 2016-10-14 18:36:39 -07:00
parent 1899fb0473
commit 8a64c04f71
2 changed files with 40 additions and 24 deletions

View File

@ -41,6 +41,7 @@ pyqtgraph-0.10.0 [unreleased]
- ColorMap forces color inputs to be sorted - ColorMap forces color inputs to be sorted
- Fixed memory mapping for RemoteGraphicsView in OSX - Fixed memory mapping for RemoteGraphicsView in OSX
- Fixed QPropertyAnimation str/bytes handling - Fixed QPropertyAnimation str/bytes handling
- Fixed __version__ string update when using `setup.py install` with newer setuptools
Maintenance: Maintenance:
- Image comparison system for unit testing plus tests for several graphics items - Image comparison system for unit testing plus tests for several graphics items

View File

@ -46,6 +46,17 @@ except ImportError:
from distutils.command import install from distutils.command import install
# Work around mbcs bug in distutils.
# http://bugs.python.org/issue10945
import codecs
try:
codecs.lookup('mbcs')
except LookupError:
ascii = codecs.lookup('ascii')
func = lambda name, enc=ascii: {True: enc}.get(name=='mbcs')
codecs.register(func)
path = os.path.split(__file__)[0] path = os.path.split(__file__)[0]
sys.path.insert(0, os.path.join(path, 'tools')) sys.path.insert(0, os.path.join(path, 'tools'))
import setupHelpers as helpers import setupHelpers as helpers
@ -62,11 +73,9 @@ version, forcedVersion, gitVersion, initVersion = helpers.getVersionStrings(pkg=
class Build(build.build): class Build(build.build):
""" """
* Clear build path before building * Clear build path before building
* Set version string in __init__ after building
""" """
def run(self): def run(self):
global path, version, initVersion, forcedVersion global path
global buildVersion
## Make sure build directory is clean ## Make sure build directory is clean
buildPath = os.path.join(path, self.build_lib) buildPath = os.path.join(path, self.build_lib)
@ -75,43 +84,49 @@ class Build(build.build):
ret = build.build.run(self) ret = build.build.run(self)
class Install(install.install):
"""
* Check for previously-installed version before installing
* Set version string in __init__ after building. This helps to ensure that we
know when an installation came from a non-release code base.
"""
def run(self):
global path, version, initVersion, forcedVersion, installVersion
name = self.config_vars['dist_name']
path = os.path.join(self.install_libbase, 'pyqtgraph')
if os.path.exists(path):
raise Exception("It appears another version of %s is already "
"installed at %s; remove this before installing."
% (name, path))
print("Installing to %s" % path)
rval = install.install.run(self)
# If the version in __init__ is different from the automatically-generated # If the version in __init__ is different from the automatically-generated
# version string, then we will update __init__ in the build directory # version string, then we will update __init__ in the build directory
if initVersion == version: if initVersion == version:
return ret return ret
try: try:
initfile = os.path.join(buildPath, 'pyqtgraph', '__init__.py') initfile = os.path.join(path, '__init__.py')
data = open(initfile, 'r').read() data = open(initfile, 'r').read()
open(initfile, 'w').write(re.sub(r"__version__ = .*", "__version__ = '%s'" % version, data)) open(initfile, 'w').write(re.sub(r"__version__ = .*", "__version__ = '%s'" % version, data))
buildVersion = version installVersion = version
except: except:
if forcedVersion:
raise
buildVersion = initVersion
sys.stderr.write("Warning: Error occurred while setting version string in build path. " sys.stderr.write("Warning: Error occurred while setting version string in build path. "
"Installation will use the original version string " "Installation will use the original version string "
"%s instead.\n" % (initVersion) "%s instead.\n" % (initVersion)
) )
if forcedVersion:
raise
installVersion = initVersion
sys.excepthook(*sys.exc_info()) sys.excepthook(*sys.exc_info())
return ret
return rval
class Install(install.install):
"""
* Check for previously-installed version before installing
"""
def run(self):
name = self.config_vars['dist_name']
path = self.install_libbase
if os.path.exists(path) and name in os.listdir(path):
raise Exception("It appears another version of %s is already "
"installed at %s; remove this before installing."
% (name, path))
print("Installing to %s" % path)
return install.install.run(self)
setup( setup(
version=version, version=version,
cmdclass={'build': Build, cmdclass={'build': Build,