symbex 0.2__py3-none-any.whl → 0.2.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
symbex/cli.py CHANGED
@@ -8,7 +8,12 @@ from .lib import code_for_node, find_symbol_nodes
8
8
  @click.version_option()
9
9
  @click.argument("symbols", nargs=-1)
10
10
  @click.option(
11
- "files", "-f", "--file", type=click.File("r"), multiple=True, help="Files to search"
11
+ "files",
12
+ "-f",
13
+ "--file",
14
+ type=click.Path(file_okay=True, dir_okay=False),
15
+ multiple=True,
16
+ help="Files to search",
12
17
  )
13
18
  @click.option(
14
19
  "directories",
@@ -18,7 +23,12 @@ from .lib import code_for_node, find_symbol_nodes
18
23
  multiple=True,
19
24
  help="Directories to search",
20
25
  )
21
- def cli(symbols, files, directories):
26
+ @click.option(
27
+ "--silent",
28
+ is_flag=True,
29
+ help="Silently ignore Python files with parse errors",
30
+ )
31
+ def cli(symbols, files, directories, silent):
22
32
  """
23
33
  Find symbols in Python code and print the code for them.
24
34
 
@@ -40,13 +50,18 @@ def cli(symbols, files, directories):
40
50
  """
41
51
  if not files and not directories:
42
52
  directories = ["."]
43
- files = list(files)
53
+ files = [pathlib.Path(f) for f in files]
44
54
  for directory in directories:
45
55
  files.extend(pathlib.Path(directory).rglob("*.py"))
46
56
  pwd = pathlib.Path(".").resolve()
47
57
  for file in files:
48
58
  code = file.read_text("utf-8") if hasattr(file, "read_text") else file.read()
49
- nodes = find_symbol_nodes(code, symbols)
59
+ try:
60
+ nodes = find_symbol_nodes(code, symbols)
61
+ except SyntaxError as ex:
62
+ if not silent:
63
+ click.secho(f"# Syntax error in {file}: {ex}", err=True, fg="yellow")
64
+ continue
50
65
  for node in nodes:
51
66
  # If file is within pwd, print relative path
52
67
  # else print absolute path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: symbex
3
- Version: 0.2
3
+ Version: 0.2.1
4
4
  Summary: Find the Python code for specified symbols
5
5
  Home-page: https://github.com/simonw/symbex
6
6
  Author: Simon Willison
@@ -57,6 +57,14 @@ To search within a specific directory and all of its subdirectories, use the `-d
57
57
  ```bash
58
58
  symbex Database -d ~/projects/datasette
59
59
  ```
60
+ If `symbex` encounters any Python code that it cannot parse, it will print a warning message and continue searching:
61
+ ```
62
+ # Syntax error in path/badcode.py: expected ':' (<unknown>, line 1)
63
+ ```
64
+ Pass `--silent` to suppress these warnings:
65
+ ```bash
66
+ symbex MyClass --silent
67
+ ```
60
68
 
61
69
  ## Example output
62
70
 
@@ -0,0 +1,10 @@
1
+ symbex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ symbex/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
3
+ symbex/cli.py,sha256=LXrPvjSG4IvDeLbDNoZ6Dykb4zt4D6UK7wVwjClf8Dw,2142
4
+ symbex/lib.py,sha256=1YViD5fJ_NP1Y32LTFM7o8UCTzUiz3yTldVvJb8owgs,1190
5
+ symbex-0.2.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ symbex-0.2.1.dist-info/METADATA,sha256=SaikT2bPWwSeRgCBlFzg13ONt-BiyV9dMdAtpdKDQJ8,4192
7
+ symbex-0.2.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
8
+ symbex-0.2.1.dist-info/entry_points.txt,sha256=YgMSEfEGqNMHM9RysFObH8lkQKVZKyymKLnXbVue_Uk,42
9
+ symbex-0.2.1.dist-info/top_level.txt,sha256=qwle8HjAaYgpdMIHlJcTcN4gaG4wmDqUvkt54beTBTs,7
10
+ symbex-0.2.1.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- symbex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- symbex/__main__.py,sha256=8hDtWlaFZK24KhfNq_ZKgtXqYHsDQDetukOCMlsbW0Q,59
3
- symbex/cli.py,sha256=tJhsnbWEiIN9LSZGGcqrmpY5U9TgISvknXsMCpijlSs,1770
4
- symbex/lib.py,sha256=1YViD5fJ_NP1Y32LTFM7o8UCTzUiz3yTldVvJb8owgs,1190
5
- symbex-0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- symbex-0.2.dist-info/METADATA,sha256=QMsejWdFVPSvRODCyd09SRl_mcH0dLvXk3tOX2GNbts,3917
7
- symbex-0.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
8
- symbex-0.2.dist-info/entry_points.txt,sha256=YgMSEfEGqNMHM9RysFObH8lkQKVZKyymKLnXbVue_Uk,42
9
- symbex-0.2.dist-info/top_level.txt,sha256=qwle8HjAaYgpdMIHlJcTcN4gaG4wmDqUvkt54beTBTs,7
10
- symbex-0.2.dist-info/RECORD,,
File without changes
File without changes