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
de23305c
Commit
de23305c
authored
Nov 13, 2021
by
Bjorn Neergaard
Committed by
Arun Babu Neelicattu
Apr 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Use importlib to invoke packaging.tags in Env
parent
b6d4b0ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
27 deletions
+38
-27
src/poetry/utils/env.py
+26
-27
tests/utils/test_env.py
+12
-0
No files found.
src/poetry/utils/env.py
View file @
de23305c
...
...
@@ -11,7 +11,6 @@ import shutil
import
subprocess
import
sys
import
sysconfig
import
textwrap
from
contextlib
import
contextmanager
from
copy
import
deepcopy
...
...
@@ -54,6 +53,31 @@ if TYPE_CHECKING:
from
poetry.poetry
import
Poetry
GET_SYS_TAGS
=
f
"""
import importlib.util
import json
import sys
from pathlib import Path
spec = importlib.util.spec_from_file_location(
"packaging", Path(r"{packaging.__file__}")
)
packaging = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = packaging
spec = importlib.util.spec_from_file_location(
"packaging.tags", Path(r"{packaging.tags.__file__}")
)
packaging_tags = importlib.util.module_from_spec(spec)
spec.loader.exec_module(packaging_tags)
print(
json.dumps([(t.interpreter, t.abi, t.platform) for t in packaging_tags.sys_tags()])
)
"""
GET_ENVIRONMENT_INFO
=
"""
\
import json
import os
...
...
@@ -1614,32 +1638,7 @@ class VirtualEnv(Env):
]
def
get_supported_tags
(
self
)
->
list
[
Tag
]:
file_path
=
Path
(
packaging
.
tags
.
__file__
)
if
file_path
.
suffix
==
".pyc"
:
# Python 2
file_path
=
file_path
.
with_suffix
(
".py"
)
with
file_path
.
open
(
encoding
=
"utf-8"
)
as
f
:
script
=
decode
(
f
.
read
())
script
=
script
.
replace
(
"from ._typing import TYPE_CHECKING, cast"
,
"TYPE_CHECKING = False
\n
cast = lambda type_, value: value"
,
)
script
=
script
.
replace
(
"from ._typing import MYPY_CHECK_RUNNING, cast"
,
"MYPY_CHECK_RUNNING = False
\n
cast = lambda type_, value: value"
,
)
script
+=
textwrap
.
dedent
(
"""
import json
print(json.dumps([(t.interpreter, t.abi, t.platform) for t in sys_tags()]))
"""
)
output
=
self
.
run_python_script
(
script
)
output
=
self
.
run_python_script
(
GET_SYS_TAGS
)
return
[
Tag
(
*
t
)
for
t
in
json
.
loads
(
output
)]
...
...
tests/utils/test_env.py
View file @
de23305c
...
...
@@ -119,6 +119,18 @@ def test_env_shell_commands_with_stdinput_in_their_arg_work_as_expected(
assert
run_output_path
.
resolve
()
==
venv_base_prefix_path
.
resolve
()
def
test_env_get_supported_tags_matches_inside_virtualenv
(
tmp_dir
:
str
,
manager
:
EnvManager
):
venv_path
=
Path
(
tmp_dir
)
/
"Virtual Env"
manager
.
build_venv
(
str
(
venv_path
))
venv
=
VirtualEnv
(
venv_path
)
import
packaging.tags
assert
venv
.
get_supported_tags
()
==
list
(
packaging
.
tags
.
sys_tags
())
@pytest.fixture
def
in_project_venv_dir
(
poetry
:
Poetry
)
->
Iterator
[
Path
]:
os
.
environ
.
pop
(
"VIRTUAL_ENV"
,
None
)
...
...
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