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
6eccf926
Unverified
Commit
6eccf926
authored
Apr 22, 2023
by
David Hotham
Committed by
GitHub
Apr 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clarify use of subprocess.call() (#7812)
parent
bc6e84e3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
17 deletions
+19
-17
src/poetry/utils/env.py
+10
-9
src/poetry/utils/pip.py
+1
-1
tests/puzzle/test_provider.py
+1
-1
tests/utils/test_env.py
+7
-6
No files found.
src/poetry/utils/env.py
View file @
6eccf926
...
@@ -1499,16 +1499,16 @@ class Env:
...
@@ -1499,16 +1499,16 @@ class Env:
return
[
str
(
self
.
_bin
(
bin
))]
return
[
str
(
self
.
_bin
(
bin
))]
def
run
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
str
|
int
:
def
run
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
str
:
cmd
=
self
.
get_command_from_bin
(
bin
)
+
list
(
args
)
cmd
=
self
.
get_command_from_bin
(
bin
)
+
list
(
args
)
return
self
.
_run
(
cmd
,
**
kwargs
)
return
self
.
_run
(
cmd
,
**
kwargs
)
def
run_pip
(
self
,
*
args
:
str
,
**
kwargs
:
Any
)
->
int
|
str
:
def
run_pip
(
self
,
*
args
:
str
,
**
kwargs
:
Any
)
->
str
:
pip
=
self
.
get_pip_command
()
pip
=
self
.
get_pip_command
()
cmd
=
pip
+
list
(
args
)
cmd
=
pip
+
list
(
args
)
return
self
.
_run
(
cmd
,
**
kwargs
)
return
self
.
_run
(
cmd
,
**
kwargs
)
def
run_python_script
(
self
,
content
:
str
,
**
kwargs
:
Any
)
->
int
|
str
:
def
run_python_script
(
self
,
content
:
str
,
**
kwargs
:
Any
)
->
str
:
return
self
.
run
(
return
self
.
run
(
self
.
_executable
,
self
.
_executable
,
"-I"
,
"-I"
,
...
@@ -1520,7 +1520,7 @@ class Env:
...
@@ -1520,7 +1520,7 @@ class Env:
**
kwargs
,
**
kwargs
,
)
)
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
int
|
str
:
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
str
:
"""
"""
Run a command inside the Python environment.
Run a command inside the Python environment.
"""
"""
...
@@ -1542,7 +1542,8 @@ class Env:
...
@@ -1542,7 +1542,8 @@ class Env:
)
.
stdout
)
.
stdout
elif
call
:
elif
call
:
assert
stderr
!=
subprocess
.
PIPE
assert
stderr
!=
subprocess
.
PIPE
return
subprocess
.
call
(
cmd
,
stderr
=
stderr
,
env
=
env
,
**
kwargs
)
subprocess
.
check_call
(
cmd
,
stderr
=
stderr
,
env
=
env
,
**
kwargs
)
output
=
""
else
:
else
:
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
stderr
,
env
=
env
,
**
kwargs
)
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
stderr
,
env
=
env
,
**
kwargs
)
except
CalledProcessError
as
e
:
except
CalledProcessError
as
e
:
...
@@ -1780,7 +1781,7 @@ class VirtualEnv(Env):
...
@@ -1780,7 +1781,7 @@ class VirtualEnv(Env):
# A virtualenv is considered sane if "python" exists.
# A virtualenv is considered sane if "python" exists.
return
os
.
path
.
exists
(
self
.
python
)
return
os
.
path
.
exists
(
self
.
python
)
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
int
|
str
:
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
str
:
kwargs
[
"env"
]
=
self
.
get_temp_environ
(
environ
=
kwargs
.
get
(
"env"
))
kwargs
[
"env"
]
=
self
.
get_temp_environ
(
environ
=
kwargs
.
get
(
"env"
))
return
super
()
.
_run
(
cmd
,
**
kwargs
)
return
super
()
.
_run
(
cmd
,
**
kwargs
)
...
@@ -1902,7 +1903,7 @@ class GenericEnv(VirtualEnv):
...
@@ -1902,7 +1903,7 @@ class GenericEnv(VirtualEnv):
return
exe
.
returncode
return
exe
.
returncode
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
int
|
str
:
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
str
:
return
super
(
VirtualEnv
,
self
)
.
_run
(
cmd
,
**
kwargs
)
return
super
(
VirtualEnv
,
self
)
.
_run
(
cmd
,
**
kwargs
)
def
is_venv
(
self
)
->
bool
:
def
is_venv
(
self
)
->
bool
:
...
@@ -1932,12 +1933,12 @@ class NullEnv(SystemEnv):
...
@@ -1932,12 +1933,12 @@ class NullEnv(SystemEnv):
return
self
.
_paths
return
self
.
_paths
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
int
|
str
:
def
_run
(
self
,
cmd
:
list
[
str
],
**
kwargs
:
Any
)
->
str
:
self
.
executed
.
append
(
cmd
)
self
.
executed
.
append
(
cmd
)
if
self
.
_execute
:
if
self
.
_execute
:
return
super
()
.
_run
(
cmd
,
**
kwargs
)
return
super
()
.
_run
(
cmd
,
**
kwargs
)
return
0
return
""
def
execute
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
int
:
def
execute
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
int
:
self
.
executed
.
append
([
bin
]
+
list
(
args
))
self
.
executed
.
append
([
bin
]
+
list
(
args
))
...
...
src/poetry/utils/pip.py
View file @
6eccf926
...
@@ -18,7 +18,7 @@ def pip_install(
...
@@ -18,7 +18,7 @@ def pip_install(
editable
:
bool
=
False
,
editable
:
bool
=
False
,
deps
:
bool
=
False
,
deps
:
bool
=
False
,
upgrade
:
bool
=
False
,
upgrade
:
bool
=
False
,
)
->
int
|
str
:
)
->
str
:
is_wheel
=
path
.
suffix
==
".whl"
is_wheel
=
path
.
suffix
==
".whl"
# We disable version check here as we are already pinning to version available in
# We disable version check here as we are already pinning to version available in
...
...
tests/puzzle/test_provider.py
View file @
6eccf926
...
@@ -36,7 +36,7 @@ SOME_URL = "https://example.com/path.tar.gz"
...
@@ -36,7 +36,7 @@ SOME_URL = "https://example.com/path.tar.gz"
class
MockEnv
(
BaseMockEnv
):
class
MockEnv
(
BaseMockEnv
):
def
run
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
str
|
int
:
def
run
(
self
,
bin
:
str
,
*
args
:
str
,
**
kwargs
:
Any
)
->
str
:
raise
EnvCommandError
(
CalledProcessError
(
1
,
"python"
,
output
=
""
))
raise
EnvCommandError
(
CalledProcessError
(
1
,
"python"
,
output
=
""
))
...
...
tests/utils/test_env.py
View file @
6eccf926
...
@@ -966,11 +966,11 @@ def test_call_with_input_and_keyboard_interrupt(
...
@@ -966,11 +966,11 @@ def test_call_with_input_and_keyboard_interrupt(
def
test_call_no_input_with_keyboard_interrupt
(
def
test_call_no_input_with_keyboard_interrupt
(
tmp_path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
"subprocess.call"
,
side_effect
=
KeyboardInterrupt
())
mocker
.
patch
(
"subprocess.c
heck_c
all"
,
side_effect
=
KeyboardInterrupt
())
kwargs
=
{
"call"
:
True
}
kwargs
=
{
"call"
:
True
}
with
pytest
.
raises
(
KeyboardInterrupt
):
with
pytest
.
raises
(
KeyboardInterrupt
):
tmp_venv
.
run
(
"python"
,
"-"
,
**
kwargs
)
tmp_venv
.
run
(
"python"
,
"-"
,
**
kwargs
)
subprocess
.
call
.
assert_called_once
()
subprocess
.
c
heck_c
all
.
assert_called_once
()
def
test_run_with_called_process_error
(
def
test_run_with_called_process_error
(
...
@@ -1010,7 +1010,7 @@ def test_call_no_input_with_called_process_error(
...
@@ -1010,7 +1010,7 @@ def test_call_no_input_with_called_process_error(
tmp_path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
tmp_path
:
Path
,
tmp_venv
:
VirtualEnv
,
mocker
:
MockerFixture
)
->
None
:
)
->
None
:
mocker
.
patch
(
mocker
.
patch
(
"subprocess.call"
,
"subprocess.c
heck_c
all"
,
side_effect
=
subprocess
.
CalledProcessError
(
side_effect
=
subprocess
.
CalledProcessError
(
42
,
"some_command"
,
"some output"
,
"some error"
42
,
"some_command"
,
"some output"
,
"some error"
),
),
...
@@ -1018,7 +1018,7 @@ def test_call_no_input_with_called_process_error(
...
@@ -1018,7 +1018,7 @@ def test_call_no_input_with_called_process_error(
kwargs
=
{
"call"
:
True
}
kwargs
=
{
"call"
:
True
}
with
pytest
.
raises
(
EnvCommandError
)
as
error
:
with
pytest
.
raises
(
EnvCommandError
)
as
error
:
tmp_venv
.
run
(
"python"
,
"-"
,
**
kwargs
)
tmp_venv
.
run
(
"python"
,
"-"
,
**
kwargs
)
subprocess
.
call
.
assert_called_once
()
subprocess
.
c
heck_c
all
.
assert_called_once
()
assert
"some output"
in
str
(
error
.
value
)
assert
"some output"
in
str
(
error
.
value
)
assert
"some error"
in
str
(
error
.
value
)
assert
"some error"
in
str
(
error
.
value
)
...
@@ -1054,9 +1054,10 @@ for i in range(10000):
...
@@ -1054,9 +1054,10 @@ for i in range(10000):
)
)
def
target
(
result
:
list
[
int
])
->
None
:
def
target
(
result
:
list
[
int
])
->
None
:
result
.
append
(
tmp_venv
.
run
(
"python"
,
str
(
script
),
call
=
True
))
tmp_venv
.
run
(
"python"
,
str
(
script
),
call
=
True
)
result
.
append
(
0
)
results
=
[]
results
:
list
[
int
]
=
[]
# use a separate thread, so that the test does not block in case of error
# use a separate thread, so that the test does not block in case of error
thread
=
Thread
(
target
=
target
,
args
=
(
results
,))
thread
=
Thread
(
target
=
target
,
args
=
(
results
,))
thread
.
start
()
thread
.
start
()
...
...
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