Skip to content

Commit

Permalink
ENH: remove --color=always from requirements files (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Mar 13, 2024
1 parent ca39b3f commit 5a77576
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ runs:
uv pip install --color=always --system update-pip-constraints@git+https://github.com/ComPWA/update-pip-constraints@v1
shell: bash

- run: update-pip-constraints --color
- run: update-pip-constraints
shell: bash
env:
FORCE_COLOR: "1"
TERM: ANSI

- name: Show git diff
run: git diff --color --unified=0
Expand Down
22 changes: 4 additions & 18 deletions src/update_pip_constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@

def main(argv: Optional[Sequence[str]] = None) -> int:
parser = ArgumentParser(description="Update pip constraints file")
parser.add_argument(
"--color",
action="store_true",
default=False,
help="Force output to be colorized or not, instead of auto-detecting color support",
)
parser.add_argument(
"-p",
"--python-version",
Expand All @@ -46,12 +40,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
"setuptools",
*_get_main_packages(),
]
exit_code = update_constraints_file_py36(output_file, excludes, args.color)
exit_code = update_constraints_file_py36(output_file, excludes)
else:
excludes = ["setuptools"]
exit_code = update_constraints_file(
output_file, python_version, excludes, args.color
)
exit_code = update_constraints_file(output_file, python_version, excludes)
if exit_code != 0:
msg = "There were issues running pip-compile"
raise RuntimeError(msg)
Expand Down Expand Up @@ -116,15 +108,14 @@ def _form_constraint_file_path(python_version: str) -> Path:


def update_constraints_file(
output_file: Path, python_version: str, unsafe_packages: List[str], use_color: bool
output_file: Path, python_version: str, unsafe_packages: List[str]
) -> int:
import subprocess # noqa: PLC0415, S404

if not __uses_pyproject():
msg = "Package has to be configured with pyproject.toml"
raise ValueError(msg)
output_file.parent.mkdir(exist_ok=True)
color_args = ["--color=always"] if use_color else []
command_arguments = [
"uv",
"pip",
Expand All @@ -133,7 +124,6 @@ def update_constraints_file(
"-o",
str(output_file),
"--all-extras",
*color_args,
"--no-annotate",
f"--python-version={python_version}",
"--upgrade",
Expand All @@ -144,9 +134,7 @@ def update_constraints_file(
return subprocess.check_call(command_arguments) # noqa: S603


def update_constraints_file_py36(
output_file: Path, unsafe_packages: List[str], use_color: bool
) -> int:
def update_constraints_file_py36(output_file: Path, unsafe_packages: List[str]) -> int:
from piptools.scripts import compile # type: ignore[import] # noqa: PLC0415

if sys.version_info < (3, 8):
Expand All @@ -156,13 +144,11 @@ def update_constraints_file_py36(

print("Resolving dependencies with pip-tools...") # noqa: T201
output_file.parent.mkdir(exist_ok=True)
color_args = ["--color"] if use_color else []
command_arguments = [
"-o",
output_file,
"--extra",
"dev",
*color_args,
"--no-annotate",
"--strip-extras",
"--upgrade",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_update_pip_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_update_constraints_file_py36():
this_directory = Path(__file__).parent.absolute()
output_file = this_directory / "constraints.txt"
with pytest.raises(SystemExit) as error:
update_constraints_file_py36(output_file, unsafe_packages=[], use_color=True)
update_constraints_file_py36(output_file, unsafe_packages=[])
assert error.type is SystemExit
assert error.value.code == 0
with open(output_file) as stream:
Expand Down

0 comments on commit 5a77576

Please sign in to comment.