Skip to content

Commit

Permalink
Change option name from --force to --overwrite-existing
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsmedstad committed Feb 16, 2024
1 parent f718daf commit 829b483
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/installer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _get_main_parser() -> argparse.ArgumentParser:
help="validate the wheel against certain part of its record (default=none)",
)
parser.add_argument(
"--force",
"--overwrite-existing",
action="store_true",
help="silently overwrite existing files",
)
Expand Down Expand Up @@ -106,7 +106,7 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None:
script_kind=get_launcher_kind(),
bytecode_optimization_levels=bytecode_levels,
destdir=args.destdir,
force=args.force,
overwrite_existing=args.overwrite_existing,
)
installer.install(source, destination, {})

Expand Down
8 changes: 4 additions & 4 deletions src/installer/destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
hash_algorithm: str = "sha256",
bytecode_optimization_levels: Collection[int] = (),
destdir: Optional[str] = None,
force: bool = False,
overwrite_existing: bool = False,
) -> None:
"""Construct a ``SchemeDictionaryDestination`` object.
Expand All @@ -129,15 +129,15 @@ def __init__(
:param destdir: A staging directory in which to write all files. This
is expected to be the filesystem root at runtime, so embedded paths
will be written as though this was the root.
:param force: silently overwrite existing files.
:param overwrite_existing: silently overwrite existing files.
"""
self.scheme_dict = scheme_dict
self.interpreter = interpreter
self.script_kind = script_kind
self.hash_algorithm = hash_algorithm
self.bytecode_optimization_levels = bytecode_optimization_levels
self.destdir = destdir
self.force = force
self.overwrite_existing = overwrite_existing

def _path_with_destdir(self, scheme: Scheme, path: str) -> str:
file = os.path.join(self.scheme_dict[scheme], path)
Expand Down Expand Up @@ -165,7 +165,7 @@ def write_to_fs(
- Hashes the written content, to determine the entry in the ``RECORD`` file.
"""
target_path = self._path_with_destdir(scheme, path)
if not self.force and os.path.exists(target_path):
if not self.overwrite_existing and os.path.exists(target_path):
message = f"File already exists: {target_path}"
raise FileExistsError(message)

Expand Down
12 changes: 7 additions & 5 deletions tests/test_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def destination(self, tmp_path):
return SchemeDictionaryDestination(scheme_dict, "/my/python", "posix")

@pytest.fixture()
def destination_force(self, tmp_path):
def destination_overwrite_existing(self, tmp_path):
scheme_dict = {}
for scheme in SCHEME_NAMES:
full_path = tmp_path / scheme
if not full_path.exists():
full_path.mkdir()
scheme_dict[scheme] = str(full_path)
return SchemeDictionaryDestination(
scheme_dict, "/my/python", "posix", force=True
scheme_dict, "/my/python", "posix", overwrite_existing=True
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -98,11 +98,13 @@ def test_write_record_duplicate(self, destination):
with pytest.raises(FileExistsError):
destination.write_file("data", "my_data.bin", io.BytesIO(b"my data"), False)

def test_write_record_duplicate_with_force(self, destination_force):
destination_force.write_file(
def test_write_record_duplicate_with_overwrite_existing(
self, destination_overwrite_existing
):
destination_overwrite_existing.write_file(
"data", "my_data.bin", io.BytesIO(b"my data"), False
)
destination_force.write_file(
destination_overwrite_existing.write_file(
"data", "my_data.bin", io.BytesIO(b"my data"), False
)

Expand Down

0 comments on commit 829b483

Please sign in to comment.