From 003498e44b41ed20fffb9c780b30581f31ac9b54 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 15 Oct 2026 19:09:02 +0100 Subject: [PATCH 1/3] Trivial changes Signed-off-by: Stephen Finucane --- pyproject.toml | 3 --- tox.ini | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 99bd59a..6384629 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,9 +35,6 @@ click-man = "click_man.shell:cli" [project.urls] Source = "https://github.com/click-contrib/click-man" -# [tool.setuptools] -# include-package-data = false - [tool.setuptools.packages.find] include = ["click_man*"] exclude = ["tests*"] diff --git a/tox.ini b/tox.ini index 05601d2..a05298b 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ [tox] minversion = 4.4 -envlist = lint,py39,py310,py311,py312,py313 +envlist = lint,py{39,310,311,312,313} [testenv] description = From e0d37ef226c7696783b73dbd4e18c5d62e48d6f5 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 15 Oct 2026 19:10:04 +0100 Subject: [PATCH 2/3] Fix compatibility with Python 3.10+ Signed-off-by: Stephen Finucane --- .github/workflows/ci.yaml | 2 +- click_man/shell.py | 20 ++++++++++++++++- tests/test_shell.py | 47 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c4ff551..15e48bb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ['3.9', '3.10', '3.11', '3.12', '3.13'] + python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] steps: - name: Checkout source code uses: actions/checkout@v4 diff --git a/click_man/shell.py b/click_man/shell.py index cb15d94..c08370b 100644 --- a/click_man/shell.py +++ b/click_man/shell.py @@ -40,6 +40,24 @@ def _get_entry_point(name: str) -> Optional[importlib.metadata.EntryPoint]: return tuple(console_scripts)[0] +def _get_version( + entry_point: importlib.metadata.EntryPoint, name: str +) -> Optional[str]: + dist = getattr(entry_point, 'dist', None) + if dist and getattr(dist, 'version', None): + return dist.version + + # Python < 3.10 fallback where EntryPoint has no dist attribute + for dist in importlib.metadata.distributions(): + if any( + ep.group == 'console_scripts' and ep.name == name + for ep in dist.entry_points + ): + return dist.version + + return None + + @click.command(context_settings={'help_option_names': ['-h', '--help']}) @click.option( '--target', @@ -77,7 +95,7 @@ def cli(target, name, man_version, man_date): pass if not man_version: - man_version = entry_point.version + man_version = _get_version(entry_point, name) if man_date: try: diff --git a/tests/test_shell.py b/tests/test_shell.py index 60e55fe..bce7a29 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -35,7 +35,7 @@ def test_cli__valid(mock_entry_point, mock_echo, mock_write): fake_version = '1.2.3' entry_point = mock.Mock(spec=importlib.metadata.EntryPoint) entry_point.load.return_value = fake_command - entry_point.version = fake_version + entry_point.dist = mock.Mock(version=fake_version) mock_entry_point.return_value = entry_point @@ -60,6 +60,51 @@ def test_cli__valid(mock_entry_point, mock_echo, mock_write): ) +@mock.patch('os.makedirs', new=mock.Mock()) +@mock.patch.object(shell, 'write_man_pages') +@mock.patch.object(click, 'echo') +@mock.patch.object(shell, '_get_entry_point') +@mock.patch('importlib.metadata.distributions') +def test_cli__valid_no_dist( + mock_distributions, mock_entry_point, mock_echo, mock_write +): + fake_target = os.path.join(os.getcwd(), 'man') + fake_command = click.Command(name='foo') + fake_version = '1.2.3' + entry_point = mock.Mock(spec=importlib.metadata.EntryPoint) + entry_point.load.return_value = fake_command + entry_point.dist = None + + mock_entry_point.return_value = entry_point + + fake_ep = mock.Mock(group='console_scripts') + fake_ep.name = 'foo' + fake_dist = mock.Mock() + fake_dist.version = fake_version + fake_dist.entry_points = [fake_ep] + mock_distributions.return_value = [fake_dist] + + runner = CLIRunner() + result = runner.invoke(shell.cli, ['foo']) + + assert result.exit_code == 0, result.output + + mock_entry_point.assert_called_once_with('foo') + mock_echo.assert_has_calls( + [ + mock.call('Load entry point foo'), + mock.call('Generate man pages for foo in %s' % fake_target), + ] + ) + mock_write.assert_called_once_with( + 'foo', + fake_command, + version=fake_version, + target_dir=fake_target, + date=None, + ) + + @mock.patch('os.makedirs', new=mock.Mock()) @mock.patch.object(shell, 'write_man_pages') @mock.patch.object(click, 'echo') From 388e09fbd633e8f266547ba9f133c1d6fc529cf8 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 15 Oct 2026 19:11:32 +0100 Subject: [PATCH 3/3] Bump actions Signed-off-by: Stephen Finucane --- .github/workflows/ci.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 15e48bb..8a2d4e0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,9 +14,9 @@ jobs: python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] steps: - name: Checkout source code - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v5 + uses: actions/setup-python@v7 with: python-version: ${{ matrix.python }} - name: Install dependencies @@ -29,11 +29,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source code - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v7 with: - python-version: '3.13' + python-version: '3.x' - name: Install dependencies run: python -m pip install tox - name: Run linters (via tox) @@ -51,13 +51,13 @@ jobs: id-token: write steps: - name: Checkout source code - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v7 with: - python-version: '3.13' + python-version: '3.x' - name: Install dependencies run: python -m pip install build - name: Build a binary wheel and a source tarball