Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tarfile-warnings due to PEP 706 #722

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fusesoc/provider/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from fusesoc.provider.provider import Provider

_HAS_TAR_FILTER = hasattr(tarfile, "tar_filter") # Requires Python 3.12

logger = logging.getLogger(__name__)

if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -41,5 +43,10 @@ def _checkout(self, local_dir):

# Ugly hack to get the first part of the directory name of the extracted files
tmp = t.getnames()[0]
t.extractall(cache_root)

extraction_arguments = {"path": cache_root}
if _HAS_TAR_FILTER:
extraction_arguments["filter"] = "data"
t.extractall(**extraction_arguments)

os.rename(os.path.join(cache_root, tmp), os.path.join(cache_root, core))
7 changes: 6 additions & 1 deletion fusesoc/provider/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from fusesoc.provider.provider import Provider

_HAS_TAR_FILTER = hasattr(tarfile, "tar_filter") # Requires Python 3.12


class Url(Provider):
def _checkout(self, local_dir):
Expand All @@ -44,7 +46,10 @@ def _checkout(self, local_dir):
filetype = self.config.get("filetype")
if filetype == "tar":
t = tarfile.open(filename)
t.extractall(local_dir)
extraction_arguments = {"path": local_dir}
if _HAS_TAR_FILTER:
extraction_arguments["filter"] = "data"
t.extractall(**extraction_arguments)
elif filetype == "zip":
with zipfile.ZipFile(filename, "r") as z:
z.extractall(local_dir)
Expand Down
Loading