From b35db048266b47c8394fea0615fbf6bd2654dadb Mon Sep 17 00:00:00 2001 From: Megan Wilhite Date: Wed, 19 Apr 2023 13:45:31 -0600 Subject: [PATCH] Fix setup.py called with salt args --- changelog/64114.fixed.md | 1 + setup.py | 7 ++-- tests/pytests/scenarios/setup/test_install.py | 37 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 changelog/64114.fixed.md diff --git a/changelog/64114.fixed.md b/changelog/64114.fixed.md new file mode 100644 index 00000000000..f01c5ea9127 --- /dev/null +++ b/changelog/64114.fixed.md @@ -0,0 +1 @@ +Fix running setup.py when passing in --salt-config-dir and --salt-cache-dir arguments. diff --git a/setup.py b/setup.py index 931ed40a511..c2992548c93 100755 --- a/setup.py +++ b/setup.py @@ -5,10 +5,10 @@ The setup script for salt # pylint: disable=file-perms,resource-leakage import setuptools # isort:skip - import distutils.dist import glob import os +import subprocess import sys import warnings from datetime import datetime @@ -170,8 +170,9 @@ if os.path.exists(SALT_VERSION_HARDCODED): with open(SALT_VERSION_HARDCODED, encoding="utf-8") as rfh: SALT_VERSION = rfh.read().strip() else: - exec(compile(open(SALT_VERSION_MODULE).read(), SALT_VERSION_MODULE, "exec")) - SALT_VERSION = str(__saltstack_version__) # pylint: disable=undefined-variable + SALT_VERSION = ( + subprocess.check_output([sys.executable, SALT_VERSION_MODULE]).decode().strip() + ) # pylint: enable=W0122 diff --git a/tests/pytests/scenarios/setup/test_install.py b/tests/pytests/scenarios/setup/test_install.py index 48f1d5889f6..9c506b56cab 100644 --- a/tests/pytests/scenarios/setup/test_install.py +++ b/tests/pytests/scenarios/setup/test_install.py @@ -3,12 +3,14 @@ Tests for building and installing salt """ import json import logging +import os import pathlib import re import sys import pytest +import salt.utils.files import salt.utils.path import salt.utils.platform import salt.version @@ -457,3 +459,38 @@ def test_setup_install(virtualenv, cache_dir, use_static_requirements, src_dir): installed_salt_path = installed_salt_path[0] / "salt" salt_generated_version_file_path = installed_salt_path / "_version.txt" assert salt_generated_version_file_path.is_file() + + +def test_salt_install_args( + virtualenv, cache_dir, use_static_requirements, src_dir, tmp_path +): + """ + test building with `install` command with --salt-* + args. For example, --salt-config-dir and --salt-cache-dir. + """ + cache_dir = tmp_path / "cache_dir" + config_dir = tmp_path / "config_dir" + # Let's create the testing virtualenv + with virtualenv as venv: + venv.run(venv.venv_python, "setup.py", "clean", cwd=src_dir) + env = os.environ.copy() + env["GENERATE_SALT_SYSPATHS"] = "True" + ret = venv.run( + venv.venv_python, + "setup.py", + "--salt-config-dir", + str(config_dir), + "--salt-cache-dir", + str(cache_dir), + "install", + cwd=src_dir, + env=env, + ) + assert ret.returncode == 0 + syspath = pathlib.Path(src_dir, "build", "lib", "salt", "_syspaths.py") + assert syspath.exists() + with salt.utils.files.fopen(syspath) as fp: + data = fp.read() + assert str(cache_dir) in data + assert str(config_dir) in data + venv.run(venv.venv_python, "setup.py", "clean", cwd=src_dir)