Skip to content

Commit

Permalink
Add compatibility with python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Mar 14, 2024
1 parent 84fc736 commit c8dee22
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tg/util/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ def get_dotted_filename(self, template_name, template_extension='.html'):

try:
exists = os.path.exists(importlib.import_module(package).__file__)
with importlib.resources.as_file(
importlib.resources.files(package).joinpath(resourcename)
) as f:
if hasattr(importlib.resources, "as_file"):
as_file_context = importlib.resources.as_file(
importlib.resources.files(package).joinpath(resourcename)
)
else:
# Compatibility with Python < 3.9
as_file_context = importlib.resources.path(
package, resourcename
)
with as_file_context as f:
if exists:
result = str(f)
else:
Expand Down

0 comments on commit c8dee22

Please sign in to comment.