From c468790687fa752fde4348fa335c37915bff0a34 Mon Sep 17 00:00:00 2001 From: shouzy <82171453+realshouzy@users.noreply.github.com> Date: Sat, 27 Jan 2024 00:41:00 +0100 Subject: [PATCH] Restructure project to a single-file format --- pip_review/_main.py => pip_review.py | 100 +++++++++++++++++++++++---- pip_review/__init__.py | 8 --- pip_review/__main__.py | 8 --- pip_review/_constants.py | 97 -------------------------- pip_review/py.typed | 0 pyproject.toml | 16 +++-- 6 files changed, 94 insertions(+), 135 deletions(-) rename pip_review/_main.py => pip_review.py (82%) mode change 100755 => 100644 delete mode 100644 pip_review/__init__.py delete mode 100755 pip_review/__main__.py delete mode 100644 pip_review/_constants.py delete mode 100644 pip_review/py.typed diff --git a/pip_review/_main.py b/pip_review.py old mode 100755 new mode 100644 similarity index 82% rename from pip_review/_main.py rename to pip_review.py index 15758f3cd..cb6f447b3 --- a/pip_review/_main.py +++ b/pip_review.py @@ -1,38 +1,108 @@ -#!/usr/bin/env python3 -"""Main module.""" from __future__ import annotations +__version__: Final[str] = "1.4.0" +__title__: Final[str] = "pip-review" + + import argparse import json import logging +import re import subprocess # nosec import sys from functools import partial -from typing import TYPE_CHECKING, TextIO +from typing import TYPE_CHECKING, Final, TextIO import pip from packaging import version -from pip_review._constants import ( - COLUMNS, - DESCRIPTION, - EPILOG, - INSTALL_ONLY, - LIST_ONLY, - NAME_PATTERN, - PIP_CMD, - VERSION_PATTERN, -) - if sys.version_info >= (3, 12): # pragma: >=3.12 cover from typing import override else: # pragma: <3.12 cover from typing_extensions import override if TYPE_CHECKING: - import re from collections.abc import Callable +VERSION_PATTERN: Final[re.Pattern[str]] = re.compile( + version.VERSION_PATTERN, + re.VERBOSE | re.IGNORECASE, # necessary according to the `packaging` docs +) + +NAME_PATTERN: Final[re.Pattern[str]] = re.compile(r"[a-z0-9_-]+", re.IGNORECASE) + +EPILOG: Final[ + str +] = """ +Unrecognised arguments will be forwarded to pip list --outdated and +pip install, so you can pass things such as --user, --pre and --timeout +and they will do what you expect. See pip list -h and pip install -h +for a full overview of the options. +""" + +# parameters that pip list supports but not pip install +LIST_ONLY: Final[set[str]] = { + "l", + "local", + "path", + "format", + "not-required", + "exclude-editable", + "include-editable", +} + +# parameters that pip install supports but not pip list +INSTALL_ONLY: Final[set[str]] = { + "c", + "constraint", + "no-deps", + "t", + "target", + "platform", + "python-version", + "implementation", + "abi", + "root", + "prefix", + "b", + "build", + "src", + "U", + "upgrade", + "upgrade-strategy", + "force-reinstall", + "I", + "ignore-installed", + "ignore-requires-python", + "no-build-isolation", + "use-pep517", + "install-option", + "global-option", + "compile", + "no-compile", + "no-warn-script-location", + "no-warn-conflicts", + "no-binary", + "only-binary", + "prefer-binary", + "no-clean", + "require-hashes", + "progress-bar", +} + +# command that sets up the pip module of the current Python interpreter +PIP_CMD: Final[list[str]] = [sys.executable, "-m", "pip"] + +# nicer headings for the columns in the oudated package table +COLUMNS: Final[dict[str, str]] = { + "Package": "name", + "Version": "version", + "Latest": "latest_version", + "Type": "latest_filetype", +} + +DESCRIPTION: Final[str] = "Keeps your Python packages fresh." + def _parse_args() -> tuple[argparse.Namespace, list[str]]: parser: argparse.ArgumentParser = argparse.ArgumentParser( diff --git a/pip_review/__init__.py b/pip_review/__init__.py deleted file mode 100644 index 502f7f3b7..000000000 --- a/pip_review/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -"""``pip-review`` package.""" -from __future__ import annotations - -__version__: Final[str] = "1.4.0" -__title__: Final[str] = "pip-review" - - -from typing import Final diff --git a/pip_review/__main__.py b/pip_review/__main__.py deleted file mode 100755 index ebec952ba..000000000 --- a/pip_review/__main__.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env python3 -"""Run module as file.""" -from __future__ import annotations - -from pip_review._main import main - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pip_review/_constants.py b/pip_review/_constants.py deleted file mode 100644 index b34b8bcd2..000000000 --- a/pip_review/_constants.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Module defining and containing global constants.""" -from __future__ import annotations - -__all__: tuple[str, ...] = ( - "VERSION_PATTERN", - "NAME_PATTERN", - "EPILOG", - "LIST_ONLY", - "INSTALL_ONLY", - "PIP_CMD", - "COLUMNS", -) - -import re -import sys -from typing import Final - -from packaging import version - -VERSION_PATTERN: Final[re.Pattern[str]] = re.compile( - version.VERSION_PATTERN, - re.VERBOSE | re.IGNORECASE, # necessary according to the `packaging` docs -) - -NAME_PATTERN: Final[re.Pattern[str]] = re.compile(r"[a-z0-9_-]+", re.IGNORECASE) - -EPILOG: Final[ - str -] = """ -Unrecognised arguments will be forwarded to pip list --outdated and -pip install, so you can pass things such as --user, --pre and --timeout -and they will do what you expect. See pip list -h and pip install -h -for a full overview of the options. -""" - -# parameters that pip list supports but not pip install -LIST_ONLY: Final[set[str]] = { - "l", - "local", - "path", - "format", - "not-required", - "exclude-editable", - "include-editable", -} - -# parameters that pip install supports but not pip list -INSTALL_ONLY: Final[set[str]] = { - "c", - "constraint", - "no-deps", - "t", - "target", - "platform", - "python-version", - "implementation", - "abi", - "root", - "prefix", - "b", - "build", - "src", - "U", - "upgrade", - "upgrade-strategy", - "force-reinstall", - "I", - "ignore-installed", - "ignore-requires-python", - "no-build-isolation", - "use-pep517", - "install-option", - "global-option", - "compile", - "no-compile", - "no-warn-script-location", - "no-warn-conflicts", - "no-binary", - "only-binary", - "prefer-binary", - "no-clean", - "require-hashes", - "progress-bar", -} - -# command that sets up the pip module of the current Python interpreter -PIP_CMD: Final[list[str]] = [sys.executable, "-m", "pip"] - -# nicer headings for the columns in the oudated package table -COLUMNS: Final[dict[str, str]] = { - "Package": "name", - "Version": "version", - "Latest": "latest_version", - "Type": "latest_filetype", -} - -DESCRIPTION: Final[str] = "Keeps your Python packages fresh." diff --git a/pip_review/py.typed b/pip_review/py.typed deleted file mode 100644 index e69de29bb..000000000 diff --git a/pyproject.toml b/pyproject.toml index a3b8797ca..cce36d1cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ requires-python = ">=3.8" dynamic = ["version", "dependencies"] [project.urls] -Repository = "https://github.com/realshouzy/pip-review" +repository = "https://github.com/realshouzy/pip-review" [project.optional-dependencies] # keep in sync with requirements-dev.txt @@ -54,16 +54,15 @@ dev = [ ] [project.scripts] -pip-review = "pip_review._main:main" +pip-review = "pip_review:main" [tool.setuptools] -packages = ["pip_review"] license-files = ["LICENSE.txt"] zip-safe = false platforms = ["any"] -[tool.setuptools.package-data] -auto_file_sorter = ["py.typed"] +# [tool.setuptools.package-data] +# auto_file_sorter = ["py.typed"] [tool.setuptools.dynamic] version = { attr = "pip_review.__version__" } @@ -104,6 +103,10 @@ ignore = [ "ERA001", "EM101", "TRY003", + "D100", + "D101", + "D102", + "D103", "D107", "UP035", "UP036", @@ -123,8 +126,7 @@ required-imports = ["from __future__ import annotations"] convention = "pep257" [tool.pylint] -# C0115 and C0116 only disabled temporary -disable = ["R0903", "C0115", "C0116"] +disable = ["R0903", "C0114", "C0115", "C0116"] load-plugins = "pylint_pytest" [tool.bandit]