diff --git a/concoursetools/cli/commands.py b/concoursetools/cli/commands.py index b3e3432..95edb80 100644 --- a/concoursetools/cli/commands.py +++ b/concoursetools/cli/commands.py @@ -17,10 +17,11 @@ cli = CLI() DEFAULT_PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}" +DEFAULT_RESOURCE_FILE = "concourse.py" @cli.register(allow_short={"executable", "class_name", "resource_file"}) -def assets(path: str, /, *, executable: str | None = None, resource_file: str = "concourse.py", +def assets(path: str, /, *, executable: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE, class_name: str | None = None) -> None: """ Create the assets script directory. @@ -49,7 +50,7 @@ def assets(path: str, /, *, executable: str | None = None, resource_file: str = @cli.register(allow_short={"executable", "class_name", "resource_file"}) def dockerfile(path: str, /, *, executable: str | None = None, image: str = "python", tag: str | None = None, - suffix: str | None = None, resource_file: str = "concourse.py", class_name: str | None = None, + suffix: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE, class_name: str | None = None, pip_args: str | None = None, include_rsa: bool = False, include_netrc: bool = False, encoding: str | None = None, no_venv: bool = False, dev: bool = False) -> None: """ @@ -182,7 +183,7 @@ def dockerfile(path: str, /, *, executable: str | None = None, image: str = "pyt @cli.register(allow_short={"executable", "class_name", "resource_file"}) -def legacy(path: str, /, *, executable: str | None = None, resource_file: str = "concourse.py", +def legacy(path: str, /, *, executable: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE, class_name: str | None = None, docker: bool = False, include_rsa: bool = False) -> None: """ Invoke the legacy CLI. diff --git a/concoursetools/cli/parser.py b/concoursetools/cli/parser.py index a6daa39..bdcd49a 100644 --- a/concoursetools/cli/parser.py +++ b/concoursetools/cli/parser.py @@ -355,7 +355,7 @@ def short_alias(self) -> str: @property @abstractmethod - def aliases(self) -> tuple[str, ...]: + def aliases(self) -> list[str]: """The aliases for the option.""" ... @@ -410,9 +410,9 @@ class PositionalArgument(Parameter[T]): :param description: An optional description of the argument. """ @property - def aliases(self) -> tuple[str, ...]: + def aliases(self) -> list[str]: """The aliases for the option.""" - return (self.name,) + return [self.name] def add_to_parser(self, parser: ArgumentParser) -> None: parser.add_argument(*self.aliases, type=self.param_type, help=self.description) @@ -433,10 +433,10 @@ class Option(Parameter[T]): allow_short: bool = False @property - def aliases(self) -> tuple[str, ...]: + def aliases(self) -> list[str]: if self.allow_short: - return (self.short_alias, self.long_alias) - return (self.long_alias,) + return [self.short_alias, self.long_alias] + return [self.long_alias] def add_to_parser(self, parser: ArgumentParser) -> None: parser.add_argument(*self.aliases, type=self.param_type, default=self.default, help=self.description) diff --git a/examples/build_status.py b/examples/build_status.py index 096e91f..2fb11b9 100644 --- a/examples/build_status.py +++ b/examples/build_status.py @@ -87,9 +87,8 @@ def __init__(self, repository: str | None = None, endpoint: str | None = None, else: endpoint = endpoint.rstrip("/") - if self.driver is Driver.CLOUD: - if repository is None: - raise ValueError("Must set repository when using Bitbucket Cloud.") + if self.driver is Driver.CLOUD and repository is None: + raise ValueError("Must set repository when using Bitbucket Cloud.") def publish_new_version(self, sources_dir: Path, build_metadata: BuildMetadata, repository: str, build_status: str, key: str | None = None, diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py index d708ba0..0ac382c 100644 --- a/tests/test_cli_commands.py +++ b/tests/test_cli_commands.py @@ -11,6 +11,7 @@ import unittest.mock from concoursetools.cli import cli +from concoursetools.cli.commands import DEFAULT_RESOURCE_FILE from concoursetools.colour import Colour, colourise @@ -26,7 +27,7 @@ def setUp(self) -> None: path_to_this_file = Path(__file__) path_to_test_resource_module = path_to_this_file.parent / "resource.py" - shutil.copyfile(path_to_test_resource_module, self.temp_dir / "concourse.py") + shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE) os.chdir(self.temp_dir) def tearDown(self) -> None: @@ -60,7 +61,7 @@ def setUp(self) -> None: path_to_this_file = Path(__file__) path_to_test_resource_module = path_to_this_file.parent / "resource.py" - shutil.copyfile(path_to_test_resource_module, self.temp_dir / "concourse.py") + shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE) self.dockerfile_path = self.temp_dir / "Dockerfile" self.assertFalse(self.dockerfile_path.exists()) @@ -115,7 +116,7 @@ def setUp(self) -> None: path_to_this_file = Path(__file__) path_to_test_resource_module = path_to_this_file.parent / "resource.py" - shutil.copyfile(path_to_test_resource_module, self.temp_dir / "concourse.py") + shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE) self.dockerfile_path = self.temp_dir / "Dockerfile" self.assertFalse(self.dockerfile_path.exists()) diff --git a/tests/test_cli_parsing.py b/tests/test_cli_parsing.py index 4a05d30..c442284 100644 --- a/tests/test_cli_parsing.py +++ b/tests/test_cli_parsing.py @@ -141,7 +141,7 @@ def test_generic_help_no_arguments(self) -> None: """).lstrip()) - def first_command_help(self) -> None: + def test_first_command_help(self) -> None: with self._mock_terminal_width(120): width, _ = shutil.get_terminal_size() self.assertGreaterEqual(width, 120) diff --git a/tests/test_examples.py b/tests/test_examples.py index 442e809..c3780a1 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -279,7 +279,7 @@ def test_file_downloads(self) -> None: self.assertDictEqual(self.expected_response, json.loads(folder_state["info.json"])) image_contents = folder_state["image.png"] - hashed_image_contents = hashlib.sha1(image_contents).hexdigest() + hashed_image_contents = hashlib.sha1(image_contents, usedforsecurity=False).hexdigest() self.assertEqual(hashed_image_contents, "22f545ac6b50163ce39bac49094c3f64e0858403") def test_file_downloads_without_files(self) -> None: diff --git a/tests/test_resource.py b/tests/test_resource.py index 7a6d515..3b2ba5b 100644 --- a/tests/test_resource.py +++ b/tests/test_resource.py @@ -735,7 +735,7 @@ def _build_test_resource_docker_image() -> str: # '3.14.0b1 (main, May 9 2025, 23:49:24) [GCC 12.2.0]' # ^^^^^^^^ tag, *_ = sys.version.split() - cli_commands.dockerfile(str(temp_dir), resource_file="concourse.py", class_name=TestResource.__name__, + cli_commands.dockerfile(str(temp_dir), resource_file=temporary_resource_file.name, class_name=TestResource.__name__, tag=tag, dev=True) stdout, _ = run_command("docker", ["build", ".", "-q"], cwd=temp_dir) diff --git a/tests/test_version.py b/tests/test_version.py index b0f8d9f..87c9e4b 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -118,7 +118,7 @@ def test_default_sorting(self) -> None: version_3 = BasicVersion("image.png") with self.assertRaises(TypeError): - sorted([version_1, version_2, version_3]) # type: ignore[type-var] + [version_1, version_2, version_3].sort() # type: ignore[call-arg] def test_complex_sorting(self) -> None: version_1 = ComplexVersion("file.txt")