stores 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -250,6 +250,11 @@ class BaseIndex:
250
250
  return {tool.__name__: tool for tool in self.tools}
251
251
 
252
252
  def execute(self, toolname: str, kwargs: dict | None = None):
253
+ loop = asyncio.new_event_loop()
254
+ asyncio.set_event_loop(loop)
255
+ return loop.run_until_complete(self.async_execute(toolname, kwargs))
256
+
257
+ async def async_execute(self, toolname: str, kwargs: dict | None = None):
253
258
  kwargs = kwargs or {}
254
259
 
255
260
  # Use regex since we need to match cases where we perform
@@ -269,9 +274,7 @@ class BaseIndex:
269
274
 
270
275
  tool = self.tools_dict[toolname]
271
276
  if inspect.iscoroutinefunction(tool):
272
- loop = asyncio.new_event_loop()
273
- asyncio.set_event_loop(loop)
274
- return loop.run_until_complete(tool(**kwargs))
277
+ return await tool(**kwargs)
275
278
  else:
276
279
  return tool(**kwargs)
277
280
 
@@ -279,5 +282,11 @@ class BaseIndex:
279
282
  toolcall = llm_parse_json(msg, keys=["toolname", "kwargs"])
280
283
  return self.execute(toolcall.get("toolname"), toolcall.get("kwargs"))
281
284
 
285
+ async def async_parse_and_execute(self, msg: str):
286
+ toolcall = llm_parse_json(msg, keys=["toolname", "kwargs"])
287
+ return await self.async_execute(
288
+ toolcall.get("toolname"), toolcall.get("kwargs")
289
+ )
290
+
282
291
  def format_tools(self, provider: ProviderFormat):
283
292
  return format_tools(self.tools, provider)
@@ -28,11 +28,35 @@ logger.setLevel(logging.INFO)
28
28
  HASH_FILE = ".deps_hash"
29
29
 
30
30
 
31
- SUPPORTED_DEP_CONFIGS = {
32
- "pyproject.toml": f"{VENV_NAME}/bin/pip install .",
33
- "setup.py": f"{VENV_NAME}/bin/pip install .",
34
- "requirements.txt": f"{VENV_NAME}/bin/pip install -r requirements.txt",
35
- }
31
+ SUPPORTED_CONFIGS = [
32
+ "pyproject.toml",
33
+ "setup.py",
34
+ "requirements.txt",
35
+ ]
36
+
37
+
38
+ def get_pip_command(venv_path: os.PathLike, config_file: str) -> list[str]:
39
+ venv_path = Path(venv_path).resolve()
40
+ if os.name == "nt":
41
+ pip_path = venv_path / "Scripts" / "pip.exe"
42
+ else:
43
+ pip_path = venv_path / "bin" / "pip"
44
+
45
+ if config_file in {"pyproject.toml", "setup.py"}:
46
+ return [str(pip_path), "install", "."]
47
+ elif config_file == "requirements.txt":
48
+ return [str(pip_path), "install", "-r", "requirements.txt"]
49
+ else:
50
+ raise ValueError(f"Unsupported config file: {config_file}")
51
+
52
+
53
+ def get_python_command(venv_path: os.PathLike) -> list[str]:
54
+ venv_path = Path(venv_path).resolve()
55
+ if os.name == "nt":
56
+ executable = venv_path / "Scripts" / "python.exe"
57
+ else:
58
+ executable = venv_path / "bin" / "python"
59
+ return str(executable)
36
60
 
37
61
 
38
62
  def has_installed(config_path: os.PathLike):
@@ -63,18 +87,19 @@ def write_hash(config_path: os.PathLike):
63
87
  def install_venv_deps(index_folder: os.PathLike):
64
88
  index_folder = Path(index_folder)
65
89
 
66
- for config_file, install_cmd in SUPPORTED_DEP_CONFIGS.items():
90
+ for config_file in SUPPORTED_CONFIGS:
67
91
  config_path = index_folder / config_file
68
92
  if config_path.exists():
69
93
  # Check if already installed
70
94
  if has_installed(config_path):
71
95
  return "Already installed"
96
+ pip_command = get_pip_command(index_folder / VENV_NAME, config_file)
72
97
  subprocess.check_call(
73
- install_cmd.split(),
98
+ pip_command,
74
99
  cwd=index_folder,
75
100
  )
