Allow setting $TMPDIR to $PWD/... during pip wheel
Needed for https://bugzilla.redhat.com/show_bug.cgi?id=1806625
This commit is contained in:
parent
7913cd9edf
commit
4347c1397d
149
7873.patch
Normal file
149
7873.patch
Normal file
@ -0,0 +1,149 @@
|
||||
From 98aa09cf88d8851bb2be6ad39be1cbca7d181916 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||||
Date: Thu, 19 Mar 2020 17:57:53 +0100
|
||||
Subject: [PATCH 1/2] Prevent infinite recursion with pip wheel with $TMPDIR in
|
||||
$PWD
|
||||
|
||||
During a build of extension module within `pip wheel` the source directory is
|
||||
recursively copied in a temporary directory.
|
||||
|
||||
See https://github.com/pypa/pip/issues/7555
|
||||
|
||||
When the temporary directory is inside the source directory
|
||||
(for example by setting `TMPDIR=$PWD/tmp`) this caused an infinite recursion
|
||||
that ended in:
|
||||
|
||||
[Errno 36] File name too long
|
||||
|
||||
We prevent that buy never copying the target to the target in _copy_source_tree.
|
||||
|
||||
Fixes https://github.com/pypa/pip/issues/7872
|
||||
---
|
||||
news/7872.bugfix | 1 +
|
||||
src/pip/_internal/operations/prepare.py | 22 +++++++++++++++++-----
|
||||
tests/data/src/extension/extension.c | 0
|
||||
tests/data/src/extension/setup.py | 4 ++++
|
||||
tests/functional/test_wheel.py | 11 +++++++++++
|
||||
5 files changed, 33 insertions(+), 5 deletions(-)
|
||||
create mode 100644 news/7872.bugfix
|
||||
create mode 100644 tests/data/src/extension/extension.c
|
||||
create mode 100644 tests/data/src/extension/setup.py
|
||||
|
||||
diff --git a/news/7872.bugfix b/news/7872.bugfix
|
||||
new file mode 100644
|
||||
index 0000000000..3550d573b8
|
||||
--- /dev/null
|
||||
+++ b/news/7872.bugfix
|
||||
@@ -0,0 +1 @@
|
||||
+Prevent an infinite recursion with ``pip wheel`` when ``$TMPDIR`` is within the source directory.
|
||||
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
|
||||
index 9f87148c03..1fcbb775ec 100644
|
||||
--- a/src/pip/_internal/operations/prepare.py
|
||||
+++ b/src/pip/_internal/operations/prepare.py
|
||||
@@ -156,13 +156,25 @@ def _copy2_ignoring_special_files(src, dest):
|
||||
|
||||
def _copy_source_tree(source, target):
|
||||
# type: (str, str) -> None
|
||||
+ target_abspath = os.path.abspath(target)
|
||||
+ target_basename = os.path.basename(target_abspath)
|
||||
+ target_dirname = os.path.dirname(target_abspath)
|
||||
+
|
||||
def ignore(d, names):
|
||||
# type: (str, List[str]) -> List[str]
|
||||
- # Pulling in those directories can potentially be very slow,
|
||||
- # exclude the following directories if they appear in the top
|
||||
- # level dir (and only it).
|
||||
- # See discussion at https://github.com/pypa/pip/pull/6770
|
||||
- return ['.tox', '.nox'] if d == source else []
|
||||
+ skipped = [] # type: List[str]
|
||||
+ if d == source:
|
||||
+ # Pulling in those directories can potentially be very slow,
|
||||
+ # exclude the following directories if they appear in the top
|
||||
+ # level dir (and only it).
|
||||
+ # See discussion at https://github.com/pypa/pip/pull/6770
|
||||
+ skipped += ['.tox', '.nox']
|
||||
+ if os.path.abspath(d) == target_dirname:
|
||||
+ # Prevent an infinite recursion if the target is in source.
|
||||
+ # This can happen when TMPDIR is set to ${PWD}/...
|
||||
+ # and we copy PWD to TMPDIR.
|
||||
+ skipped += [target_basename]
|
||||
+ return skipped
|
||||
|
||||
kwargs = dict(ignore=ignore, symlinks=True) # type: CopytreeKwargs
|
||||
|
||||
diff --git a/tests/data/src/extension/extension.c b/tests/data/src/extension/extension.c
|
||||
new file mode 100644
|
||||
index 0000000000..e69de29bb2
|
||||
diff --git a/tests/data/src/extension/setup.py b/tests/data/src/extension/setup.py
|
||||
new file mode 100644
|
||||
index 0000000000..b26302b053
|
||||
--- /dev/null
|
||||
+++ b/tests/data/src/extension/setup.py
|
||||
@@ -0,0 +1,4 @@
|
||||
+from setuptools import Extension, setup
|
||||
+
|
||||
+module = Extension('extension', sources=['extension.c'])
|
||||
+setup(name='extension', version='0.0.1', ext_modules = [module])
|
||||
diff --git a/tests/functional/test_wheel.py b/tests/functional/test_wheel.py
|
||||
index ce79dbee5e..f293233b9d 100644
|
||||
--- a/tests/functional/test_wheel.py
|
||||
+++ b/tests/functional/test_wheel.py
|
||||
@@ -289,6 +289,17 @@ def test_pip_wheel_with_user_set_in_config(script, data, common_wheels):
|
||||
assert "Successfully built withpyproject" in result.stdout, result.stdout
|
||||
|
||||
|
||||
+def test_pip_wheel_ext_module_with_tmpdir_inside(script, data, common_wheels):
|
||||
+ tmpdir = data.src / 'extension/tmp'
|
||||
+ tmpdir.mkdir()
|
||||
+ script.environ['TMPDIR'] = str(tmpdir)
|
||||
+ result = script.pip(
|
||||
+ 'wheel', data.src / 'extension',
|
||||
+ '--no-index', '-f', common_wheels
|
||||
+ )
|
||||
+ assert "Successfully built extension" in result.stdout, result.stdout
|
||||
+
|
||||
+
|
||||
@pytest.mark.network
|
||||
def test_pep517_wheels_are_not_confused_with_other_files(script, tmpdir, data):
|
||||
"""Check correct wheels are copied. (#6196)
|
||||
|
||||
From eb070d23721c5a0bff59ed5a252291efd3f5a7c6 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||||
Date: Thu, 19 Mar 2020 23:21:56 +0100
|
||||
Subject: [PATCH 2/2] Avoid a test dependency on a C compiler, skip the test on
|
||||
Windows
|
||||
|
||||
---
|
||||
tests/functional/test_wheel.py | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
diff --git a/tests/functional/test_wheel.py b/tests/functional/test_wheel.py
|
||||
index f293233b9d..545c50ac9a 100644
|
||||
--- a/tests/functional/test_wheel.py
|
||||
+++ b/tests/functional/test_wheel.py
|
||||
@@ -1,6 +1,7 @@
|
||||
"""'pip wheel' tests"""
|
||||
import os
|
||||
import re
|
||||
+import sys
|
||||
from os.path import exists
|
||||
|
||||
import pytest
|
||||
@@ -289,10 +290,17 @@ def test_pip_wheel_with_user_set_in_config(script, data, common_wheels):
|
||||
assert "Successfully built withpyproject" in result.stdout, result.stdout
|
||||
|
||||
|
||||
+@pytest.mark.skipif(sys.platform.startswith('win'),
|
||||
+ reason='The empty extension module does not work on Win')
|
||||
def test_pip_wheel_ext_module_with_tmpdir_inside(script, data, common_wheels):
|
||||
tmpdir = data.src / 'extension/tmp'
|
||||
tmpdir.mkdir()
|
||||
script.environ['TMPDIR'] = str(tmpdir)
|
||||
+
|
||||
+ # To avoid a test dependency on a C compiler, we set the env vars to "noop"
|
||||
+ # The .c source is empty anyway
|
||||
+ script.environ['CC'] = script.environ['LDSHARED'] = str('true')
|
||||
+
|
||||
result = script.pip(
|
||||
'wheel', data.src / 'extension',
|
||||
'--no-index', '-f', common_wheels
|
@ -16,7 +16,7 @@ Name: python-%{srcname}
|
||||
# When updating, update the bundled libraries versions bellow!
|
||||
# You can use vendor_meta.sh in the dist git repo
|
||||
Version: 20.0.2
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
Summary: A tool for installing and managing Python packages
|
||||
|
||||
# We bundle a lot of libraries with pip, which itself is under MIT license.
|
||||
@ -94,6 +94,11 @@ Patch4: dummy-certifi.patch
|
||||
# this warning is juts moot. Also, the warning breaks CPython test suite.
|
||||
Patch5: nowarn-pip._internal.main.patch
|
||||
|
||||
# Allow setting $TMPDIR to $PWD/... during pip wheel
|
||||
# This is needed to have proper debugsource packages with pyproject-rpm-macros
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1806625
|
||||
Patch6: https://github.com/pypa/pip/pull/7873.patch
|
||||
|
||||
# Downstream only patch
|
||||
# Users might have local installations of pip from using
|
||||
# `pip install --user --upgrade pip` on older/newer versions.
|
||||
@ -253,6 +258,7 @@ popd
|
||||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
%patch5 -p1
|
||||
%patch6 -p1
|
||||
|
||||
# this goes together with patch4
|
||||
rm src/pip/_vendor/certifi/*.pem
|
||||
@ -379,6 +385,9 @@ ln -sf %{buildroot}%{_bindir}/pip3 _bin/pip
|
||||
%{python_wheeldir}/%{python_wheelname}
|
||||
|
||||
%changelog
|
||||
* Fri Apr 10 2020 Miro Hrončok <mhroncok@redhat.com> - 20.0.2-3
|
||||
- Allow setting $TMPDIR to $PWD/... during pip wheel (#1806625)
|
||||
|
||||
* Tue Mar 10 2020 Miro Hrončok <mhroncok@redhat.com> - 20.0.2-2
|
||||
- Don't warn the user about pip._internal.main() entrypoint to fix ensurepip
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user