Skip to content

Commit

Permalink
More fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp committed Jan 13, 2024
1 parent 6aed4d3 commit 0e9e78d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions partcad/src/partcad/project_factory_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

import hashlib
import inspect
import os
import requests
import tarfile
Expand Down Expand Up @@ -67,20 +68,27 @@ def _extract(self, tarball_url, cache_dir=None):
try:
os.makedirs(cache_path)

if not self.import_rel_path is None:
filter = lambda member, _: (
member if member.name.startswith(self.import_rel_path) else None
)
else:
filter = lambda member, _: member

auth = None
if not (self.auth_user is None or self.auth_pass is None):
auth = (self.auth_user, self.auth_pass)
with requests.get(
tarball_url, stream=True, auth=auth
) as rx, tarfile.open(fileobj=rx.raw, mode="r:gz") as tarobj:
tarobj.extractall(cache_path, filter=filter)
args = inspect.getfullargspec(tarobj.extractall)

if "filter" in args.args:
if not self.import_rel_path is None:
filter = lambda member, _: (
member
if member.name.startswith(self.import_rel_path)
else None
)
else:
filter = lambda member, _: member

tarobj.extractall(cache_path, filter=filter)
else:
tarobj.extractall(cache_path)
except Exception as e:
raise RuntimeError(f"Failed to download the tarball: {e}")

Expand Down

0 comments on commit 0e9e78d

Please sign in to comment.