From ab037cb0ffa5cef47baa897e0d14ebb5eb394bcf Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Tue, 8 Aug 2023 03:35:24 -0700 Subject: [PATCH] Support running tests in more environments (#84) --- setuptools_git_versioning.py | 5 +++++ tests/lib/util.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/setuptools_git_versioning.py b/setuptools_git_versioning.py index ab4ff00..19d7965 100644 --- a/setuptools_git_versioning.py +++ b/setuptools_git_versioning.py @@ -15,6 +15,11 @@ from pprint import pformat from typing import TYPE_CHECKING, Any, Callable +# because we use distutils in this file, we need to ensure that setuptools is +# imported first so that it can do monkey patching. this is not always already +# done for us, for example, when running this in a test or as a module +import setuptools # noqa: F401 + if TYPE_CHECKING: # avoid importing 'packaging' because setuptools-git-versioning can be installed using sdist # where 'packaging' is not installed yet diff --git a/tests/lib/util.py b/tests/lib/util.py index 3706a8b..ab218cf 100644 --- a/tests/lib/util.py +++ b/tests/lib/util.py @@ -30,6 +30,13 @@ def rand_sha() -> str: def execute(cwd: str | os.PathLike, cmd: str, **kwargs) -> str: log.info(f"Executing '{cmd}' at '{cwd}'") + + if "env" in kwargs: + kwargs["env"]["PATH"] = os.environ["PATH"] + pythonpath = os.getenv("PYTHONPATH", None) + if pythonpath: + kwargs["env"]["PYTHONPATH"] = pythonpath + return subprocess.check_output(cmd, cwd=cwd, shell=True, universal_newlines=True, **kwargs) # nosec