Skip to content

Commit 870cd33

Browse files
authored
fix: testing in Windows and add missing dev dependency (#2340)
This changes addresses two issues. First, we add `setuptools` to the dev dependencies in order to debug tests locally with an IDE, especially with PyCharm. All dependencies dev dependencies should be installed with `poetry install --extras "dev"`. Second, we use PurePosixPath instead of Path for URL paths to fix issues with testing in Windows. This ensures that forward slashes are used as the path separator regardless of the operating system. Closes #2334
1 parent 393cd3c commit 870cd33

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

langchain/utilities/loading.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import re
55
import tempfile
6-
from pathlib import Path
6+
from pathlib import Path, PurePosixPath
77
from typing import Any, Callable, Optional, Set, TypeVar, Union
88
from urllib.parse import urljoin
99

@@ -16,7 +16,6 @@
1616
)
1717
HUB_PATH_RE = re.compile(r"lc(?P<ref>@[^:]+)?://(?P<path>.*)")
1818

19-
2019
T = TypeVar("T")
2120

2221

@@ -38,7 +37,13 @@ def try_load_from_hub(
3837
if remote_path.suffix[1:] not in valid_suffixes:
3938
raise ValueError("Unsupported file type.")
4039

41-
full_url = urljoin(URL_BASE.format(ref=ref), str(remote_path))
40+
# Using Path with URLs is not recommended, because on Windows
41+
# the backslash is used as the path separator, which can cause issues
42+
# when working with URLs that use forward slashes as the path separator.
43+
# Instead, use PurePosixPath to ensure that forward slashes are used as the
44+
# path separator, regardless of the operating system.
45+
full_url = urljoin(URL_BASE.format(ref=ref), PurePosixPath(remote_path).__str__())
46+
4247
r = requests.get(full_url, timeout=5)
4348
if r.status_code != 200:
4449
raise ValueError(f"Could not find file at {full_url}")

poetry.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ optional = true
9999
[tool.poetry.group.dev.dependencies]
100100
jupyter = "^1.0.0"
101101
playwright = "^1.28.0"
102+
setuptools = "^67.6.1"
102103

103104
[tool.poetry.extras]
104105
llms = ["anthropic", "cohere", "openai", "nlpcloud", "huggingface_hub", "manifest-ml", "torch", "transformers"]

0 commit comments

Comments
 (0)