Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
521ed521
Commit
521ed521
authored
May 12, 2013
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes issue #17732: ignore install-directory specific options in
distutils.cfg when a venv is active.
parent
b3bd624a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
3 deletions
+87
-3
Doc/install/index.rst
Doc/install/index.rst
+5
-0
Doc/library/venv.rst
Doc/library/venv.rst
+4
-0
Lib/distutils/dist.py
Lib/distutils/dist.py
+13
-1
Lib/distutils/tests/test_dist.py
Lib/distutils/tests/test_dist.py
+62
-2
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Doc/install/index.rst
View file @
521ed521
...
...
@@ -645,6 +645,11 @@ environment variables, such as Mac OS 9, the configuration variables supplied by
the Distutils are the only ones you can use.) See section :ref:`inst-config-files`
for details.
.. note:: When a :ref:`virtual environment <venv-def>` is activated, any options
that change the installation path will be ignored from all distutils configuration
files to prevent inadvertently installing projects outside of the virtual
environment.
.. XXX need some Windows examples---when would custom installation schemes be
needed on those platforms?
...
...
Doc/library/venv.rst
View file @
521ed521
...
...
@@ -57,6 +57,10 @@ Creating virtual environments
:attr:`sys.exec_prefix` is the same as :attr:`sys.base_exec_prefix` (they
all point to a non-venv Python installation).
When a venv is active, any options that change the installation path will be
ignored from all distutils configuration files to prevent projects being
inadvertently installed outside of the virtual environment.
API
---
...
...
Lib/distutils/dist.py
View file @
521ed521
...
...
@@ -343,6 +343,18 @@ Common commands: (see '--help-commands' for more)
def
parse_config_files
(
self
,
filenames
=
None
):
from
configparser
import
ConfigParser
# Ignore install directory options if we have a venv
if
sys
.
prefix
!=
sys
.
base_prefix
:
ignore_options
=
[
'install-base'
,
'install-platbase'
,
'install-lib'
,
'install-platlib'
,
'install-purelib'
,
'install-headers'
,
'install-scripts'
,
'install-data'
,
'prefix'
,
'exec-prefix'
,
'home'
,
'user'
,
'root'
]
else
:
ignore_options
=
[]
ignore_options
=
frozenset
(
ignore_options
)
if
filenames
is
None
:
filenames
=
self
.
find_config_files
()
...
...
@@ -359,7 +371,7 @@ Common commands: (see '--help-commands' for more)
opt_dict
=
self
.
get_option_dict
(
section
)
for
opt
in
options
:
if
opt
!=
'__name__'
:
if
opt
!=
'__name__'
and
opt
not
in
ignore_options
:
val
=
parser
.
get
(
section
,
opt
)
opt
=
opt
.
replace
(
'-'
,
'_'
)
opt_dict
[
opt
]
=
(
filename
,
val
)
...
...
Lib/distutils/tests/test_dist.py
View file @
521ed521
...
...
@@ -6,6 +6,8 @@ import unittest
import
warnings
import
textwrap
from
unittest
import
mock
from
distutils.dist
import
Distribution
,
fix_help_options
from
distutils.cmd
import
Command
...
...
@@ -18,7 +20,7 @@ class test_dist(Command):
user_options
=
[
(
"sample-option="
,
"S"
,
"help text"
),
]
]
def
initialize_options
(
self
):
self
.
sample_option
=
None
...
...
@@ -77,6 +79,64 @@ class DistributionTestCase(support.LoggingSilencer,
self
.
assertIsInstance
(
cmd
,
test_dist
)
self
.
assertEqual
(
cmd
.
sample_option
,
"sometext"
)
def
test_venv_install_options
(
self
):
sys
.
argv
.
append
(
"install"
)
self
.
addCleanup
(
os
.
unlink
,
TESTFN
)
fakepath
=
'/somedir'
with
open
(
TESTFN
,
"w"
)
as
f
:
print
((
"[install]
\
n
"
"install-base = {0}
\
n
"
"install-platbase = {0}
\
n
"
"install-lib = {0}
\
n
"
"install-platlib = {0}
\
n
"
"install-purelib = {0}
\
n
"
"install-headers = {0}
\
n
"
"install-scripts = {0}
\
n
"
"install-data = {0}
\
n
"
"prefix = {0}
\
n
"
"exec-prefix = {0}
\
n
"
"home = {0}
\
n
"
"user = {0}
\
n
"
"root = {0}"
).
format
(
fakepath
),
file
=
f
)
# Base case: Not in a Virtual Environment
with
mock
.
patch
.
multiple
(
sys
,
prefix
=
'/a'
,
base_prefix
=
'/a'
)
as
values
:
d
=
self
.
create_distribution
([
TESTFN
])
option_tuple
=
(
TESTFN
,
fakepath
)
result_dict
=
{
'install_base'
:
option_tuple
,
'install_platbase'
:
option_tuple
,
'install_lib'
:
option_tuple
,
'install_platlib'
:
option_tuple
,
'install_purelib'
:
option_tuple
,
'install_headers'
:
option_tuple
,
'install_scripts'
:
option_tuple
,
'install_data'
:
option_tuple
,
'prefix'
:
option_tuple
,
'exec_prefix'
:
option_tuple
,
'home'
:
option_tuple
,
'user'
:
option_tuple
,
'root'
:
option_tuple
,
}
self
.
assertEqual
(
sorted
(
d
.
command_options
.
get
(
'install'
).
keys
()),
sorted
(
result_dict
.
keys
()))
for
(
key
,
value
)
in
d
.
command_options
.
get
(
'install'
).
items
():
self
.
assertEqual
(
value
,
result_dict
[
key
])
# Test case: In a Virtual Environment
with
mock
.
patch
.
multiple
(
sys
,
prefix
=
'/a'
,
base_prefix
=
'/b'
)
as
values
:
d
=
self
.
create_distribution
([
TESTFN
])
for
key
in
result_dict
.
keys
():
self
.
assertNotIn
(
key
,
d
.
command_options
.
get
(
'install'
,
{}))
def
test_command_packages_configfile
(
self
):
sys
.
argv
.
append
(
"build"
)
self
.
addCleanup
(
os
.
unlink
,
TESTFN
)
...
...
@@ -304,7 +364,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
os
.
environ
[
'HOME'
]
=
temp_dir
files
=
dist
.
find_config_files
()
self
.
assertIn
(
user_filename
,
files
,
'%r not found in %r'
%
(
user_filename
,
files
))
'%r not found in %r'
%
(
user_filename
,
files
))
finally
:
os
.
remove
(
user_filename
)
...
...
Misc/NEWS
View file @
521ed521
...
...
@@ -49,6 +49,9 @@ Core and Builtins
Library
-------
- Issue #17732: Ignore distutils.cfg options pertaining to install paths if a
virtual environment is active.
- Issue #1159051: Back out a fix for handling corrupted gzip files that
broke backwards compatibility.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment