Skip to content

Commit

Permalink
Use pathlib.Path objects internally
Browse files Browse the repository at this point in the history
It is the best practice nowadays. Paths are only converted to strings for text representation, like when logging.
  • Loading branch information
webknjaz committed Jun 13, 2023
1 parent 06fb793 commit 9ef5f8f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pip._internal.req.constructors import install_req_from_line
from pip._internal.utils.misc import redact_auth_from_url

from pathlib import Path
from .._compat import parse_requirements
from ..cache import DependencyCache
from ..exceptions import NoCandidateFound, PipToolsError
Expand Down Expand Up @@ -356,7 +357,7 @@ def cli(
emit_index_url: bool,
emit_options: bool,
unsafe_package: tuple[str, ...],
config: str | None,
config: Path | None,
) -> None:
"""
Compiles requirements.txt from requirements.in, pyproject.toml, setup.cfg,
Expand Down Expand Up @@ -409,7 +410,7 @@ def cli(
)

if config:
log.info(f"Using pip-tools configuration defaults found in '{config}'.")
log.info(f"Using pip-tools configuration defaults found in '{config !s}'.")

if resolver_name == "legacy":
log.warning(
Expand Down
5 changes: 3 additions & 2 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pip._internal.metadata import get_environment

from .. import sync
from pathlib import Path
from .._compat import parse_requirements
from .._compat.pip_compat import Distribution
from ..exceptions import PipToolsError
Expand Down Expand Up @@ -120,7 +121,7 @@ def cli(
client_cert: str | None,
src_files: tuple[str, ...],
pip_args: str | None,
config: str | None,
config: Path | None,
) -> None:
"""Synchronize virtual environment with requirements.txt."""
log.verbosity = verbose - quiet
Expand All @@ -146,7 +147,7 @@ def cli(
sys.exit(2)

if config:
log.info(f"Using pip-tools configuration defaults found in '{config}'.")
log.info(f"Using pip-tools configuration defaults found in '{config !s}'.")

if python_executable:
_validate_python_executable(python_executable)
Expand Down
4 changes: 2 additions & 2 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def parse_requirements_from_wheel_metadata(

def callback_config_file_defaults(
ctx: click.Context, param: click.Parameter, value: str | None
) -> str | None:
) -> Path | None:
"""
Returns the path to the config file with defaults being used, or `None` if no such file is
found.
Expand Down Expand Up @@ -570,7 +570,7 @@ def callback_config_file_defaults(
defaults.update(config)

ctx.default_map = defaults
return str(config_file)
return config_file


def select_config_file(src_files: tuple[str, ...]) -> Path | None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_callback_config_file_defaults(pyproject_param, new_default, make_config
ctx = Context(compile_cli)
ctx.params["src_files"] = (str(config_file),)
found_config_file = callback_config_file_defaults(ctx, "config", None)
assert found_config_file == str(config_file)
assert found_config_file == config_file
# Make sure the default has been updated
lookup_param = get_click_dest_for_option(pyproject_param)
assert ctx.default_map[lookup_param] == new_default
Expand Down

0 comments on commit 9ef5f8f

Please sign in to comment.