close
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import textwrap
from unittest.mock import patch
import tempfile
from copy import copy

from test import support
Expand Down Expand Up @@ -760,6 +761,46 @@ def test_sysconfig_config_vars_no_prefix_cache(self):
self.assertEqual(config_vars['exec_prefix'], sys.exec_prefix)
self.assertEqual(config_vars['platbase'], sys.exec_prefix)

@unittest.skipUnless(
os.name == "posix" and sys.platform != "darwin",
"requires shell python-config",
)
@skip_unless_symlink
@requires_subprocess()
def test_python_config_symlink(self):
if not is_python_build():
self.skipTest("requires a CPython build directory")

python_config = os.path.join(_PROJECT_BASE, "python-config")
if not os.path.isfile(python_config):
self.skipTest("python-config was not built")

with tempfile.TemporaryDirectory() as tmpdir:
real_prefix = os.path.join(tmpdir, "real")
real_bindir = os.path.join(real_prefix, "bin")
os.makedirs(real_bindir)

real_config = os.path.join(real_bindir, "python-config")
shutil.copyfile(python_config, real_config)

link_prefix = os.path.join(tmpdir, "link")
link_bindir = os.path.join(link_prefix, "bin")
os.makedirs(link_bindir)

linked_config = os.path.join(link_bindir, "python-config")
os.symlink(real_config, linked_config)

def get_prefix(config):
return subprocess.check_output(
["/bin/sh", config, "--prefix"],
text=True,
).strip()

expected = os.path.realpath(real_prefix)

self.assertEqual(get_prefix(real_config), expected)
self.assertEqual(get_prefix(linked_config), expected)


class MakefileTests(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion Misc/python-config.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
# Returns the actual prefix where this script was installed to.
installed_prefix ()
{
RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
RESULT=$(dirname $(cd $(dirname $(realpath "$1")) && pwd -P))
if which readlink >/dev/null 2>&1 ; then
if readlink -f "$RESULT" >/dev/null 2>&1; then
RESULT=$(readlink -f "$RESULT")
Expand Down
Loading