Skip to content

Commit

Permalink
add _patched_resolve() as workaround for cpython #82852
Browse files Browse the repository at this point in the history
for python <3.10 on windows
  • Loading branch information
dennisvang committed Sep 6, 2023
1 parent 0769051 commit da8ff95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tufup/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from tuf.api.serialization.json import JSONSerializer

from tufup.common import Patcher, SUFFIX_ARCHIVE, SUFFIX_PATCH, TargetMeta
from tufup.utils.platform_specific import _patched_resolve

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -515,9 +516,9 @@ def __init__(
thresholds: Optional[RolesDict] = None,
):
if repo_dir is None:
repo_dir = pathlib.Path.cwd() / DEFAULT_REPO_DIR_NAME
repo_dir = DEFAULT_REPO_DIR_NAME
if keys_dir is None:
keys_dir = pathlib.Path.cwd() / DEFAULT_KEYS_DIR_NAME
keys_dir = DEFAULT_KEYS_DIR_NAME
if key_map is None:
key_map = deepcopy(DEFAULT_KEY_MAP)
if encrypted_keys is None:
Expand All @@ -529,8 +530,8 @@ def __init__(
self.app_name = app_name
self.app_version_attr = app_version_attr
# force path object and resolve, in case of relative paths
self.repo_dir = pathlib.Path(repo_dir).resolve()
self.keys_dir = pathlib.Path(keys_dir).resolve()
self.repo_dir = _patched_resolve(pathlib.Path(repo_dir))
self.keys_dir = _patched_resolve(pathlib.Path(keys_dir))
self.key_map = key_map
self.encrypted_keys = encrypted_keys
self.expiration_days = expiration_days
Expand Down
17 changes: 17 additions & 0 deletions src/tufup/utils/platform_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,20 @@ def _install_update_mac(
logger.debug(f'Restarting application, running {sys.executable}.')
subprocess.Popen(sys.executable, shell=True) # nosec
sys.exit(0)


def _patched_resolve(path: pathlib.Path):
"""
this is a rather crude workaround for cpython issue #82852,
where Path.resolve() yields a relative path, on windows, if the target
does not exist yet
https://github.com/python/cpython/issues/82852
todo: remove this as soon as support for python 3.9 is dropped
"""
if ON_WINDOWS and sys.version_info[:2] < (3, 10):
logger.warning('using patched path for cpython #82852')
if not path.is_absolute():
path = pathlib.Path.cwd() / path
return path.resolve()

0 comments on commit da8ff95

Please sign in to comment.