Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
e0156477
Commit
e0156477
authored
Nov 20, 2019
by
K900
Committed by
Sébastien Eustace
Nov 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commonize pip running logic and use system pip in system env (#861)
parent
c05948a7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
16 deletions
+36
-16
poetry/installation/pip_installer.py
+1
-1
poetry/masonry/builders/editable.py
+2
-4
poetry/utils/env.py
+29
-9
tests/masonry/builders/test_editable.py
+4
-2
No files found.
poetry/installation/pip_installer.py
View file @
e0156477
...
...
@@ -115,7 +115,7 @@ class PipInstaller(BaseInstaller):
raise
def
run
(
self
,
*
args
,
**
kwargs
):
# type: (...) -> str
return
self
.
_env
.
run
(
"python"
,
"-m"
,
"pip"
,
*
args
,
**
kwargs
)
return
self
.
_env
.
run
_pip
(
*
args
,
**
kwargs
)
def
requirement
(
self
,
package
,
formatted
=
False
):
if
formatted
and
not
package
.
source_type
:
...
...
poetry/masonry/builders/editable.py
View file @
e0156477
...
...
@@ -31,16 +31,14 @@ class EditableBuilder(Builder):
try
:
if
self
.
_env
.
pip_version
<
Version
(
19
,
0
):
self
.
_env
.
run
(
"python"
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
self
.
_path
))
self
.
_env
.
run
_pip
(
"install"
,
"-e"
,
str
(
self
.
_path
))
else
:
# Temporarily rename pyproject.toml
shutil
.
move
(
str
(
self
.
_poetry
.
file
),
str
(
self
.
_poetry
.
file
.
with_suffix
(
".tmp"
))
)
try
:
self
.
_env
.
run
(
"python"
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
self
.
_path
)
)
self
.
_env
.
run_pip
(
"install"
,
"-e"
,
str
(
self
.
_path
))
finally
:
shutil
.
move
(
str
(
self
.
_poetry
.
file
.
with_suffix
(
".tmp"
)),
...
...
poetry/utils/env.py
View file @
e0156477
...
...
@@ -772,6 +772,9 @@ class Env(object):
def
get_marker_env
(
self
):
# type: () -> Dict[str, Any]
raise
NotImplementedError
()
def
get_pip_command
(
self
):
# type: () -> List[str]
raise
NotImplementedError
()
def
config_var
(
self
,
var
):
# type: (str) -> Any
raise
NotImplementedError
()
...
...
@@ -788,12 +791,19 @@ class Env(object):
return
True
def
run
(
self
,
bin
,
*
args
,
**
kwargs
):
bin
=
self
.
_bin
(
bin
)
cmd
=
[
bin
]
+
list
(
args
)
return
self
.
_run
(
cmd
,
**
kwargs
)
def
run_pip
(
self
,
*
args
,
**
kwargs
):
pip
=
self
.
get_pip_command
()
cmd
=
pip
+
list
(
args
)
return
self
.
_run
(
cmd
,
**
kwargs
)
def
_run
(
self
,
cmd
,
**
kwargs
):
"""
Run a command inside the Python environment.
"""
bin
=
self
.
_bin
(
bin
)
cmd
=
[
bin
]
+
list
(
args
)
shell
=
kwargs
.
get
(
"shell"
,
False
)
call
=
kwargs
.
pop
(
"call"
,
False
)
input_
=
kwargs
.
pop
(
"input_"
,
None
)
...
...
@@ -886,6 +896,11 @@ class SystemEnv(Env):
def
get_python_implementation
(
self
):
# type: () -> str
return
platform
.
python_implementation
()
def
get_pip_command
(
self
):
# type: () -> List[str]
# If we're not in a venv, assume the interpreter we're running on
# has a pip and use that
return
[
sys
.
executable
,
"-m"
,
"pip"
]
def
get_marker_env
(
self
):
# type: () -> Dict[str, Any]
if
hasattr
(
sys
,
"implementation"
):
info
=
sys
.
implementation
.
version
...
...
@@ -960,6 +975,11 @@ class VirtualEnv(Env):
def
get_python_implementation
(
self
):
# type: () -> str
return
self
.
marker_env
[
"platform_python_implementation"
]
def
get_pip_command
(
self
):
# type: () -> List[str]
# We're in a virtualenv that is known to be sane,
# so assume that we have a functional pip
return
[
self
.
_bin
(
"pip"
)]
def
get_marker_env
(
self
):
# type: () -> Dict[str, Any]
output
=
self
.
run
(
"python"
,
"-"
,
input_
=
GET_ENVIRONMENT_INFO
)
...
...
@@ -984,7 +1004,7 @@ class VirtualEnv(Env):
return
value
def
get_pip_version
(
self
):
# type: () -> Version
output
=
self
.
run
(
"python"
,
"-m"
,
"pip"
,
"--version"
)
.
strip
()
output
=
self
.
run
_pip
(
"--version"
)
.
strip
()
m
=
re
.
match
(
"pip (.+?)(?: from .+)?$"
,
output
)
if
not
m
:
return
Version
.
parse
(
"0.0"
)
...
...
@@ -998,7 +1018,7 @@ class VirtualEnv(Env):
# A virtualenv is considered sane if both "python" and "pip" exist.
return
os
.
path
.
exists
(
self
.
_bin
(
"python"
))
and
os
.
path
.
exists
(
self
.
_bin
(
"pip"
))
def
run
(
self
,
bin
,
*
args
,
**
kwargs
):
def
_run
(
self
,
cmd
,
**
kwargs
):
with
self
.
temp_environ
():
os
.
environ
[
"PATH"
]
=
self
.
_updated_path
()
os
.
environ
[
"VIRTUAL_ENV"
]
=
str
(
self
.
_path
)
...
...
@@ -1006,7 +1026,7 @@ class VirtualEnv(Env):
self
.
unset_env
(
"PYTHONHOME"
)
self
.
unset_env
(
"__PYVENV_LAUNCHER__"
)
return
super
(
VirtualEnv
,
self
)
.
run
(
bin
,
*
args
,
**
kwargs
)
return
super
(
VirtualEnv
,
self
)
.
_run
(
cmd
,
**
kwargs
)
def
execute
(
self
,
bin
,
*
args
,
**
kwargs
):
with
self
.
temp_environ
():
...
...
@@ -1045,11 +1065,11 @@ class NullEnv(SystemEnv):
self
.
_execute
=
execute
self
.
executed
=
[]
def
run
(
self
,
bin
,
*
args
,
**
kwargs
):
self
.
executed
.
append
(
[
bin
]
+
list
(
args
)
)
def
_run
(
self
,
cmd
,
**
kwargs
):
self
.
executed
.
append
(
cmd
)
if
self
.
_execute
:
return
super
(
NullEnv
,
self
)
.
run
(
bin
,
*
args
,
**
kwargs
)
return
super
(
NullEnv
,
self
)
.
_run
(
cmd
,
**
kwargs
)
def
execute
(
self
,
bin
,
*
args
,
**
kwargs
):
self
.
executed
.
append
([
bin
]
+
list
(
args
))
...
...
tests/masonry/builders/test_editable.py
View file @
e0156477
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
sys
from
clikit.io
import
NullIO
from
poetry.factory
import
Factory
...
...
@@ -22,7 +24,7 @@ def test_build_should_delegate_to_pip_for_non_pure_python_packages(tmp_dir, mock
builder
=
EditableBuilder
(
Factory
()
.
create_poetry
(
module_path
),
env
,
NullIO
())
builder
.
build
()
expected
=
[[
"python"
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
module_path
)]]
expected
=
[[
sys
.
executable
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
module_path
)]]
assert
expected
==
env
.
executed
assert
0
==
move
.
call_count
...
...
@@ -38,7 +40,7 @@ def test_build_should_temporarily_remove_the_pyproject_file(tmp_dir, mocker):
builder
=
EditableBuilder
(
Factory
()
.
create_poetry
(
module_path
),
env
,
NullIO
())
builder
.
build
()
expected
=
[[
"python"
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
module_path
)]]
expected
=
[[
sys
.
executable
,
"-m"
,
"pip"
,
"install"
,
"-e"
,
str
(
module_path
)]]
assert
expected
==
env
.
executed
assert
2
==
move
.
call_count
...
...
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