From a5b216324dc843d7d46692baeea885fa47b1bdc1 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Mon, 5 Dec 2016 13:49:57 -0500 Subject: setup.py: exclude passlib._setup from bdists, only needed for sdists. --- passlib/_setup/stamp.py | 43 ++++++++++++++++++++++++++++++++++++++----- setup.py | 10 ++++++++-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/passlib/_setup/stamp.py b/passlib/_setup/stamp.py index 3140e5d..2ce3eb3 100644 --- a/passlib/_setup/stamp.py +++ b/passlib/_setup/stamp.py @@ -23,6 +23,15 @@ __all__ = [ def get_command_class(opts, name): return opts['cmdclass'].get(name) or Distribution().get_command_class(name) +def get_command_options(opts, command): + return opts.setdefault("command_options", {}).setdefault(command, {}) + +def set_command_options(opts, command, _source_="setup.py", **kwds): + target = get_command_options(opts, command) + target.update( + (key, (_source_, value)) + for key, value in kwds.items() + ) def _get_file(path): with open(path, "r") as fh: @@ -57,13 +66,15 @@ def stamp_source(base_dir, version, dry_run=False): # # update flag in setup.py + # (not present when called from bdist_wheel, etc) # 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) + if os.path.exists(path): + 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): @@ -112,6 +123,28 @@ def append_hg_revision(version): return version +def install_build_py_exclude(opts): + + _build_py = get_command_class(opts, "build_py") + + class build_py(_build_py): + + user_options = _build_py.user_options + [ + ("exclude-packages=", None, + "exclude packages from builds"), + ] + + exclude_packages = None + + def finalize_options(self): + _build_py.finalize_options(self) + target = self.packages + for package in self.exclude_packages or []: + if package in target: + target.remove(package) + + opts['cmdclass']['build_py'] = build_py + #============================================================================= # eof #============================================================================= diff --git a/setup.py b/setup.py index 1cf9598..9d7a13a 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ opts = dict( #================================================================== # sources #================================================================== - # XXX: could omit 'passlib._setup' for bdist_wheel & eggs packages=setuptools.find_packages(root_dir), package_data={ "passlib.tests": ["*.cfg"], @@ -142,7 +141,8 @@ from passlib import __version__ as version 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 + as_bool, append_hg_revision, stamp_distutils_output, + install_build_py_exclude, set_command_options ) # add HG revision to end of version @@ -153,6 +153,12 @@ if stamp_build: # and clears stamp_build flag so this doesn't run again. stamp_distutils_output(opts, version) + # exclude 'passlib._setup' from builds, only needed for sdist + install_build_py_exclude(opts) + set_command_options(opts, "build_py", + exclude_packages=["passlib._setup"], + ) + opts['version'] = version #============================================================================= -- cgit v1.2.1