Skip to content

Commit

Permalink
Manage temp file manually because of Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed May 11, 2021
1 parent a18e73f commit 7807177
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions poetry/core/pyproject/constraint_dependencies_toml.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import os
import urllib.request

from tempfile import NamedTemporaryFile
from tempfile import mkstemp
from typing import TYPE_CHECKING
from typing import Optional
from typing import Union
from urllib.error import URLError
from urllib.parse import urlparse


if TYPE_CHECKING:
from tomlkit.container import Container
from tomlkit.items import Item


class ConstraintDependenciesTOML:
def __init__(self, path_or_url: str) -> None:
self._path_or_url = path_or_url

@property
def dependencies(self) -> Optional[Union["Item", "Container"]]:
def dependencies(self) -> "Container":
from tomlkit.exceptions import NonExistentKey

from poetry.core.toml import TOMLFile
Expand All @@ -29,19 +27,21 @@ def dependencies(self) -> Optional[Union["Item", "Container"]]:
else "file:" + self._path_or_url
)
try:
response = urllib.request.urlopen(url)
content = urllib.request.urlopen(url).read()
except URLError as e:
raise RuntimeError(
"Poetry could not load constraint dependencies file {}".format(
self._path_or_url
)
) from e
else:
with NamedTemporaryFile(
prefix="poetry-constraint-dependencies-", buffering=0
) as fp:
fp.write(response.read())
constraint_dependencies_file = TOMLFile(fp.name)
fd, path = mkstemp(prefix="poetry-constraint-dependencies-")
with open(path, mode="w+b") as f:
f.write(content)

constraint_dependencies_file = TOMLFile(f.name)

try:
data = constraint_dependencies_file.read()

try:
Expand All @@ -52,3 +52,6 @@ def dependencies(self) -> Optional[Union["Item", "Container"]]:
self._path_or_url
)
) from e
finally:
os.close(fd)
os.unlink(path)

0 comments on commit 7807177

Please sign in to comment.