From bbe5a2b0b4ebcac1230bbe954b5da6592bda6321 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 22 Apr 2025 22:28:41 -0700 Subject: [PATCH 1/3] Fix for repeated import lines, refs #46 --- symbex/cli.py | 4 +++- tests/test_output.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/symbex/cli.py b/symbex/cli.py index cf01330..b0bca06 100644 --- a/symbex/cli.py +++ b/symbex/cli.py @@ -538,11 +538,13 @@ def stuff_to_output(): ) if sum(output_formats) == 0: + seen_imports = set() for item in stuff_to_output(): if item.output_identifier_line: click.echo(item.output_identifier_line) - if item.output_import_line: + if item.output_import_line and item.output_import_line not in seen_imports: click.echo(item.output_import_line) + seen_imports.add(item.output_import_line) click.echo(item.snippet) click.echo() else: diff --git a/tests/test_output.py b/tests/test_output.py index aa01e5f..7afd7e6 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -44,3 +44,30 @@ def test_output(extra_args, expected, expected_error): else: assert result.exit_code == 0 assert result.output == expected + + +def test_output_class_with_methods(): + runner = CliRunner() + with runner.isolated_filesystem(): + open("symbex.py", "w").write( + "class Foo:\n" + " def bar(self):\n" + " pass\n" + " def baz(self):\n" + " pass\n" + ) + result = runner.invoke( + cli, + ["*", "*.*", "--docs", "--imports", "-n"], + catch_exceptions=False, + ) + assert result.exit_code == 0 + assert result.output == ( + "# from symbex import Foo\n" + "class Foo:\n" + "\n" + " def bar(self):\n" + "\n" + " def baz(self):\n" + "\n" + ) From beb53c3f6f5d17a04ec775817a60d1aaeb86b743 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 22 Apr 2025 22:20:53 -0700 Subject: [PATCH 2/3] Upgrade to pyproject.toml Refs https://github.com/simonw/symbex/issues/46#issuecomment-2823086557 --- .github/workflows/publish.yml | 12 +++++++----- .github/workflows/test.yml | 4 ++-- pyproject.toml | 32 ++++++++++++++++++++++++++++++ setup.py | 37 ----------------------------------- 4 files changed, 41 insertions(+), 44 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7275191..586b21c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,10 +21,10 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: pip - cache-dependency-path: setup.py + cache-dependency-path: pyproject.toml - name: Install dependencies run: | - pip install '.[test]' + pip install -e '.[test]' - name: Run tests run: | python -m pytest @@ -32,14 +32,16 @@ jobs: runs-on: ubuntu-latest needs: [test] environment: release + permissions: + id-token: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.13" cache: pip - cache-dependency-path: setup.py + cache-dependency-path: pyproject.toml - name: Install dependencies run: | pip install setuptools wheel build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97092b9..1654300 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,10 +18,10 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: pip - cache-dependency-path: setup.py + cache-dependency-path: pyproject.toml - name: Install dependencies run: | - pip install '.[test]' + pip install -e '.[test]' - name: Run tests run: | python -m pytest diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6dd866b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[project] +name = "symbex" +version = "1.4.1" +description = "Find the Python code for specified symbols" +readme = "README.md" +authors = [{name = "Simon Willison"}] +license = "Apache-2.0" +requires-python = ">=3.8" +dependencies = [ + "click" +] + +[project.urls] +Homepage = "https://github.com/simonw/symbex" +Issues = "https://github.com/simonw/symbex/issues" +CI = "https://github.com/simonw/symbex/actions" +Changelog = "https://github.com/simonw/symbex/releases" + +[project.scripts] +symbex = "symbex.cli:cli" + +[project.optional-dependencies] +test = ["pytest", "pytest-icdiff", "cogapp", "PyYAML", "ruff"] + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +where = ["."] +include = ["symbex"] + diff --git a/setup.py b/setup.py deleted file mode 100644 index f22b4a3..0000000 --- a/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -from setuptools import setup -import os - -VERSION = "1.4.1" - - -def get_long_description(): - with open( - os.path.join(os.path.dirname(os.path.abspath(__file__)), "README.md"), - encoding="utf8", - ) as fp: - return fp.read() - - -setup( - name="symbex", - description="Find the Python code for specified symbols", - long_description=get_long_description(), - long_description_content_type="text/markdown", - author="Simon Willison", - url="https://github.com/simonw/symbex", - project_urls={ - "Issues": "https://github.com/simonw/symbex/issues", - "CI": "https://github.com/simonw/symbex/actions", - "Changelog": "https://github.com/simonw/symbex/releases", - }, - license="Apache License, Version 2.0", - version=VERSION, - packages=["symbex"], - entry_points=""" - [console_scripts] - symbex=symbex.cli:cli - """, - install_requires=["click"], - extras_require={"test": ["pytest", "pytest-icdiff", "cogapp", "PyYAML", "ruff"]}, - python_requires=">=3.8", -) From 81c4b9c042f271f0d8b9a4d50095876cd54e05a2 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 22 Apr 2025 22:31:14 -0700 Subject: [PATCH 3/3] Release 2.0 Refs #46 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6dd866b..ba5b2fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "symbex" -version = "1.4.1" +version = "2.0" description = "Find the Python code for specified symbols" readme = "README.md" authors = [{name = "Simon Willison"}]