76
101
  write_hash(config_path)
77
- message = f"Installed with {index_folder}/{install_cmd}"
102
+ message = f'Installed with "{" ".join(pip_command)}"'
78
103
  logger.info(message)
79
104
  return message
80
105
 
@@ -201,10 +226,10 @@ except Exception as e:
201
226
  pickle.dump({{"ok": False, "error": err}}, sys.stdout.buffer)
202
227
  """
203
228
  result = subprocess.run(
204
- [f"{venv}/bin/python", "-c", runner],
229
+ [get_python_command(Path(index_folder) / venv), "-c", runner],
205
230
  capture_output=True,
206
231
  cwd=index_folder,
207
- env=env_var,
232
+ env=env_var or None,
208
233
  )
209
234
  try:
210
235
  response = pickle.loads(result.stdout)
@@ -380,11 +405,11 @@ sock = socket.create_connection(("localhost", {port}))
380
405
  sock.sendall(response.encode("utf-8"))
381
406
  sock.close()
382
407
  """
383
- subprocess.run(
384
- [f"{index_folder}/{venv}/bin/python", "-c", runner],
408
+ result = subprocess.run(
409
+ [get_python_command(Path(index_folder) / venv), "-c", runner],
385
410
  input=payload,
386
411
  capture_output=True,
387
- env=env_var,
412
+ env=env_var or None,
388
413
  )
389
414
 
390
415
  t.join()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stores
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Repository of Python functions and tools for LLMs
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -4,12 +4,12 @@ stores/format.py,sha256=LduYBVDiUDB1J1HDyu9jHrRG1V97pw6C5g76OirpJJY,7792
4
4
  stores/parse.py,sha256=HYPNPzQod2vpu1Cln7yQ8aVkZT1Mw2IN0sZ2A1DIaqE,4967
5
5
  stores/utils.py,sha256=GPWT6lCoGobwP3PlEOHyJfKyd0dobamjyErcR7lgm7M,242
6
6
  stores/indexes/__init__.py,sha256=s-RNqml8uGREQhxwSdDoxcbcxeD8soB9BcL5dBKsQfI,215
7
- stores/indexes/base_index.py,sha256=K4--_OAFyPNESaisD0JPNRIEffCnjw9nziahDgjdZHU,10708
7
+ stores/indexes/base_index.py,sha256=U12ZuvyuHSZJGdVdTMakdz6yHJQ1No0wOY45W5FoN0s,11073
8
8
  stores/indexes/index.py,sha256=C3i5JAwYoKEK7jIJRAgnLrQxjeewtInKcMinep6yvyA,2432
9
9
  stores/indexes/local_index.py,sha256=TVk7W8BXF5KEqjEK0LYqq3CtLMfHaF-Tk_5cZ6bjsBU,3189
10
10
  stores/indexes/remote_index.py,sha256=CHa9kQVDQlgI8qw3XQXchrE1cjXJk9fNY2j2HWL2gio,3226
11
- stores/indexes/venv_utils.py,sha256=U69UsHn9APTc615TchW2aZmrBORgbZhuZunv4zQv_hU,12514
12
- stores-0.1.4.dist-info/METADATA,sha256=Rkj7Ot2ClwUiCfkhejFU7Hs8PvXxTEdBXNQeWtlIrGA,3076
13
- stores-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- stores-0.1.4.dist-info/licenses/LICENSE,sha256=VTidYE7_Dam0Dwyq095EhhDIqi47g03oVpLAHQgKws0,1066
15
- stores-0.1.4.dist-info/RECORD,,
11
+ stores/indexes/venv_utils.py,sha256=2D0VasFfjwzEu_-LEyXREDN-SkWHGzx5TImvMpuKbjU,13313
12
+ stores-0.1.5.dist-info/METADATA,sha256=3yGFn2ANPUz3kxJ6jqZpvu5vwvm-LzUWq4-_0ObKDFU,3076
13
+ stores-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ stores-0.1.5.dist-info/licenses/LICENSE,sha256=VTidYE7_Dam0Dwyq095EhhDIqi47g03oVpLAHQgKws0,1066
15
+ stores-0.1.5.dist-info/RECORD,,
File without changes