symbex 1.4__tar.gz → 2.0__tar.gz

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.
@@ -1,19 +1,26 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: symbex
3
- Version: 1.4
3
+ Version: 2.0
4
4
  Summary: Find the Python code for specified symbols
5
- Home-page: https://github.com/simonw/symbex
6
5
  Author: Simon Willison
7
- License: Apache License, Version 2.0
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/simonw/symbex
8
8
  Project-URL: Issues, https://github.com/simonw/symbex/issues
9
9
  Project-URL: CI, https://github.com/simonw/symbex/actions
10
10
  Project-URL: Changelog, https://github.com/simonw/symbex/releases
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
- Provides-Extra: test
14
13
  License-File: LICENSE
14
+ Requires-Dist: click
15
+ Provides-Extra: test
16
+ Requires-Dist: pytest; extra == "test"
17
+ Requires-Dist: pytest-icdiff; extra == "test"
18
+ Requires-Dist: cogapp; extra == "test"
19
+ Requires-Dist: PyYAML; extra == "test"
20
+ Requires-Dist: ruff; extra == "test"
21
+ Dynamic: license-file
15
22
 
16
- # symbex
23
+ # Symbex
17
24
 
18
25
  [![PyPI](https://img.shields.io/pypi/v/symbex.svg)](https://pypi.org/project/symbex/)
19
26
  [![Changelog](https://img.shields.io/github/v/release/simonw/symbex?include_prereleases&label=changelog)](https://github.com/simonw/symbex/releases)
@@ -22,7 +29,7 @@ License-File: LICENSE
22
29
 
23
30
  Find the Python code for specified symbols
24
31
 
25
- Read [symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
32
+ Read [Symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
26
33
 
27
34
  ## Installation
28
35
 
@@ -1,4 +1,4 @@
1
- # symbex
1
+ # Symbex
2
2
 
3
3
  [![PyPI](https://img.shields.io/pypi/v/symbex.svg)](https://pypi.org/project/symbex/)
4
4
  [![Changelog](https://img.shields.io/github/v/release/simonw/symbex?include_prereleases&label=changelog)](https://github.com/simonw/symbex/releases)
@@ -7,7 +7,7 @@
7
7
 
8
8
  Find the Python code for specified symbols
9
9
 
10
- Read [symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
10
+ Read [Symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
11
11
 
12
12
  ## Installation
13
13
 
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "symbex"
3
+ version = "2.0"
4
+ description = "Find the Python code for specified symbols"
5
+ readme = "README.md"
6
+ authors = [{name = "Simon Willison"}]
7
+ license = "Apache-2.0"
8
+ requires-python = ">=3.8"
9
+ dependencies = [
10
+ "click"
11
+ ]
12
+
13
+ [project.urls]
14
+ Homepage = "https://github.com/simonw/symbex"
15
+ Issues = "https://github.com/simonw/symbex/issues"
16
+ CI = "https://github.com/simonw/symbex/actions"
17
+ Changelog = "https://github.com/simonw/symbex/releases"
18
+
19
+ [project.scripts]
20
+ symbex = "symbex.cli:cli"
21
+
22
+ [project.optional-dependencies]
23
+ test = ["pytest", "pytest-icdiff", "cogapp", "PyYAML", "ruff"]
24
+
25
+ [build-system]
26
+ requires = ["setuptools"]
27
+ build-backend = "setuptools.build_meta"
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["."]
31
+ include = ["symbex"]
32
+
@@ -396,7 +396,7 @@ def cli(
396
396
  for directory in directories:
397
397
  for path in pathlib.Path(directory).rglob("*.py"):
398
398
  # Skip if path is inside any of 'excludes'
399
- if any(is_subpath(path, exclude) for exclude in excludes):
399
+ if any(path.resolve().is_relative_to(exclude) for exclude in excludes):
400
400
  continue
401
401
  if path.is_file():
402
402
  yield path
@@ -538,11 +538,13 @@ def cli(
538
538
  )
539
539
 
540
540
  if sum(output_formats) == 0:
541
+ seen_imports = set()
541
542
  for item in stuff_to_output():
542
543
  if item.output_identifier_line:
543
544
  click.echo(item.output_identifier_line)
544
- if item.output_import_line:
545
+ if item.output_import_line and item.output_import_line not in seen_imports:
545
546
  click.echo(item.output_import_line)
547
+ seen_imports.add(item.output_import_line)
546
548
  click.echo(item.snippet)
547
549
  click.echo()
548
550
  else:
@@ -601,14 +603,6 @@ def cli(
601
603
  filepath.write_text(new, "utf-8")
602
604
 
603
605
 
604
- def is_subpath(path: pathlib.Path, parent: pathlib.Path) -> bool:
605
- try:
606
- path.relative_to(parent)
607
- return True
608
- except ValueError:
609
- return False
610
-
611
-
612
606
  def is_dunder(name):
613
607
  return name.startswith("__") and name.endswith("__")
614
608
 
@@ -1,19 +1,26 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: symbex
3
- Version: 1.4
3
+ Version: 2.0
4
4
  Summary: Find the Python code for specified symbols
5
- Home-page: https://github.com/simonw/symbex
6
5
  Author: Simon Willison
7
- License: Apache License, Version 2.0
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/simonw/symbex
8
8
  Project-URL: Issues, https://github.com/simonw/symbex/issues
9
9
  Project-URL: CI, https://github.com/simonw/symbex/actions
10
10
  Project-URL: Changelog, https://github.com/simonw/symbex/releases
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
- Provides-Extra: test
14
13
  License-File: LICENSE
14
+ Requires-Dist: click
15
+ Provides-Extra: test
16
+ Requires-Dist: pytest; extra == "test"
17
+ Requires-Dist: pytest-icdiff; extra == "test"
18
+ Requires-Dist: cogapp; extra == "test"
19
+ Requires-Dist: PyYAML; extra == "test"
20
+ Requires-Dist: ruff; extra == "test"
21
+ Dynamic: license-file
15
22
 
16
- # symbex
23
+ # Symbex
17
24
 
18
25
  [![PyPI](https://img.shields.io/pypi/v/symbex.svg)](https://pypi.org/project/symbex/)
19
26
  [![Changelog](https://img.shields.io/github/v/release/simonw/symbex?include_prereleases&label=changelog)](https://github.com/simonw/symbex/releases)
@@ -22,7 +29,7 @@ License-File: LICENSE
22
29
 
23
30
  Find the Python code for specified symbols
24
31
 
25
- Read [symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
32
+ Read [Symbex: search Python code for functions and classes, then pipe them into a LLM](https://simonwillison.net/2023/Jun/18/symbex/) for background on this project.
26
33
 
27
34
  ## Installation
28
35
 
@@ -1,6 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
- setup.py
3
+ pyproject.toml
4
4
  symbex/__init__.py
5
5
  symbex/__main__.py
6
6
  symbex/cli.py
@@ -44,3 +44,30 @@ def test_output(extra_args, expected, expected_error):
44
44
  else:
45
45
  assert result.exit_code == 0
46
46
  assert result.output == expected
47
+
48
+
49
+ def test_output_class_with_methods():
50
+ runner = CliRunner()
51
+ with runner.isolated_filesystem():
52
+ open("symbex.py", "w").write(
53
+ "class Foo:\n"
54
+ " def bar(self):\n"
55
+ " pass\n"
56
+ " def baz(self):\n"
57
+ " pass\n"
58
+ )
59
+ result = runner.invoke(
60
+ cli,
61
+ ["*", "*.*", "--docs", "--imports", "-n"],
62
+ catch_exceptions=False,
63
+ )
64
+ assert result.exit_code == 0
65
+ assert result.output == (
66
+ "# from symbex import Foo\n"
67
+ "class Foo:\n"
68
+ "\n"
69
+ " def bar(self):\n"
70
+ "\n"
71
+ " def baz(self):\n"
72
+ "\n"
73
+ )
@@ -89,6 +89,8 @@ def directory_full_of_code(tmpdir):
89
89
  ["baz", "-d", "nested.py", "-x", "nested.py/x/", "--silent"],
90
90
  "",
91
91
  ),
92
+ # -x to exclude top level directory
93
+ (["baz", "-x", "nested.py", "--silent"], ""),
92
94
  # Classes
93
95
  (
94
96
  ["MyClass", "--silent"],
@@ -164,10 +166,10 @@ def test_fixture(directory_full_of_code, monkeypatch, args, expected):
164
166
  'def baz(delimiter=", ", type=str):'
165
167
  ),
166
168
  ),
167
- # Test for the --module option
169
+ # Tests for the --module option
168
170
  (
169
- ["-m", "pathlib", "Path", "--silent", "-in"],
170
- ("# from pathlib import Path\nclass Path(PurePath):"),
171
+ ["-m", "contextlib", "suppress", "--silent", "-sn"],
172
+ ("class suppress(AbstractContextManager):"),
171
173
  ),
172
174
  ),
173
175
  )
symbex-1.4/setup.py DELETED
@@ -1,37 +0,0 @@
1
- from setuptools import setup
2
- import os
3
-
4
- VERSION = "1.4"
5
-
6
-
7
- def get_long_description():
8
- with open(
9
- os.path.join(os.path.dirname(os.path.abspath(__file__)), "README.md"),
10
- encoding="utf8",
11
- ) as fp:
12
- return fp.read()
13
-
14
-
15
- setup(
16
- name="symbex",
17
- description="Find the Python code for specified symbols",
18
- long_description=get_long_description(),
19
- long_description_content_type="text/markdown",
20
- author="Simon Willison",
21
- url="https://github.com/simonw/symbex",
22
- project_urls={
23
- "Issues": "https://github.com/simonw/symbex/issues",
24
- "CI": "https://github.com/simonw/symbex/actions",
25
- "Changelog": "https://github.com/simonw/symbex/releases",
26
- },
27
- license="Apache License, Version 2.0",
28
- version=VERSION,
29
- packages=["symbex"],
30
- entry_points="""
31
- [console_scripts]
32
- symbex=symbex.cli:cli
33
- """,
34
- install_requires=["click"],
35
- extras_require={"test": ["pytest", "pytest-icdiff", "cogapp", "PyYAML", "ruff"]},
36
- python_requires=">=3.8",
37
- )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes