Skip to content

Commit

Permalink
Fix issue caused by pkg_resources deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
jma127 committed Nov 2, 2024
1 parent b69e2ad commit 498ad39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pcu/defaults.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import pkg_resources
import importlib.resources
from typing import Optional


_TOP_PACKAGE = __name__.rpartition('.')[0]


def exists_static(path: str) -> bool:
return pkg_resources.resource_exists(_TOP_PACKAGE, 'static/' + path)
try:
with importlib.resources.open_binary(_TOP_PACKAGE, 'static/' + path):
return True
except FileNotFoundError:
return False


def load_static(path: str) -> bytes:
return pkg_resources.resource_string(_TOP_PACKAGE, 'static/' + path)
with importlib.resources.open_binary(_TOP_PACKAGE, 'static/' + path) as file:
return file.read()


def default_settings_data() -> str:
Expand All @@ -21,3 +26,4 @@ def default_template(template: str) -> Optional[str]:
internal_path = 'default_templates/' + template
return load_static(internal_path).decode() \
if exists_static(internal_path) else None

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pcu',
version='0.1.3',
version='0.1.4',
description='Comprehensive suite for competitive programming.',
author='Jerry Ma',
author_email='jmnospam@mail.com',
Expand Down

0 comments on commit 498ad39

Please sign in to comment.