diff options
author | Tim Harder <radhermit@gmail.com> | 2021-03-16 16:13:16 -0600 |
---|---|---|
committer | Tim Harder <radhermit@gmail.com> | 2021-03-16 16:13:16 -0600 |
commit | 3bf45307c5498a0660fc34b2ce54f2564834a571 (patch) | |
tree | 7a8d93aa69e9bd759a10f5cc61cedd492db6b727 /src/snakeoil/dist | |
parent | dist: drop old, unused unittest_extensions module (diff) | |
download | snakeoil-3bf45307c5498a0660fc34b2ce54f2564834a571.tar.gz snakeoil-3bf45307c5498a0660fc34b2ce54f2564834a571.tar.bz2 snakeoil-3bf45307c5498a0660fc34b2ce54f2564834a571.zip |
dist.distutils_extensions: drop duplicated snakeoil functionality
We should be able to use functionality imported from where it's
implemented now due to pyproject.toml build dep support and forcing
setup.py test runs to run against built copies.
Diffstat (limited to 'src/snakeoil/dist')
-rw-r--r-- | src/snakeoil/dist/distutils_extensions.py | 90 |
1 files changed, 3 insertions, 87 deletions
diff --git a/src/snakeoil/dist/distutils_extensions.py b/src/snakeoil/dist/distutils_extensions.py index 1cee238c..c8a63209 100644 --- a/src/snakeoil/dist/distutils_extensions.py +++ b/src/snakeoil/dist/distutils_extensions.py @@ -31,6 +31,9 @@ from distutils.command import ( sdist as dst_sdist, build_ext as dst_build_ext, build_py as dst_build_py, build as dst_build, build_scripts as dst_build_scripts, config as dst_config) +from ..contexts import syspath +from ..version import get_git_version + # forcibly disable lazy module loading os.environ['SNAKEOIL_DEMANDIMPORT'] = 'false' @@ -1157,93 +1160,6 @@ class config(dst_config.config): % (typename, member), headers, include_dirs, lang) -# directly copied from snakeoil.contexts -@contextmanager -def syspath(path, condition=True, position=0): - """Context manager that mangles sys.path and then reverts on exit. - - Args: - path: The directory path to add to sys.path. - condition: Optional boolean that decides whether sys.path is mangled or - not, defaults to being enabled. - position: Optional integer that is the place where the path is inserted - in sys.path, defaults to prepending. - """ - syspath = sys.path[:] - if condition: - sys.path.insert(position, path) - try: - yield - finally: - sys.path = syspath - - -# directly copied from snakeoil.version -# currently required to avoid test failures when running directly via the setup script -def get_git_version(path): - """Return git related revision data.""" - path = os.path.abspath(path) - try: - stdout, ret = _run_git(path, ["log", "--format=%H\n%aD", "HEAD^..HEAD"]) - - if ret != 0: - return None - - data = stdout.decode().splitlines() - tag = _get_git_tag(path, data[0]) - - # get number of commits since most recent tag - stdout, ret = _run_git(path, ['describe', '--tags', '--abbrev=0']) - prev_tag = None - commits = None - if ret == 0: - prev_tag = stdout.decode().strip() - stdout, ret = _run_git( - path, ['log', '--oneline', f'{prev_tag}..HEAD']) - if ret == 0: - commits = len(stdout.decode().splitlines()) - - return { - 'rev': data[0], - 'date': data[1], - 'tag': tag, - 'commits': commits, - } - except EnvironmentError as e: - # ENOENT is thrown when the git binary can't be found. - if e.errno != errno.ENOENT: - raise - return None - - -def _run_git(path, cmd): - env = dict(os.environ) - env["LC_CTYPE"] = "C" - - r = subprocess.Popen( - ['git'] + list(cmd), stdout=subprocess.PIPE, env=env, - stderr=subprocess.DEVNULL, cwd=path) - - stdout = r.communicate()[0] - return stdout, r.returncode - - -def _get_git_tag(path, rev): - stdout, _ = _run_git(path, ['name-rev', '--tag', rev]) - tag = stdout.decode().split() - if len(tag) != 2: - return None - tag = tag[1] - if not tag.startswith("tags/"): - return None - tag = tag[len("tags/"):] - if tag.endswith("^0"): - tag = tag[:-2] - if tag.startswith("v"): - tag = tag[1:] - return tag - - @contextmanager def suppress(verbosity=0): """Context manager that conditionally suppresses stdout/stderr.""" |