Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make py 3.12 work #142

Merged
merged 1 commit into from
Nov 1, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/rich-codex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
rich_codex:
if: github.repository_owner == 'ewels'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
2 changes: 1 addition & 1 deletion src/rich_click/_compat_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from importlib import metadata # type: ignore[import,unused-ignore]
except ImportError:
# Python < 3.8
import importlib_metadata as metadata # type: ignore[no-redef,import]
import importlib_metadata as metadata # type: ignore[no-redef,import-not-found]


click_version = metadata.version("click")
Expand Down
21 changes: 17 additions & 4 deletions src/rich_click/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from typing import Any, List, Optional

try:
from importlib.metadata import entry_points # type: ignore[import,unused-ignore]
from importlib import metadata # type: ignore[import,unused-ignore]
except ImportError:
# Support Python <3.8
from importlib_metadata import entry_points # type: ignore[import,no-redef]
# Python < 3.8
import importlib_metadata as metadata # type: ignore[no-redef,import-not-found]

import click
from rich.console import Console
Expand Down Expand Up @@ -73,6 +73,19 @@ def patch() -> None:
click.MultiCommand = RichMultiCommand # type: ignore[assignment,misc]


def entry_points(*, group: str) -> "metadata.EntryPoints": # type: ignore[name-defined]
"""entry_points function that is compatible with Python 3.7+."""
if sys.version_info >= (3, 10):
return metadata.entry_points(group=group)

epg = metadata.entry_points()

if sys.version_info < (3, 8) and hasattr(epg, "select"):
return epg.select(group=group)

return epg.get(group, [])


def main(args: Optional[List[str]] = None) -> Any:
"""
The [link=https://github.com/ewels/rich-click]rich-click[/] CLI provides attractive help output from any
Expand Down Expand Up @@ -100,7 +113,7 @@ def main(args: Optional[List[str]] = None) -> Any:
sys.exit(0)
else:
script_name = args[0]
scripts = {script.name: script for script in entry_points().get("console_scripts", [])}
scripts = {script.name: script for script in entry_points(group="console_scripts")}
if script_name in scripts:
# a valid script was passed
script = scripts[script_name]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from importlib import metadata # type: ignore[import,unused-ignore]
except ImportError:
# Python < 3.8
import importlib_metadata as metadata # type: ignore[no-redef,import]
import importlib_metadata as metadata # type: ignore[no-redef,import-not-found]


rich_version = version.parse(metadata.version("rich"))
Expand Down
Loading