summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2016-12-05 12:37:19 -0500
committerEli Collins <elic@assurancetechnologies.com>2016-12-05 12:37:19 -0500
commitf5992a60837a4da87dd50843d7cb29ae8f9c9286 (patch)
treefc943d544e157217d17b675e3019533f40c5b43f
parent210537f1210e13f17efa734ea080f1d70d605603 (diff)
downloadpasslib-f5992a60837a4da87dd50843d7cb29ae8f9c9286.tar.gz
setup.py: fixed hg revision stamping so builds from sdist don't try to
re-append hg revision; relocated code to ._setup helper package.
-rwxr-xr-xadmin/upload.sh2
-rw-r--r--passlib/_setup/stamp.py83
-rw-r--r--setup.py44
3 files changed, 88 insertions, 41 deletions
diff --git a/admin/upload.sh b/admin/upload.sh
index 6d1dfda..5aaa053 100755
--- a/admin/upload.sh
+++ b/admin/upload.sh
@@ -10,7 +10,7 @@ SEP2="-----------------------------------------------------"
# init config
#
-export PASSLIB_SETUP_TAG_RELEASE=no
+export SETUP_TAG_RELEASE=no
if [ -z "$DRY_RUN" ]; then
echo "DRY_RUN not set"
diff --git a/passlib/_setup/stamp.py b/passlib/_setup/stamp.py
index d5e559f..3140e5d 100644
--- a/passlib/_setup/stamp.py
+++ b/passlib/_setup/stamp.py
@@ -2,16 +2,20 @@
#=============================================================================
# imports
#=============================================================================
-from __future__ import with_statement
+from __future__ import absolute_import, division, print_function
# core
+from distutils.dist import Distribution
import os
import re
-from distutils.dist import Distribution
+import subprocess
+import time
# pkg
# local
__all__ = [
"stamp_source",
"stamp_distutils_output",
+ "append_hg_revision",
+ "as_bool",
]
#=============================================================================
# helpers
@@ -19,19 +23,48 @@ __all__ = [
def get_command_class(opts, name):
return opts['cmdclass'].get(name) or Distribution().get_command_class(name)
+
+def _get_file(path):
+ with open(path, "r") as fh:
+ return fh.read()
+
+
+def _replace_file(path, content, dry_run=False):
+ if dry_run:
+ return
+ if os.path.exists(path):
+ # sdist likes to use hardlinks, have to remove them first,
+ # or we modify *source* file
+ os.unlink(path)
+ with open(path, "w") as fh:
+ fh.write(content)
+
+
def stamp_source(base_dir, version, dry_run=False):
- """update version string in passlib dist"""
+ """
+ update version info in passlib source
+ """
+ #
+ # update version string in toplevel package source
+ #
path = os.path.join(base_dir, "passlib", "__init__.py")
- with open(path) as fh:
- input = fh.read()
- output, count = re.subn('(?m)^__version__\s*=.*$',
+ content = _get_file(path)
+ content, count = re.subn('(?m)^__version__\s*=.*$',
'__version__ = ' + repr(version),
- input)
+ content)
assert count == 1, "failed to replace version string"
- if not dry_run:
- os.unlink(path) # sdist likes to use hardlinks
- with open(path, "w") as fh:
- fh.write(output)
+ _replace_file(path, content, dry_run=dry_run)
+
+ #
+ # update flag in setup.py
+ #
+ path = os.path.join(base_dir, "setup.py")
+ content = _get_file(path)
+ content, count = re.subn('(?m)^stamp_build\s*=.*$',
+ 'stamp_build = False', content)
+ assert count == 1, "failed to update 'stamp_build' flag"
+ _replace_file(path, content, dry_run=dry_run)
+
def stamp_distutils_output(opts, version):
@@ -51,6 +84,34 @@ def stamp_distutils_output(opts, version):
stamp_source(base_dir, version, self.dry_run)
opts['cmdclass']['sdist'] = sdist
+
+def as_bool(value):
+ return (value or "").lower() in "yes y true t 1".split()
+
+
+def append_hg_revision(version):
+
+ # call HG via subprocess
+ # NOTE: for py26 compat, using Popen() instead of check_output()
+ try:
+ proc = subprocess.Popen(["hg", "tip", "--template", "{date(date, '%Y%m%d%H%M%S')}+hg.{node|short}"],
+ stdout=subprocess.PIPE)
+ stamp, _ = proc.communicate()
+ if proc.returncode:
+ raise subprocess.CalledProcessError(1, [])
+ stamp = stamp.decode("ascii")
+ except (OSError, subprocess.CalledProcessError):
+ # fallback - just use build date
+ stamp = time.strftime("%Y%m%d%H%M%S")
+
+ # modify version
+ if version.endswith((".dev0", ".post0")):
+ version = version[:-1] + stamp
+ else:
+ version += ".post" + stamp
+
+ return version
+
#=============================================================================
# eof
#=============================================================================
diff --git a/setup.py b/setup.py
index 0a1be48..1ea2b9d 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
passlib setup script
This script honors one environmental variable:
-PASSLIB_SETUP_TAG_RELEASE
+SETUP_TAG_RELEASE
if "yes" (the default), revision tag is appended to version.
for release, this is explicitly set to "no".
"""
@@ -16,12 +16,8 @@ os.chdir(root_dir)
#=============================================================================
# imports
#=============================================================================
-import re
from setuptools import setup, find_packages
-import subprocess
import sys
-import time
-PY3 = (sys.version_info[0] >= 3)
#=============================================================================
# init setup options
@@ -45,30 +41,19 @@ except ImportError:
# pull version string from passlib
from passlib import __version__ as version
-# by default, stamp HG revision to end of version
-if os.environ.get("PASSLIB_SETUP_TAG_RELEASE", "y").lower() in "yes y true t 1".split():
- # call HG via subprocess
- # NOTE: for py26 compat, using Popen() instead of check_output()
- try:
- proc = subprocess.Popen(["hg", "tip", "--template", "{date(date, '%Y%m%d%H%M%S')}+hg.{node|short}"],
- stdout=subprocess.PIPE)
- stamp, _ = proc.communicate()
- if proc.returncode:
- raise subprocess.CalledProcessError(1, [])
- stamp = stamp.decode("ascii")
- except (OSError, subprocess.CalledProcessError):
- # fallback - just use build date
- stamp = time.strftime("%Y%m%d%H%M%S")
-
- # modify version
- if version.endswith((".dev0", ".post0")):
- version = version[:-1] + stamp
- else:
- version += ".post" + stamp
-
- # subclass build_py & sdist so they rewrite passlib/__init__.py
- # to have the correct version string
- from passlib._setup.stamp import stamp_distutils_output
+# append hg revision to builds
+stamp_build = True # NOTE: modified by stamp_distutils_output()
+if stamp_build:
+ from passlib._setup.stamp import (
+ as_bool, append_hg_revision, stamp_distutils_output
+ )
+
+ # add HG revision to end of version
+ if as_bool(os.environ.get("SETUP_TAG_RELEASE", "yes")):
+ version = append_hg_revision(version)
+
+ # subclass build_py & sdist to rewrite source version string,
+ # and clears stamp_build flag so this doesn't run again.
stamp_distutils_output(opts, version)
#=============================================================================
@@ -136,6 +121,7 @@ else:
# XXX: could omit 'passlib._setup' from eggs, but not sdist
setup(
# package info
+ # XXX: could omit 'passlib._setup' for bdist_wheel
packages=find_packages(root_dir),
package_data={
"passlib.tests": ["*.cfg"],