Skip to content

Commit

Permalink
try if this makes it work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 9, 2023
1 parent 2784b72 commit 470d615
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/mxdev/including.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from configparser import ConfigParser
from configparser import ExtendedInterpolation
from pathlib import Path
from urllib import parse
from urllib import request

import os
import pathlib
import tempfile
import typing


def resolve_dependencies(
file_or_url: typing.Union[str, pathlib.Path],
file_or_url: typing.Union[str, Path],
tmpdir: str,
http_parent=None,
) -> typing.List[pathlib.Path]:
) -> typing.List[Path]:
"""Resolve dependencies of a file or url
The result is a list of pathlib.Path objects, starting with the
The result is a list of Path objects, starting with the
given file_or_url and followed by all file_or_urls referenced from it.
The file_or_url is assumed to be a ini file or url to such, with an option key "include"
Expand All @@ -28,15 +28,19 @@ def resolve_dependencies(
parsed = parse.urlparse(str(file_or_url))
if parsed.scheme:
with request.urlopen(str(file_or_url)) as fio:
tf = tempfile.NamedTemporaryFile(suffix=".ini", dir=str(tmpdir))
tf = tempfile.NamedTemporaryFile(
suffix=".ini",
dir=str(tmpdir),
delete=False,
)
tf.write(fio.read())
tf.flush()
file = pathlib.Path(tf.name)
file = Path(tf.name)
parts = list(parsed)
parts[2] = str(pathlib.Path(parts[2]).parent)
parts[2] = str(Path(parts[2]).parent)
http_parent = parse.urlunparse(parts)
else:
file = pathlib.Path(file_or_url)
file = Path(file_or_url)
else:
file = file_or_url
if not file.exists():
Expand All @@ -59,7 +63,7 @@ def resolve_dependencies(
return file_list


def read_with_included(file_or_url: typing.Union[str, pathlib.Path]) -> ConfigParser:
def read_with_included(file_or_url: typing.Union[str, Path]) -> ConfigParser:
"""Read a file or url and include all referenced files,
Parse the result as a ConfigParser and return it.
Expand Down

0 comments on commit 470d615

Please sign in to comment.