From 6706f2f56133446d012753c178a4ed61b9d8ac8b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 24 Jan 2022 17:07:56 +0000 Subject: [PATCH 1/7] Fixes #112 install command doesn't use platform in nt_user scheme --- distutils/command/install.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 511938f47f..0c280f1c8c 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -68,8 +68,8 @@ INSTALL_SCHEMES['nt_user'] = { 'purelib': '{usersite}', 'platlib': '{usersite}', - 'headers': '{userbase}/{implementation}{py_version_nodot}/Include/{dist_name}', - 'scripts': '{userbase}/{implementation}{py_version_nodot}/Scripts', + 'headers': '{userbase}/{implementation}{py_version_nodot_plat}/Include/{dist_name}', + 'scripts': '{userbase}/{implementation}{py_version_nodot_plat}/Scripts', 'data' : '{userbase}', } @@ -411,6 +411,10 @@ def finalize_options(self): 'implementation_lower': _get_implementation().lower(), 'implementation': _get_implementation(), } + try: + local_vars['py_version_nodot_plat'] = sys.winver.replace('.', '') + except AttributeError: + local_vars['py_version_nodot_plat'] = '' if HAS_USER_SITE: local_vars['userbase'] = self.install_userbase From a855f07676a3a925797d6bce49af730dfc7e62c8 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 24 Jan 2022 17:58:53 +0000 Subject: [PATCH 2/7] Fix fake expanduser() and verify calculated headers path --- distutils/tests/test_install.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index 75770b05e6..a60db13993 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -81,7 +81,9 @@ def test_user_site(self): install_module.USER_SITE = self.user_site def _expanduser(path): - return self.tmpdir + if path.startswith('~'): + return os.path.normpath(self.tmpdir + path[1:]) + return path self.old_expand = os.path.expanduser os.path.expanduser = _expanduser @@ -122,6 +124,15 @@ def cleanup(): self.assertIn('userbase', cmd.config_vars) self.assertIn('usersite', cmd.config_vars) + actual_headers = os.path.relpath(cmd.install_headers, self.user_base) + expect_headers = os.path.join( + os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), + "Include", + "xx", + ) + + self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers)) + def test_handle_extra_path(self): dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'}) cmd = install(dist) From 2cadaba69aa3d8bef49a5dc8225b4cf5139446a2 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 24 Jan 2022 18:13:13 +0000 Subject: [PATCH 3/7] Add non-NT path for expected path --- distutils/tests/test_install.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index a60db13993..2cc9d31c68 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -125,11 +125,18 @@ def cleanup(): self.assertIn('usersite', cmd.config_vars) actual_headers = os.path.relpath(cmd.install_headers, self.user_base) - expect_headers = os.path.join( - os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), - "Include", - "xx", - ) + if os.name == 'nt': + expect_headers = os.path.join( + os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), + 'Include', + 'xx', + ) + else: + expect_headers = os.path.join( + 'include', + os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base).rpartition(os.sep)[2], + 'xx', + ) self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers)) From aac97591cf99214eb9a7493028ebbbea5b44209c Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 24 Jan 2022 20:19:38 +0000 Subject: [PATCH 4/7] Change API --- distutils/tests/test_install.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index 2cc9d31c68..554b2770e2 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -125,18 +125,7 @@ def cleanup(): self.assertIn('usersite', cmd.config_vars) actual_headers = os.path.relpath(cmd.install_headers, self.user_base) - if os.name == 'nt': - expect_headers = os.path.join( - os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), - 'Include', - 'xx', - ) - else: - expect_headers = os.path.join( - 'include', - os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base).rpartition(os.sep)[2], - 'xx', - ) + expect_headers = os.path.join(sysconfig.get_python_inc(0, ''), 'xx') self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers)) From 198cd3b1c38ac0419933484fecc833581e4b5de3 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 24 Jan 2022 20:54:58 +0000 Subject: [PATCH 5/7] Special case for Windows --- distutils/tests/test_install.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index 554b2770e2..e8ef1caf5f 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -125,7 +125,14 @@ def cleanup(): self.assertIn('usersite', cmd.config_vars) actual_headers = os.path.relpath(cmd.install_headers, self.user_base) - expect_headers = os.path.join(sysconfig.get_python_inc(0, ''), 'xx') + if os.name == 'nt': + expect_headers = os.path.join( + os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), + 'Include', + 'xx', + ) + else: + expect_headers = os.path.join(sysconfig.get_python_inc(0, ''), 'xx') self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers)) From d16d759bb080761732cafb0e85bc804e6b902e46 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Jan 2022 12:55:04 -0500 Subject: [PATCH 6/7] Refactor to limit indentation and share behavior. --- distutils/tests/test_install.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/distutils/tests/test_install.py b/distutils/tests/test_install.py index e8ef1caf5f..5dbc06b090 100644 --- a/distutils/tests/test_install.py +++ b/distutils/tests/test_install.py @@ -126,13 +126,12 @@ def cleanup(): actual_headers = os.path.relpath(cmd.install_headers, self.user_base) if os.name == 'nt': - expect_headers = os.path.join( - os.path.relpath(os.path.dirname(self.old_user_site), self.old_user_base), - 'Include', - 'xx', - ) + site_path = os.path.relpath( + os.path.dirname(self.old_user_site), self.old_user_base) + include = os.path.join(site_path, 'Include') else: - expect_headers = os.path.join(sysconfig.get_python_inc(0, ''), 'xx') + include = sysconfig.get_python_inc(0, '') + expect_headers = os.path.join(include, 'xx') self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers)) From 917046dc70da8c6c5ba87571b0864826085e3659 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Jan 2022 13:12:34 -0500 Subject: [PATCH 7/7] Only rely on py_version_nodot_plat where not present (Python 3.9 and earlier). --- distutils/command/install.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 0c280f1c8c..9fe659131f 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -411,17 +411,19 @@ def finalize_options(self): 'implementation_lower': _get_implementation().lower(), 'implementation': _get_implementation(), } - try: - local_vars['py_version_nodot_plat'] = sys.winver.replace('.', '') - except AttributeError: - local_vars['py_version_nodot_plat'] = '' + + # vars for compatibility on older Pythons + compat_vars = dict( + # Python 3.9 and earlier + py_version_nodot_plat=getattr(sys, 'winver', '').replace('.', ''), + ) if HAS_USER_SITE: local_vars['userbase'] = self.install_userbase local_vars['usersite'] = self.install_usersite self.config_vars = _collections.DictStack( - [sysconfig.get_config_vars(), local_vars]) + [compat_vars, sysconfig.get_config_vars(), local_vars]) self.expand_basedirs()