Skip to content

Commit

Permalink
Keep existing files in index when updating a package with --force (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo De Wint authored Jan 14, 2020
1 parent 467996e commit 3247bf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions s3pypi/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ def to_html(self):
return self.template.render({"packages": self.packages})

def add_package(self, package, force=False):
if force:
self.packages.discard(package)
elif any(p.version == package.version for p in self.packages):
existing = next(
(p for p in self.packages if p.version == package.version), None
)
if existing and force:
self.packages.discard(existing)
package = Package(str(package), existing.files | package.files)
elif existing:
raise S3PyPiError(
"%s already exists! You should use a different version (use --force to override)."
% package
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def test_add_package_force():

index = Index([pkg1])
index.add_package(pkg2, force=True)
assert index.packages == {pkg2}

assert len(index.packages) == 1
assert next(iter(index.packages)).files == {"foo", "bar"}


def test_directory_normalize_package_name():
Expand Down

0 comments on commit 3247bf9

Please sign in to comment.