diff --git a/changelog.d/windows-copy-pool.md b/changelog.d/windows-copy-pool.md new file mode 100644 index 00000000..4a67cb4c --- /dev/null +++ b/changelog.d/windows-copy-pool.md @@ -0,0 +1,5 @@ +### Fixed + +- On Windows a host copy of 32 MiB or more (on two or more threads) raised + `AttributeError`: the copy pool registered a fork handler, which Windows + does not have. diff --git a/changelog.d/windows-editable-version.md b/changelog.d/windows-editable-version.md new file mode 100644 index 00000000..fa17d2be --- /dev/null +++ b/changelog.d/windows-editable-version.md @@ -0,0 +1,4 @@ +### Fixed + +- On Windows an editable install's version was read from its metadata, not its + `pyproject.toml`: the `file:///C:/...` URL's path does not open there. diff --git a/packages/tack-core/src/tack/_deprecation.py b/packages/tack-core/src/tack/_deprecation.py index 77c5be08..a802ba13 100644 --- a/packages/tack-core/src/tack/_deprecation.py +++ b/packages/tack-core/src/tack/_deprecation.py @@ -124,12 +124,15 @@ def _package_version(package): import json import tomllib from importlib.metadata import distribution - from urllib.parse import unquote, urlparse + from urllib.parse import urlparse + from urllib.request import url2pathname found = distribution(package) origin = json.loads(found.read_text("direct_url.json") or "{}") if origin.get("dir_info", {}).get("editable") and origin.get("url", "").startswith("file:"): - project = os.path.join(unquote(urlparse(origin["url"]).path), "pyproject.toml") + # url2pathname, not the URL's path alone: on Windows that is /C:/..., which + # opens nothing (it unquotes as unquote did). + project = os.path.join(url2pathname(urlparse(origin["url"]).path), "pyproject.toml") try: with open(project, "rb") as f: stated = tomllib.load(f).get("project", {}).get("version") diff --git a/packages/tack-core/src/tack/lang/array.py b/packages/tack-core/src/tack/lang/array.py index eee36ee3..0b9bdbe0 100644 --- a/packages/tack-core/src/tack/lang/array.py +++ b/packages/tack-core/src/tack/lang/array.py @@ -278,7 +278,8 @@ def _host_copy(dst: np.ndarray, src: np.ndarray): from concurrent.futures import ThreadPoolExecutor _copy_pool = ThreadPoolExecutor(max_workers=_COPY_THREADS, thread_name_prefix="tack-copy") - os.register_at_fork(after_in_child=_reset_copy_pool) + if hasattr(os, "register_at_fork"): # POSIX alone: Windows never forks + os.register_at_fork(after_in_child=_reset_copy_pool) d, s = dst.reshape(-1), src.reshape(-1) k = int(min(threads, max(1, nbytes // _COPY_CHUNK_BYTES))) step = -(-d.size // k)