Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ 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
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
Expand All @@ -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)
Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion click_man/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"]
Expand Down
47 changes: 46 additions & 1 deletion tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading