Replaced pkg_resources with importlib.resources
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import pkg_resources
|
||||
from importlib.resources import files as resource_files
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import re_path, include
|
||||
@@ -65,7 +65,7 @@ class ModuleMeta:
|
||||
|
||||
def _load_from_package(self):
|
||||
package_name = self._package_name
|
||||
json_text = pkg_resources.resource_string(package_name, self._json_file)
|
||||
json_text = resource_files(package_name).joinpath(self._json_file).read_bytes()
|
||||
meta_dict = json.loads(json_text)
|
||||
meta_dict['package'] = package_name
|
||||
self.load_from_dict(meta_dict)
|
||||
|
||||
@@ -2,7 +2,7 @@ import argparse
|
||||
import os
|
||||
import posix
|
||||
import sys
|
||||
import pkg_resources
|
||||
from importlib.resources import files as resource_files
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
from dav_base.config.modules import DJANGO_MAIN_MODULE, ModuleConfig
|
||||
@@ -94,20 +94,20 @@ class AdminCommand: # pylint: disable=too-few-public-methods
|
||||
config = ModuleConfig(django_base_dir=django_base_dir)
|
||||
config.save()
|
||||
|
||||
input_file = os.path.join('django_project_config', 'additional_settings.py')
|
||||
input_file = resource_files(__package__).joinpath('django_project_config', 'additional_settings.py')
|
||||
output_file = os.path.join(django_base_dir, django_main_module, 'settings.py')
|
||||
with open(output_file, 'ab') as f:
|
||||
f.write(pkg_resources.resource_string(__package__, input_file))
|
||||
f.write(input_file.read_bytes())
|
||||
|
||||
input_file = os.path.join('django_project_config', 'urls.py')
|
||||
input_file = resource_files(__package__).joinpath('django_project_config', 'urls.py')
|
||||
output_file = os.path.join(django_base_dir, django_main_module, 'urls.py')
|
||||
with open(output_file, 'wb') as f:
|
||||
f.write(pkg_resources.resource_string(__package__, input_file))
|
||||
f.write(input_file.read_bytes())
|
||||
|
||||
input_file = os.path.join('django_project_config', 'settings-dav_base.py')
|
||||
input_file = resource_files(__package__).joinpath('django_project_config', 'settings-dav_base.py')
|
||||
output_file = os.path.join(django_base_dir, django_main_module, 'settings-dav_base.py')
|
||||
with open(output_file, 'wb') as f:
|
||||
f.write(pkg_resources.resource_string(__package__, input_file))
|
||||
f.write(input_file.read_bytes())
|
||||
|
||||
return posix.EX_OK
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
import pkg_resources
|
||||
from importlib.resources import files as resource_files
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
@@ -23,12 +23,12 @@ class Command(BaseCommand):
|
||||
raise CommandError('Module \'{}\' is already enabled'.format(module_name))
|
||||
|
||||
settings_file_name = 'settings-{}.py'.format(module_name)
|
||||
input_file = os.path.join('django_project_config', settings_file_name)
|
||||
if pkg_resources.resource_exists(module_name, input_file):
|
||||
input_file = resource_files(module_name).joinpath('django_project_config', settings_file_name)
|
||||
if input_file.is_file():
|
||||
output_file = os.path.join(django_base_dir, django_main_module, settings_file_name)
|
||||
if not os.path.exists(output_file):
|
||||
with open(output_file, 'wb') as f:
|
||||
f.write(pkg_resources.resource_string(module_name, input_file))
|
||||
f.write(input_file.read_bytes())
|
||||
|
||||
module_meta_obj = ModuleMeta(module_name)
|
||||
config.modules[module_name] = module_meta_obj
|
||||
|
||||
Reference in New Issue
Block a user