Skip to content

Commit 4ae65fd

Browse files
authored
avoid dep issues (#1197)
1 parent 2aea2be commit 4ae65fd

1 file changed

Lines changed: 41 additions & 9 deletions

File tree

examples/slackbot/src/slackbot/search.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import httpx
55
from prefect import task
66
from pretty_mod import display_signature
7-
from pretty_mod.explorer import ModuleTreeExplorer
87
from raggy.vectorstores.tpuf import multi_query_tpuf
98

109
from slackbot.github import format_issues_summary, search_issues
1110

1211

13-
def explore_module_offerings(module_path: str, max_depth: int = 1) -> str:
12+
def explore_module_offerings(
13+
module_path: str, max_depth: int = 1, with_packages: list[str] | None = None
14+
) -> str:
1415
"""
1516
Explore and return the public API tree of a specific module and its submodules as a string.
1617
@@ -20,6 +21,7 @@ def explore_module_offerings(module_path: str, max_depth: int = 1) -> str:
2021
Args:
2122
module_path: String representing the module path (e.g., 'prefect.runtime', 'json', 'pandas')
2223
max_depth: Maximum depth to explore in the module tree (default: 1)
24+
with_packages: Optional list of packages to install for the exploration (e.g., ['prefect[aws]', 'boto3'])
2325
2426
Returns:
2527
str: A formatted string representation of the module tree
@@ -31,17 +33,47 @@ def explore_module_offerings(module_path: str, max_depth: int = 1) -> str:
3133
# Explore Prefect's runtime module in detail
3234
>>> explore_module_offerings('prefect.runtime', max_depth=2)
3335
34-
# Quick overview of pandas structure
35-
>>> explore_module_offerings('pandas', max_depth=1)
36+
# Explore AWS integration modules
37+
>>> explore_module_offerings('prefect_aws.ecs', max_depth=1, with_packages=['prefect[aws]'])
3638
3739
# See what's in a specific submodule
3840
>>> explore_module_offerings('prefect.artifacts', max_depth=0)
3941
"""
40-
explorer = ModuleTreeExplorer(module_path, max_depth=max_depth)
41-
explorer.explore()
42-
summary = explorer.get_tree_string()
43-
print(summary)
44-
return summary
42+
# Build the command
43+
cmd = ["uvx"]
44+
if with_packages:
45+
for package in with_packages:
46+
cmd.extend(["--with", package])
47+
cmd.extend(["pretty-mod", "tree"])
48+
49+
cmd.extend([module_path, "--depth", str(max_depth)])
50+
51+
try:
52+
result = subprocess.run(
53+
cmd,
54+
capture_output=True,
55+
text=True,
56+
timeout=30,
57+
check=False,
58+
)
59+
60+
# Check if it failed due to missing module
61+
if result.returncode != 0:
62+
error_output = result.stderr or result.stdout
63+
if "missing dependency" in error_output.lower():
64+
# Extract the missing module name if possible
65+
if "'" in error_output:
66+
missing = error_output.split("'")[1]
67+
return f"Module '{missing}' not found. Try specifying with_packages parameter with the required package (e.g., 'prefect[aws]', 'prefect-aws', or any PyPI package)."
68+
return f"Error exploring module: {error_output}"
69+
70+
# Return the formatted tree output
71+
return result.stdout if result.stdout else "No output from module exploration"
72+
73+
except subprocess.TimeoutExpired:
74+
return "Module exploration timed out after 30 seconds"
75+
except Exception as e:
76+
return f"Error running pretty-mod: {str(e)}"
4577

4678

4779
def review_common_3x_gotchas() -> list[str]:

0 commit comments

Comments
 (0)