From 498ad392386f9b7b1e60481a171280e779bd5ce9 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Sat, 2 Nov 2024 17:29:00 -0400 Subject: [PATCH] Fix issue caused by pkg_resources deprecation --- pcu/defaults.py | 12 +++++++++--- setup.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pcu/defaults.py b/pcu/defaults.py index 63fe1bb..8f4cb0f 100644 --- a/pcu/defaults.py +++ b/pcu/defaults.py @@ -1,4 +1,4 @@ -import pkg_resources +import importlib.resources from typing import Optional @@ -6,11 +6,16 @@ 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: @@ -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 + diff --git a/setup.py b/setup.py index 60d43ba..932f67a 100644 --- a/setup.py +++ b/setup.py @@ -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',