Skip to content

Commit

Permalink
Remove deprecated use of pkg_resources (#265)
Browse files Browse the repository at this point in the history
* Change from pkg_resources to importlib-metadata

In a backwards compatible way for 3.6 for now

Fixes #253
  • Loading branch information
tfoote authored Jan 26, 2024
1 parent cd919bf commit 998761f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/basic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, '3.10']
python-version: ['3.8', 3.x]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, '3.10']
python-version: [3.8, '3.x']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import os
from setuptools import setup

# importlib-metadata dependency can be removed when RHEL8 and other 3.6 based systems are not in support cycles

install_requires = [
'empy',
'importlib-metadata; python_version < "3.8"',
'pexpect',
'packaging',
'urllib3',
Expand Down
29 changes: 25 additions & 4 deletions src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import re
import sys

import pkg_resources
# importlib-metadata dependency can be removed when RHEL8 and other 3.6 based systems are not in support cycles
if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata


import pkgutil
from requests.exceptions import ConnectionError
import shlex
Expand Down Expand Up @@ -455,11 +461,26 @@ def generate_dockerfile(extensions, args_dict, base_image):
return dockerfile_str


def list_entry_points():
entry_points = importlib_metadata.entry_points()
if hasattr(entry_points, 'select'):
styles_groups = entry_points.select(group='flake8_import_order.styles')
else:
styles_groups = entry_points.get('flake8_import_order.styles', [])

return styles_groups

def list_plugins(extension_point='rocker.extensions'):

all_entry_points = importlib_metadata.entry_points()
if hasattr(all_entry_points, 'select'):
rocker_extensions = all_entry_points.select(group=extension_point)
else:
rocker_extensions = all_entry_points.get(extension_point, [])

unordered_plugins = {
entry_point.name: entry_point.load()
for entry_point
in pkg_resources.iter_entry_points(extension_point)
for entry_point in rocker_extensions
}
# Order plugins by extension point name for consistent ordering below
plugin_names = list(unordered_plugins.keys())
Expand All @@ -468,4 +489,4 @@ def list_plugins(extension_point='rocker.extensions'):


def get_rocker_version():
return pkg_resources.require('rocker')[0].version
return importlib_metadata.version('rocker')

0 comments on commit 998761f

Please sign in to comment.