From 470d6151724df8af015323232f1f4bca2a0f0a55 Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Sat, 9 Dec 2023 22:20:37 +0100 Subject: [PATCH] try if this makes it work on windows --- src/mxdev/including.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/mxdev/including.py b/src/mxdev/including.py index c797856..3b4a340 100644 --- a/src/mxdev/including.py +++ b/src/mxdev/including.py @@ -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" @@ -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(): @@ -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.