Skip to content

Commit

Permalink
Merge pull request #141 from sbidoul/min_version
Browse files Browse the repository at this point in the history
Support `--min-version`, `tool.pip-deepfreeze.min_version`
  • Loading branch information
sbidoul authored Feb 24, 2024
2 parents a65f5e8 + fa25b38 commit 009efcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Global options
python environment to work on. Defaults to the
'py' or 'python' executable found in PATH.
-r, --project-root DIRECTORY The project root directory. [default: .]
--min-version VERSION Minimum version of pip-deepfreeze required.
--version Show the version and exit.
-v, --verbose
--install-completion Install completion for the current shell.
Expand Down
3 changes: 3 additions & 0 deletions news/95.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Declare minimum pip-deepfreeze version in ``pyproject.toml``.
pip-deepfreeze verifies its version according to `tool.pip-deepfreeze.min_version`,
so a project can ensure all contributors have the minmum required version.
15 changes: 15 additions & 0 deletions src/pip_deepfreeze/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import typer
from packaging.utils import canonicalize_name
from packaging.version import Version

from .pip import Installer
from .pyproject_toml import load_pyproject_toml
Expand Down Expand Up @@ -173,6 +174,12 @@ def callback(
resolve_path=True,
help="The project root directory.",
),
min_version: Optional[str] = typer.Option(
None,
"--min-version",
metavar="VERSION",
help="Minimum version of pip-deepfreeze required.",
),
version: bool = typer.Option(
None,
"--version",
Expand All @@ -183,6 +190,14 @@ def callback(
verbose: bool = typer.Option(False, "--verbose", "-v", show_default=False),
) -> None:
"""A simple pip freeze workflow for Python application developers."""
if min_version:
current_version = importlib.metadata.version("pip-deepfreeze")
if Version(current_version) < Version(min_version):
log_error(
f"pip-deepfreeze {min_version} or later is required. "
f"Current version is {current_version}."
)
raise typer.Exit(1)
# handle verbosity/quietness
if verbose:
increase_verbosity()
Expand Down

0 comments on commit 009efcd

Please sign in to comment.