Skip to content

Commit

Permalink
Merge pull request #206 from neutrinoceros/drop_3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros authored Jul 18, 2023
2 parents fcdca57 + fba8f87 commit 87d909d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 46 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
os:
- ubuntu-latest
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
include:
Expand Down Expand Up @@ -103,7 +101,7 @@ jobs:
# to make sure we're not using unparseable syntax,
# and also run on the most recent version possible to make sure
# the code typechecks also there
- '3.8'
- '3.10'
- '3.11'

steps:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# wxc

[![PyPI](https://img.shields.io/pypi/v/wxc.svg?logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/wxc/)
[![PyPI](https://img.shields.io/badge/requires-Python%20≥%203.8-blue?logo=python&logoColor=white)](https://pypi.org/project/wxc/)
[![](https://img.shields.io/badge/contributions-welcome-brightgreen)](https://github.com/neutrinoceros/wxc/pulls)

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/neutrinoceros/wxc/main.svg)](https://results.pre-commit.ci/latest/github/neutrinoceros/wxc/main)
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"rich>=10.13.0",
"stdlib-list>=0.8;python_version < \"3.10\"",
]
dynamic = ["version"]

Expand Down Expand Up @@ -102,7 +101,7 @@ omit = [
parallel = true

[tool.mypy]
python_version = "3.8"
python_version = "3.10"
show_error_codes = true
pretty = true
warn_return_any = true
Expand Down
24 changes: 9 additions & 15 deletions src/wxc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
from functools import lru_cache
from types import BuiltinFunctionType

if sys.version_info >= (3, 10):

def in_stdlib(package_name: str) -> bool:
return package_name in sys.stdlib_module_names

else:
from stdlib_list import in_stdlib # type: ignore

from wxc.levenshtein import levenshtein_distance

if False:
# typecheck only
from typing import Any # type: ignore [unreachable]
from collections.abc import Iterable # type: ignore [unreachable]
from typing import Any


# sorted by decreasing order of priority
VERSION_ATTR_LOOKUP_TABLE = ("__version__", "VERSION", "version")
Expand All @@ -45,7 +39,7 @@ def get_builtin_obj(name: str):


def get_suggestions(
candidates: list[str], target: str, *, max_dist: int = sys.maxsize
candidates: Iterable[str], target: str, *, max_dist: int = sys.maxsize
) -> list[str]:
suggestions: dict[int, list[str]] = defaultdict(list)
minimal_distance: int = max_dist
Expand Down Expand Up @@ -120,7 +114,7 @@ def get_sourcefile(obj):
if inspect.ismodule(obj) or is_builtin_func(obj):
raise
if isinstance(obj, property):
return get_sourcefile()
raise
return get_sourcefile(inspect.getmodule(obj))
return file

Expand Down Expand Up @@ -149,7 +143,7 @@ def get_version(package_name: str) -> str:
except md.PackageNotFoundError:
pass

if in_stdlib(package_name):
if package_name in sys.stdlib_module_names:
from platform import python_version

return f"Python {python_version()}"
Expand All @@ -169,9 +163,9 @@ def get_full_data(name: str) -> dict:
except RecursionError:
pass
except TypeError:
# as of Python 3.9, inspect.getfile doesn't have support for properties
# as of Python 3.11, inspect.getfile doesn't have support for properties
# but we're not making this a hard failure in case it is added in the future
# and we faillback on finding out the sourcefile of the class itself
# and we fallback to finding out the sourcefile of the class itself
if not isinstance(obj, property):
raise
else:
Expand All @@ -190,6 +184,6 @@ def get_full_data(name: str) -> dict:
except LookupError:
pass

data["in_stdlib"] = in_stdlib(package_name)
data["in_stdlib"] = package_name in sys.stdlib_module_names

return data
17 changes: 5 additions & 12 deletions src/wxc/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import sys
from argparse import ArgumentParser

Expand Down Expand Up @@ -95,16 +93,11 @@ def main(argv: list[str] | None = None) -> int:
except ImportError:
package_name = args.name.partition(".")[0]
msg = f"no installed package with name {package_name!r}"
if sys.version_info >= (3, 10):
# the standard library in Python >= 3.10 is the only subset of available packages
# for which we have a computationally cheap way to retrieve a list.
suggestions = get_suggestions(
sys.builtin_module_names, package_name, max_dist=2
)
if len(suggestions) == 1:
msg += f". Did you mean {suggestions[0]!r} ?"
else:
pass
suggestions = get_suggestions(
sys.builtin_module_names, package_name, max_dist=2
)
if len(suggestions) == 1:
msg += f". Did you mean {suggestions[0]!r} ?"
progress.stop()
print_err(msg)
return 1
Expand Down
17 changes: 5 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ def test_stdlib_typos_in_module_name(capsys):
# rich may output an unspecified amount of newlines
# that don't actually affect the result visually
assert out.strip() == ""
if sys.version_info >= (3, 10):
assert (
err == "ERROR no installed package with name 'sis'. Did you mean 'sys' ?\n"
)
else:
assert err == "ERROR no installed package with name 'sis'\n"
assert err == "ERROR no installed package with name 'sis'. Did you mean 'sys' ?\n"


def test_non_existing_member(capsys):
Expand All @@ -76,12 +71,10 @@ def test_non_existing_member(capsys):
# rich may output an unspecified amount of newlines
# that don't actually affect the result visually
assert out.strip() == ""
assert (
# not matching exact results since they are different between Python 3.9 and 3.10
err.startswith(
"ERROR module 'pathlib' has no attribute 'nothing'."
" Here are the closest matches:"
)

assert err.startswith(
"ERROR module 'pathlib' has no attribute 'nothing'."
" Here are the closest matches:"
)


Expand Down

0 comments on commit 87d909d

Please sign in to comment.