Skip to content

Commit

Permalink
Replace pkg_resources with importlib backports
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Feb 1, 2024
1 parent c02d385 commit 9cfcd0c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions reprounzip/reprounzip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
This contains :func:`~reprounzip.reprounzip.main`, which is the entry point
declared to setuptools. It is also callable directly.
It dispatchs to plugins registered through pkg_resources as entry point
It dispatchs to plugins registered through importlib.metadata as entry point
``reprounzip.unpackers``.
"""

import argparse
from importlib_metadata import entry_points
import locale
import logging
from pkg_resources import iter_entry_points
import sys
import traceback

Expand All @@ -35,7 +35,7 @@


def get_plugins(entry_point_name):
for entry_point in iter_entry_points(entry_point_name):
for entry_point in entry_points().select(group=entry_point_name):
try:
func = entry_point.load()
except Exception:
Expand Down
9 changes: 4 additions & 5 deletions reprounzip/reprounzip/unpackers/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import copy
import functools
import logging
import importlib_resources
import itertools
import os
from pathlib import Path, PurePosixPath
import pickle
import pkg_resources
import random
import re
import shutil
Expand Down Expand Up @@ -131,10 +131,9 @@ def busybox_url(arch):
def rpzsudo_binary(arch):
"""Gets the rpzsudo file given the architecture.
"""
return pkg_resources.resource_stream(
__name__.split('.', 1)[0],
'rpzsudo-%s' % arch,
)
files = importlib_resources.files(__name__.split('.', 1)[0])
ref = files.joinpath('rpzsudo-%s' % arch)
return ref.open('rb')


def rpztar_url(arch):
Expand Down
2 changes: 2 additions & 0 deletions reprounzip/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
with io.open('README.rst', encoding='utf-8') as fp:
description = fp.read()
req = [
'importlib-metadata',
'importlib-resources',
'packaging',
'PyYAML',
'usagestats>=1.0.1',
Expand Down
8 changes: 3 additions & 5 deletions reprozip-core/reprozip_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
from datetime import datetime
import functools
import gzip
import importlib_resources
import json
import logging
import logging.handlers
import os
import packaging.version
from pathlib import Path, PurePosixPath
import pkg_resources
import shutil
import sys
import tarfile
Expand Down Expand Up @@ -1001,7 +1001,5 @@ def submit_usage_report(**kwargs):
def get_reprozip_ca_certificate():
"""Gets the ReproZip CA certificate filename.
"""
return Path(pkg_resources.resource_filename(
__name__.split('.', 1)[0],
'reprozip-ca.crt',
))
files = importlib_resources.files(__name__.split('.', 1)[0])
return files.joinpath('reprozip-ca.crt')
1 change: 1 addition & 0 deletions reprozip-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with io.open('README.rst', encoding='utf-8') as fp:
description = fp.read()
req = [
'importlib-resources',
'packaging',
'PyYAML',
'usagestats>=1.0.1',
Expand Down
4 changes: 2 additions & 2 deletions reprozip/reprozip/tracer/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import contextlib
import distro
from collections import defaultdict
from importlib_metadata import entry_points
from itertools import count
import logging
import os
from pathlib import Path, PurePosixPath
from pkg_resources import iter_entry_points
import platform
import shutil
import sqlite3
Expand Down Expand Up @@ -103,7 +103,7 @@ def to_file(self):


def run_filter_plugins(files, input_files):
for entry_point in iter_entry_points('reprozip.filters'):
for entry_point in entry_points().select(group='reprozip.filters'):
func = entry_point.load()
name = entry_point.name

Expand Down
1 change: 1 addition & 0 deletions reprozip/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
with io.open('README.rst', encoding='utf-8') as fp:
description = fp.read()
req = [
'importlib-metadata',
'PyYAML',
'usagestats>=1.0.1',
'requests',
Expand Down

0 comments on commit 9cfcd0c

Please sign in to comment.