Initial removal usage of distutils and replacement with setuptools

This commit is contained in:
David Murphy 2022-12-12 19:04:48 -07:00 committed by Megan Wilhite
parent 7231157c96
commit c6c1a9d121
5 changed files with 64 additions and 8 deletions

View file

@ -211,6 +211,8 @@ def _run_command(args):
def _make_sdist(opts, python_bin="python"):
os.chdir(opts.source_dir)
# TBD replace with build when implement pyproject.toml
stdout, stderr, rcode = _run_command([python_bin, "setup.py", "sdist"])
if rcode == 0:
# Find the sdist with the most recently-modified metadata

View file

@ -29,6 +29,8 @@ class KitchenTestCase(TestCase):
cls.topdir = "/" + os.path.join(*CURRENT_DIR.split("/")[:-2])
cls.use_vt = int(os.environ.get("TESTS_LOG_LEVEL")) >= 5
cmd.run("python setup.py sdist", cwd=cls.topdir)
# TBD cmd.run("python -m pip install --upgrade build") # add build when implement pyproject.toml
# TBD cmd.run("python -m build --sdist {}".format(cls.topdir)) # replace with build when implement pyproject.toml
cmd.run("bundle install", cwd=CURRENT_DIR)
cls.env = {
"KITCHEN_YAML": os.path.join(CURRENT_DIR, ".kitchen.yml"),

View file

@ -4,6 +4,7 @@ import os
import pathlib
import shutil
import sys
from sysconfig import get_path
import _pytest._version
import attr
@ -12,11 +13,6 @@ import pytest
import salt.utils.files
from tests.conftest import CODE_DIR
try:
from sysconfig import get_python_lib # pylint: disable=no-name-in-module
except ImportError:
from distutils.sysconfig import get_python_lib
PYTEST_GE_7 = getattr(_pytest._version, "version_tuple", (-1, -1)) >= (7, 0)
@ -139,7 +135,9 @@ def system_aptsources(request, grains):
"{}".format(*sys.version_info),
"{}.{}".format(*sys.version_info),
]
session_site_packages_dir = get_python_lib()
session_site_packages_dir = get_path(
"purelib"
) # note: platlib and purelib could differ
session_site_packages_dir = os.path.relpath(
session_site_packages_dir, str(CODE_DIR)
)

View file

@ -273,6 +273,7 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
print(f"DGM test_sdist cache_dir '{cache_dir}', src_dir '{src_dir}'")
venv.run(
venv.venv_python,
"-m",
@ -296,6 +297,7 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
fname.unlink()
continue
packages.append(fname)
print(f"DGM test_sdist packages '{packages}'")
venv.install(*[str(pkg) for pkg in packages])
for package in packages:
package.unlink()
@ -307,6 +309,7 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
# pre-installed before installing salt
venv.install("pycurl==7.43.0.5")
print(f"DGM test_sdist for sdist cache_dir '{cache_dir}', src_dir '{src_dir}'")
venv.run(
venv.venv_python,
"setup.py",
@ -315,9 +318,21 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
str(cache_dir),
cwd=src_dir,
)
## dgm_dir = "/home/david/tmp_salt_gen"
## print(f"DGM test_sdist for sdist dgm_dir '{dgm_dir}', src_dir '{src_dir}'")
## venv.run(
## venv.venv_python,
## "setup.py",
## "sdist",
## "--dist-dir",
## dgm_dir,
## cwd=src_dir,
## )
venv.run(venv.venv_python, "setup.py", "clean", cwd=src_dir)
salt_generated_package = list(cache_dir.glob("*.tar.gz"))
print(f"DGM test_sdist salt_generated_package '{salt_generated_package}'")
if not salt_generated_package:
pytest.fail("Could not find the generated sdist file")
salt_generated_package = salt_generated_package[0]
@ -327,12 +342,25 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
sdist_ver_cmp = salt_generated_package.name.split(".tar.gz")[0].split("salt-")[
-1
]
dgm_version = dir(salt.version)
print(
f"DGM test_sdist dgm_version '{dgm_version}', sdist_ver_cmp '{sdist_ver_cmp}', salt.version.__version__ '{salt.version.__version__}'"
)
assert sdist_ver_cmp == salt.version.__version__, "{} != {}".format(
sdist_ver_cmp, salt.version.__version__
)
print(
f"DGM test_sdist venv.install salt_generated_package '{salt_generated_package}'"
)
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
print(f"DGM test_sdist pre-install pip3 list output '{cmd}'")
venv.install(str(salt_generated_package))
## dgm_abspath = "/home/david/tmp_salt_manual/salt-3005.1+1561.g7e544dd3bd.tar.gz"
## print(f"DGM test_sdist attempting install with dgm_abspath '{dgm_abspath}'")
## venv.install(dgm_abspath)
# Let's also ensure we have a salt/_version.py from the installed salt wheel
subdir = [
"lib",
@ -347,12 +375,17 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
installed_salt_path = installed_salt_path.joinpath(*subdir)
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
print(
f"DGM test_sdist salt_generated_version_file_path '{salt_generated_version_file_path}'"
)
assert salt_generated_version_file_path.is_file()
with salt_generated_version_file_path.open() as rfh:
print("DGM _version.py contents to follow:")
log.debug("_version.py contents:\n >>>>>>\n%s\n <<<<<<", rfh.read())
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
print(f"DGM test_sdist pip3 list output '{cmd.stdout}'")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
@ -362,6 +395,10 @@ def test_sdist(virtualenv, cache_dir, use_static_requirements, src_dir):
pytest.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
dgm_version = dir(salt.version)
print(
f"DGM test_sdist dgm_version '{dgm_version}', installed_version '{installed_version}', salt.version.__version__ '{salt.version.__version__}'"
)
assert installed_version == salt.version.__version__, "{} != {}".format(
installed_version, salt.version.__version__
)

View file

@ -1605,6 +1605,7 @@ class VirtualEnv:
setuptools_requirement = attr.ib(
default="setuptools!=50.*,!=51.*,!=52.*", repr=False
)
# TBD build_requirement = attr.ib(default="build!=0.6.*", repr=False) # add build when implement pyproject.toml
environ = attr.ib(init=False, repr=False)
venv_python = attr.ib(init=False, repr=False)
venv_bin_dir = attr.ib(init=False, repr=False)
@ -1642,7 +1643,18 @@ class VirtualEnv:
shutil.rmtree(str(self.venv_dir), ignore_errors=True)
def install(self, *args, **kwargs):
return self.run(self.venv_python, "-m", "pip", "install", *args, **kwargs)
print(f"DGM helper install args '{args}, kwargs '{kwargs}'")
return self.run(
self.venv_python,
"-m",
"pip",
"-vvv",
"install",
"--ignore-installed",
"--force-reinstall",
*args,
**kwargs,
)
def uninstall(self, *args, **kwargs):
return self.run(
@ -1741,7 +1753,12 @@ class VirtualEnv:
cmd.append("--system-site-packages")
cmd.append(str(self.venv_dir))
self.run(*cmd, cwd=str(self.venv_dir.parent))
self.install("-U", self.pip_requirement, self.setuptools_requirement)
self.install(
"-U",
self.pip_requirement,
self.setuptools_requirement,
# TBD self.build_requirement, # add build when implement pyproject.toml
)
log.debug("Created virtualenv in %s", self.venv_dir)