|
2 | 2 |
|
3 | 3 | import collections |
4 | 4 | import copy |
5 | | -import functools |
6 | 5 | import itertools |
7 | 6 | import json |
8 | 7 | import os |
@@ -366,6 +365,12 @@ def get_compile_command(click_ctx: click.Context) -> str: |
366 | 365 | if option_long_name in COMPILE_EXCLUDE_OPTIONS: |
367 | 366 | continue |
368 | 367 |
|
| 368 | + # Exclude config option if it's the default one |
| 369 | + if option_long_name == "--config": |
| 370 | + default_config = select_config_file(click_ctx.params.get("src_files", ())) |
| 371 | + if value == default_config: |
| 372 | + continue |
| 373 | + |
369 | 374 | # Skip options without a value |
370 | 375 | if option.default is None and not value: |
371 | 376 | continue |
@@ -594,7 +599,14 @@ def select_config_file(src_files: tuple[str, ...]) -> Path | None: |
594 | 599 | ), |
595 | 600 | None, |
596 | 601 | ) |
597 | | - return config_file_path |
| 602 | + if config_file_path is None: |
| 603 | + return None |
| 604 | + |
| 605 | + return ( |
| 606 | + config_file_path.relative_to(working_directory) |
| 607 | + if is_path_relative_to(config_file_path, working_directory) |
| 608 | + else config_file_path |
| 609 | + ) |
598 | 610 |
|
599 | 611 |
|
600 | 612 | # Some of the defined click options have different `dest` values than the defaults |
@@ -628,7 +640,6 @@ def get_click_dest_for_option(option_name: str) -> str: |
628 | 640 | ] |
629 | 641 |
|
630 | 642 |
|
631 | | -@functools.lru_cache() |
632 | 643 | def parse_config_file(config_file: Path) -> dict[str, Any]: |
633 | 644 | try: |
634 | 645 | config = tomllib.loads(config_file.read_text(encoding="utf-8")) |
@@ -656,3 +667,14 @@ def parse_config_file(config_file: Path) -> dict[str, Any]: |
656 | 667 | original_option, f"Config key '{original_option}' must be a list" |
657 | 668 | ) |
658 | 669 | return piptools_config |
| 670 | + |
| 671 | + |
| 672 | +def is_path_relative_to(path1: Path, path2: Path) -> bool: |
| 673 | + """Return True if ``path1`` is relative to ``path2``.""" |
| 674 | + # TODO: remove this function in favor of Path.is_relative_to() |
| 675 | + # when we drop support for Python 3.8 |
| 676 | + try: |
| 677 | + path1.relative_to(path2) |
| 678 | + except ValueError: |
| 679 | + return False |
| 680 | + return True |
0 commit comments