Skip to content

Commit

Permalink
Restructure project to a single-file format
Browse files Browse the repository at this point in the history
  • Loading branch information
realshouzy committed Jan 26, 2024
1 parent 55250e6 commit c468790
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 135 deletions.
100 changes: 85 additions & 15 deletions pip_review/_main.py → pip_review.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
8 changes: 0 additions & 8 deletions pip_review/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions pip_review/__main__.py

This file was deleted.

97 changes: 0 additions & 97 deletions pip_review/_constants.py

This file was deleted.

Empty file removed pip_review/py.typed
Empty file.
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__" }
Expand Down Expand Up @@ -104,6 +103,10 @@ ignore = [
"ERA001",
"EM101",
"TRY003",
"D100",
"D101",
"D102",
"D103",
"D107",
"UP035",
"UP036",
Expand All @@ -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]
Expand Down

0 comments on commit c468790

Please sign in to comment.