Skip to content

Commit

Permalink
Let --version output system details on python >= 3.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Feb 20, 2023
1 parent aab4731 commit 1f7c6de
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 46 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
This version is not released yet and is under active development.
```

- Let `--version` option output system details when run on `python >= 3.10`.

## {gh}`3.8.2 (2023-02-20) <compare/v3.8.1...v3.8.2>`

- Fix overlapping detection of `linux` and `wsl2` platforms.
Expand Down
12 changes: 3 additions & 9 deletions click_extra/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from __future__ import annotations

import os
import sys
from functools import partial
from pathlib import Path
from textwrap import dedent
Expand Down Expand Up @@ -368,6 +367,7 @@ def _create_config(filename, content):
r"debug: Search local file system.\n"
r"debug: No configuration file found.\n"
r"debug: \S+, version \S+\n"
r"debug: {.*}\n"
)


Expand All @@ -380,11 +380,5 @@ def _create_config(filename, content):
r"\x1b\[34mdebug: \x1b\[0mNo configuration file found.\n"
r"\x1b\[34mdebug: \x1b\[0m\x1b\[97m\S+\x1b\[0m,"
r" version \x1b\[32m\S+\x1b\[0m(\x1b\[90m)?\n"
)


# XXX Temporarily expect extra-env info for Python < 3.10 while we wait for
# https://github.com/mahmoud/boltons/issues/294 to be released upstream.
if sys.version_info[:2] < (3, 10):
default_debug_uncolored_log += r"debug: {.*}\n"
default_debug_colored_log += r"\x1b\[34mdebug: \x1b\[0m{.*}\x1b\[0m\n"
r"\x1b\[34mdebug: \x1b\[0m{.*}\x1b\[0m\n"
)
10 changes: 4 additions & 6 deletions click_extra/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import annotations

import re
import sys
from textwrap import dedent

import click
Expand Down Expand Up @@ -207,11 +206,10 @@ def test_integrated_version_value(invoke, all_command_cli):
result = invoke(all_command_cli, "--version", color=False)
assert result.exit_code == 0

regex_output = r"command-cli1, version 2021.10.08\n"
# XXX Temporarily skip displaying environment details for Python >= 3.10 while we
# wait for https://github.com/mahmoud/boltons/issues/294 to be released upstream.
if sys.version_info[:2] < (3, 10):
regex_output += r"{'.+'}\n"
regex_output = (
r"command-cli1, version 2021.10.08\n"
r"{'.+'}\n"
)
assert re.fullmatch(regex_output, result.output)

assert not result.stderr
Expand Down
6 changes: 1 addition & 5 deletions click_extra/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import re
import sys
from os.path import sep
from pathlib import Path

Expand Down Expand Up @@ -452,11 +451,8 @@ def test_conf_file_overrides_defaults(
rf"Load configuration matching {re.escape(str(conf_path))}\n"
r"debug: Verbosity set to DEBUG.\n"
r"debug: \S+, version \S+\n"
r"debug: {.*}\n"
)
# XXX Temporarily expect extra-env info for Python < 3.10 while we wait for
# https://github.com/mahmoud/boltons/issues/294 to be released upstream.
if sys.version_info[:2] < (3, 10):
debug_log += r"debug: {.*}\n"
assert re.fullmatch(debug_log, result.stderr)


Expand Down
23 changes: 10 additions & 13 deletions click_extra/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import re
import sys

import click
import pytest
Expand All @@ -42,12 +41,11 @@ def color_cli2():
result = invoke(color_cli2, "--version", color=True)
assert result.exit_code == 0

regex_output = r"\x1b\[97mcolor-cli2\x1b\[0m, version \x1b\[32m1.2.3.4"
# XXX Temporarily skip displaying environment details for Python >= 3.10 while we
# wait for https://github.com/mahmoud/boltons/issues/294 to be released upstream.
if sys.version_info[:2] < (3, 10):
regex_output += r"\x1b\[0m\x1b\[90m\n{'.+'}"
regex_output += r"\x1b\[0m\n"
regex_output = (
r"\x1b\[97mcolor-cli2\x1b\[0m, version \x1b\[32m1.2.3.4"
r"\x1b\[0m\x1b\[90m\n{'.+'}"
r"\x1b\[0m\n"
)
assert re.fullmatch(regex_output, result.output)

assert not result.stderr
Expand Down Expand Up @@ -85,12 +83,11 @@ def color_cli4():
result = invoke(color_cli4, "--version", params, color=True)
assert result.exit_code == 0

regex_output = r"\x1b\[97mcolor-cli4\x1b\[0m, version \x1b\[32m1.2.3.4"
# XXX Temporarily skip displaying environment details for Python >= 3.10 while we
# wait for https://github.com/mahmoud/boltons/issues/294 to be released upstream.
if sys.version_info[:2] < (3, 10):
regex_output += r"\x1b\[0m\x1b\[90m\n{'.+'}"
regex_output += r"\x1b\[0m\n"
regex_output = (
r"\x1b\[97mcolor-cli4\x1b\[0m, version \x1b\[32m1.2.3.4"
r"\x1b\[0m\x1b\[90m\n{'.+'}"
r"\x1b\[0m\n"
)
assert re.fullmatch(regex_output, result.output)

assert not result.stderr
Expand Down
7 changes: 2 additions & 5 deletions click_extra/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
else:
import importlib_metadata as metadata # type: ignore[import]

from boltons.ecoutils import get_profile
from click import Parameter, echo
from cloup import Context, Style, option

Expand Down Expand Up @@ -194,11 +195,7 @@ def __init__(
if self.version is None and self.package_name is None:
self.package_name = self.guess_package_name()

# XXX Temporarily skip displaying environment details for Python >= 3.10 while
# we wait for https://github.com/mahmoud/boltons/issues/294 to reach upstream.
if print_env_info and sys.version_info[:2] < (3, 10):
from boltons.ecoutils import get_profile

if print_env_info:
env_info = "\n" + str(get_profile(scrub=True))
if env_info_style:
env_info = env_info_style(env_info)
Expand Down
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ classifiers = [
# List of python versions and their support status:
# https://en.wikipedia.org/wiki/History_of_Python#Support
python = "^3.7"
boltons = "^21.0.0"
boltons = "^23.0.0"
click = "^8.1.1"
click-log = "^0.4.0"
cloup = "^2.0.0.post1"
Expand Down

0 comments on commit 1f7c6de

Please sign in to comment.