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
58dbca46
Unverified
Commit
58dbca46
authored
Nov 16, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix errors for virtualenvs with spaces in their path
parent
aca69a14
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
125 additions
and
67 deletions
+125
-67
CHANGELOG.md
+1
-0
poetry/utils/_compat.py
+19
-0
poetry/utils/env.py
+83
-54
tests/conftest.py
+9
-0
tests/console/commands/test_init.py
+0
-13
tests/utils/test_env.py
+13
-0
No files found.
CHANGELOG.md
View file @
58dbca46
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
-
Fixed executables from outside the virtualenv not being accessible.
-
Fixed executables from outside the virtualenv not being accessible.
-
Fixed a possible error when building distributions with the
`exclude`
option.
-
Fixed a possible error when building distributions with the
`exclude`
option.
-
Fixed the
`run`
command for namespaced packages.
-
Fixed the
`run`
command for namespaced packages.
-
Fixed errors for virtualenvs with spaces in their path.
## [0.12.8] - 2018-11-13
## [0.12.8] - 2018-11-13
...
...
poetry/utils/_compat.py
View file @
58dbca46
import
subprocess
import
sys
import
sys
try
:
try
:
...
@@ -19,6 +20,17 @@ PY2 = sys.version_info[0] == 2
...
@@ -19,6 +20,17 @@ PY2 = sys.version_info[0] == 2
PY35
=
sys
.
version_info
>=
(
3
,
5
)
PY35
=
sys
.
version_info
>=
(
3
,
5
)
PY36
=
sys
.
version_info
>=
(
3
,
6
)
PY36
=
sys
.
version_info
>=
(
3
,
6
)
WINDOWS
=
sys
.
platform
==
"win32"
if
PY2
:
import
pipes
shell_quote
=
pipes
.
quote
else
:
import
shlex
shell_quote
=
shlex
.
quote
if
PY35
:
if
PY35
:
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -80,3 +92,10 @@ def to_str(string):
...
@@ -80,3 +92,10 @@ def to_str(string):
pass
pass
return
getattr
(
string
,
method
)(
encodings
[
0
],
errors
=
"ignore"
)
return
getattr
(
string
,
method
)(
encodings
[
0
],
errors
=
"ignore"
)
def
list_to_shell_command
(
cmd
):
if
not
WINDOWS
:
cmd
=
[
cmd
[
0
]]
+
[
shell_quote
(
a
)
for
a
in
cmd
[
1
:]]
return
subprocess
.
list2cmdline
(
cmd
)
poetry/utils/env.py
View file @
58dbca46
...
@@ -17,9 +17,72 @@ from poetry.config import Config
...
@@ -17,9 +17,72 @@ from poetry.config import Config
from
poetry.locations
import
CACHE_DIR
from
poetry.locations
import
CACHE_DIR
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
decode
from
poetry.utils._compat
import
decode
from
poetry.utils._compat
import
encode
from
poetry.utils._compat
import
list_to_shell_command
from
poetry.version.markers
import
BaseMarker
from
poetry.version.markers
import
BaseMarker
GET_ENVIRONMENT_INFO
=
"""
\
import json
import os
import platform
import sys
if hasattr(sys, "implementation"):
info = sys.implementation.version
iver = "{0.major}.{0.minor}.{0.micro}".format(info)
kind = info.releaselevel
if kind != "final":
iver += kind[0] + str(info.serial)
implementation_name = sys.implementation.name
else:
iver = "0"
implementation_name = ""
env = {
"implementation_name": implementation_name,
"implementation_version": iver,
"os_name": os.name,
"platform_machine": platform.machine(),
"platform_release": platform.release(),
"platform_system": platform.system(),
"platform_version": platform.version(),
"python_full_version": platform.python_version(),
"platform_python_implementation": platform.python_implementation(),
"python_version": platform.python_version()[:3],
"sys_platform": sys.platform,
"version_info": tuple(sys.version_info),
}
print(json.dumps(env))
"""
GET_BASE_PREFIX
=
"""
\
import sys
if hasattr(sys, "real_prefix"):
print(sys.real_prefix)
elif hasattr(sys, "base_prefix"):
print(sys.base_prefix)
else:
print(sys.prefix)
"""
GET_CONFIG_VAR
=
"""
\
import sysconfig
print(sysconfig.get_config_var("{config_var}")),
"""
GET_PYTHON_VERSION
=
"""
\
import sys
print('.'.join([str(s) for s in sys.version_info[:3]]))
"""
class
EnvError
(
Exception
):
class
EnvError
(
Exception
):
pass
pass
...
@@ -272,18 +335,30 @@ class Env(object):
...
@@ -272,18 +335,30 @@ class Env(object):
cmd
=
[
bin
]
+
list
(
args
)
cmd
=
[
bin
]
+
list
(
args
)
shell
=
kwargs
.
get
(
"shell"
,
False
)
shell
=
kwargs
.
get
(
"shell"
,
False
)
call
=
kwargs
.
pop
(
"call"
,
False
)
call
=
kwargs
.
pop
(
"call"
,
False
)
input_
=
kwargs
.
pop
(
"input_"
,
None
)
if
shell
:
if
shell
:
cmd
=
" "
.
join
(
cmd
)
cmd
=
list_to_shell_command
(
cmd
)
try
:
try
:
if
self
.
_is_windows
:
if
self
.
_is_windows
:
kwargs
[
"shell"
]
=
True
kwargs
[
"shell"
]
=
True
if
call
:
if
input_
:
p
=
subprocess
.
Popen
(
cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
output
=
p
.
communicate
(
encode
(
input_
))[
0
]
elif
call
:
return
subprocess
.
call
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
return
subprocess
.
call
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
else
:
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
except
CalledProcessError
as
e
:
except
CalledProcessError
as
e
:
raise
EnvCommandError
(
e
)
raise
EnvCommandError
(
e
)
...
@@ -375,29 +450,10 @@ class VirtualEnv(Env):
...
@@ -375,29 +450,10 @@ class VirtualEnv(Env):
# In this case we need to get sys.base_prefix
# In this case we need to get sys.base_prefix
# from inside the virtualenv.
# from inside the virtualenv.
if
base
is
None
:
if
base
is
None
:
self
.
_base
=
Path
(
self
.
_base
=
Path
(
self
.
run
(
"python"
,
"-"
,
input_
=
GET_BASE_PREFIX
)
.
strip
())
self
.
run
(
"python"
,
"-c"
,
'"import sys; '
"print("
" getattr("
" sys,"
" 'real_prefix', "
" getattr(sys, 'base_prefix', sys.prefix)"
" )"
')"'
,
shell
=
True
,
)
.
strip
()
)
def
get_version_info
(
self
):
# type: () -> Tuple[int]
def
get_version_info
(
self
):
# type: () -> Tuple[int]
output
=
self
.
run
(
output
=
self
.
run
(
"python"
,
"-"
,
input_
=
GET_PYTHON_VERSION
)
"python"
,
"-c"
,
"
\"
import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))
\"
"
,
shell
=
True
,
)
return
tuple
([
int
(
s
)
for
s
in
output
.
strip
()
.
split
(
"."
)])
return
tuple
([
int
(
s
)
for
s
in
output
.
strip
()
.
split
(
"."
)])
...
@@ -405,41 +461,14 @@ class VirtualEnv(Env):
...
@@ -405,41 +461,14 @@ class VirtualEnv(Env):
return
self
.
marker_env
[
"platform_python_implementation"
]
return
self
.
marker_env
[
"platform_python_implementation"
]
def
get_marker_env
(
self
):
# type: () -> Dict[str, Any]
def
get_marker_env
(
self
):
# type: () -> Dict[str, Any]
output
=
self
.
run
(
output
=
self
.
run
(
"python"
,
"-"
,
input_
=
GET_ENVIRONMENT_INFO
)
"python"
,
"-c"
,
'"import json; import os; import platform; import sys; '
"implementation = getattr(sys, 'implementation', None); "
"iver = '{0.major}.{0.minor}.{0.micro}'.format(implementation.version) if implementation else '0'; "
"implementation_name = implementation.name if implementation else ''; "
"env = {"
"'implementation_name': implementation_name,"
"'implementation_version': iver,"
"'os_name': os.name,"
"'platform_machine': platform.machine(),"
"'platform_release': platform.release(),"
"'platform_system': platform.system(),"
"'platform_version': platform.version(),"
"'python_full_version': platform.python_version(),"
"'platform_python_implementation': platform.python_implementation(),"
"'python_version': platform.python_version()[:3],"
"'sys_platform': sys.platform,"
"'version_info': sys.version_info[:3],"
"};"
'print(json.dumps(env))"'
,
shell
=
True
,
)
return
json
.
loads
(
output
)
return
json
.
loads
(
output
)
def
config_var
(
self
,
var
):
# type: (str) -> Any
def
config_var
(
self
,
var
):
# type: (str) -> Any
try
:
try
:
value
=
self
.
run
(
value
=
self
.
run
(
"python"
,
"python"
,
"-"
,
input_
=
GET_CONFIG_VAR
.
format
(
config_var
=
var
)
"-c"
,
'"import sysconfig; '
"print(sysconfig.get_config_var('{}'))
\"
"
.
format
(
var
),
shell
=
True
,
)
.
strip
()
)
.
strip
()
except
EnvCommandError
as
e
:
except
EnvCommandError
as
e
:
warnings
.
warn
(
"{0}"
.
format
(
e
),
RuntimeWarning
)
warnings
.
warn
(
"{0}"
.
format
(
e
),
RuntimeWarning
)
...
...
tests/conftest.py
View file @
58dbca46
...
@@ -13,6 +13,15 @@ from poetry.utils.toml_file import TomlFile
...
@@ -13,6 +13,15 @@ from poetry.utils.toml_file import TomlFile
@pytest.fixture
@pytest.fixture
def
tmp_dir
():
dir_
=
tempfile
.
mkdtemp
(
prefix
=
"poetry_"
)
yield
dir_
shutil
.
rmtree
(
dir_
)
@pytest.fixture
def
config
():
# type: () -> Config
def
config
():
# type: () -> Config
with
tempfile
.
NamedTemporaryFile
()
as
f
:
with
tempfile
.
NamedTemporaryFile
()
as
f
:
f
.
close
()
f
.
close
()
...
...
tests/console/commands/test_init.py
View file @
58dbca46
import
pytest
import
shutil
import
tempfile
from
cleo.testers
import
CommandTester
from
cleo.testers
import
CommandTester
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
Path
...
@@ -9,15 +5,6 @@ from poetry.utils._compat import Path
...
@@ -9,15 +5,6 @@ from poetry.utils._compat import Path
from
tests.helpers
import
get_package
from
tests.helpers
import
get_package
@pytest.fixture
def
tmp_dir
():
dir_
=
tempfile
.
mkdtemp
(
prefix
=
"poetry_"
)
yield
dir_
shutil
.
rmtree
(
dir_
)
def
test_basic_interactive
(
app
,
mocker
,
poetry
):
def
test_basic_interactive
(
app
,
mocker
,
poetry
):
command
=
app
.
find
(
"init"
)
command
=
app
.
find
(
"init"
)
command
.
_pool
=
poetry
.
pool
command
.
_pool
=
poetry
.
pool
...
...
tests/utils/test_env.py
0 → 100644
View file @
58dbca46
from
poetry.utils._compat
import
Path
from
poetry.utils.env
import
Env
from
poetry.utils.env
import
VirtualEnv
def
test_virtualenvs_with_spaces_in_their_path_work_as_expected
(
tmp_dir
):
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
Env
.
build_venv
(
str
(
venv_path
))
venv
=
VirtualEnv
(
venv_path
)
assert
venv
.
run
(
"python"
,
"-V"
,
shell
=
True
)
.
startswith
(
"Python"
)
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