From 5c6684f314d4261f6721a98c1a3cda8f0ec91a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 10 Jun 2011 03:10:53 +0200 Subject: Packaging: use repr to display projects name (3ebabfbf6fe3 followup) --- Lib/packaging/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/packaging/install.py b/Lib/packaging/install.py index 4b82088..2317645 100644 --- a/Lib/packaging/install.py +++ b/Lib/packaging/install.py @@ -520,7 +520,7 @@ def install(project): except InstallationConflict as e: if logger.isEnabledFor(logging.INFO): - projects = ['%s %s' % (p.name, p.version) for p in e.args[0]] + projects = ['%r %s' % (p.name, p.version) for p in e.args[0]] logger.info('%r conflicts with %s', project, ','.join(projects)) return True -- cgit v0.12 From edd95dd3cb205be06270ca7e79467917bd7d3783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 10 Jun 2011 03:48:04 +0200 Subject: Remove *.egg-info from Makefile.pre.in (follow-up to d615eb7bce33, #12218) --- Makefile.pre.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 07486fd..2ca89cf 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -950,7 +950,7 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) else true; \ fi; \ done - @for i in $(srcdir)/Lib/*.py $(srcdir)/Lib/*.egg-info $(srcdir)/Lib/*.cfg ; \ + @for i in $(srcdir)/Lib/*.py $(srcdir)/Lib/*.cfg ; \ do \ if test -x $$i; then \ $(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \ -- cgit v0.12 From f53cd89006ccd2144e5707c3fd4ccf5c96a3ec20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 10 Jun 2011 03:53:49 +0200 Subject: Fix omission in test for packaging install_distinfo command. The code does not write checksum or file length for .pyc and .pyo in the RECORD file, in compliance with PEP 376, but the test forgot to take .pyo into account. This was not caught because there were no .pyo in the checkout, but after installing there are .pyo files created by compileall, and the test picks them up. --- Lib/packaging/tests/test_command_install_distinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/packaging/tests/test_command_install_distinfo.py b/Lib/packaging/tests/test_command_install_distinfo.py index 6d40f66..ade191c 100644 --- a/Lib/packaging/tests/test_command_install_distinfo.py +++ b/Lib/packaging/tests/test_command_install_distinfo.py @@ -162,7 +162,7 @@ class InstallDistinfoTestCase(support.TempdirManager, expected = [] for f in install.get_outputs(): - if (f.endswith('.pyc') or f == os.path.join( + if (f.endswith(('.pyc', '.pyo')) or f == os.path.join( install_dir, 'foo-1.0.dist-info', 'RECORD')): expected.append([f, '', '']) else: -- cgit v0.12 From 2b612220e4ddaea89058065f98735590b710550d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 10 Jun 2011 04:29:43 +0200 Subject: Clean up extra environment variable after packaging tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit packaging.util.check_environ will define HOME and PLAT if they don’t exist; for some reason, it does not define PLAT when running the tests from a checkout (so no regrtest warning) but does when running from an installed Python. Cleaning up the envvar in test_dist fixes the warning on my machine, but I suspect that a test runner using a different order to run files or running them in parallel may have PLAT defined in its environment because of another test. Quite a lot of code ends up calling check_environ; maybe we should just clean up PLAT in every test. For now I’m doing this simple fix, we’ll see if we get bug reports. --- Lib/packaging/tests/test_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/packaging/tests/test_dist.py b/Lib/packaging/tests/test_dist.py index fb6d524..e1c5ff0 100644 --- a/Lib/packaging/tests/test_dist.py +++ b/Lib/packaging/tests/test_dist.py @@ -35,7 +35,7 @@ class DistributionTestCase(support.TempdirManager, support.EnvironRestorer, unittest.TestCase): - restore_environ = ['HOME'] + restore_environ = ['HOME', 'PLAT'] def setUp(self): super(DistributionTestCase, self).setUp() -- cgit v0.12 From fa6cfbc4f73100714bca79280d51836f2bac4bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 10 Jun 2011 18:31:40 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20try=20to=20install=20something=20when?= =?UTF-8?q?=20running=20from=20uninstalled=20source=20(#12246).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original patch by Tshepang Lekhonkhobe. --- Lib/packaging/install.py | 17 ++++++++++++++--- Lib/packaging/tests/test_install.py | 14 ++++++++++++-- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Lib/packaging/install.py b/Lib/packaging/install.py index 2317645..c5bda45 100644 --- a/Lib/packaging/install.py +++ b/Lib/packaging/install.py @@ -13,7 +13,7 @@ import errno import shutil import logging import tempfile -from sysconfig import get_config_var, get_path +from sysconfig import get_config_var, get_path, is_python_build from packaging import logger from packaging.dist import Distribution @@ -488,20 +488,31 @@ def install(project): Returns True on success, False on failure """ + if is_python_build(): + # Python would try to install into the site-packages directory under + # $PREFIX, but when running from an uninstalled code checkout we don't + # want to create directories under the installation root + message = ('installing third-party projects from an uninstalled ' + 'Python is not supported') + logger.error(message) + return False + logger.info('Checking the installation location...') purelib_path = get_path('purelib') + # trying to write a file there try: with tempfile.NamedTemporaryFile(suffix=project, dir=purelib_path) as testfile: testfile.write(b'test') except OSError: - # was unable to write a file + # FIXME this should check the errno, or be removed altogether (race + # condition: the directory permissions could be changed between here + # and the actual install) logger.info('Unable to write in "%s". Do you have the permissions ?' % purelib_path) return False - logger.info('Getting information about %r...', project) try: info = get_infos(project) diff --git a/Lib/packaging/tests/test_install.py b/Lib/packaging/tests/test_install.py index c50a45e..35733c8 100644 --- a/Lib/packaging/tests/test_install.py +++ b/Lib/packaging/tests/test_install.py @@ -1,5 +1,7 @@ """Tests for the packaging.install module.""" import os +import logging +from sysconfig import is_python_build from tempfile import mkstemp from packaging import install @@ -357,9 +359,17 @@ class TestInstall(LoggingCatcher, TempdirManager, unittest.TestCase): install._install_dist = old_install_dist def test_install_permission_denied(self): - # if we don't have the access to the installation - # path, we should abort immediatly + # if we don't have access to the installation path, we should abort + # immediately project = os.path.join(os.path.dirname(__file__), 'package.tgz') + + # when running from an uninstalled build, a warning is emitted and the + # installation is not attempted + if is_python_build(): + self.assertFalse(install.install(project)) + self.assertEqual(1, len(self.get_logs(logging.ERROR))) + return + install_path = self.mkdtemp() old_get_path = install.get_path install.get_path = lambda path: install_path diff --git a/Misc/ACKS b/Misc/ACKS index 900fae7..de5410c 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -550,6 +550,7 @@ Joerg Lehmann Robert Lehmann Petri Lehtinen Luke Kenneth Casson Leighton +Tshepang Lekhonkhobe Marc-Andre Lemburg John Lenton Christopher Tur Lesniewski-Laas diff --git a/Misc/NEWS b/Misc/NEWS index 772eef9..e94b77c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -187,6 +187,10 @@ Core and Builtins Library ------- +- Issue #12246: Warn and fail when trying to install a third-party project from + an uninstalled Python (built in a source checkout). Original patch by + Tshepang Lekhonkhobe. + - Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes instead of os.stat. -- cgit v0.12