Skip to content

Commit

Permalink
Removed importlib_resources dependency when using python < 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
jooste committed Dec 7, 2022
1 parent f0211cf commit a501855
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 19 additions & 3 deletions bluesky/pathfinder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
''' BlueSky resource access '''
import sys
import shutil
import itertools
from pathlib import Path
Expand All @@ -10,8 +9,25 @@
from importlib.readers import MultiplexedPath
except ImportError:
# Python < 3.9 only provides deprecated resources API
from importlib_resources import files
from importlib_resources.readers import MultiplexedPath
from importlib.resources import path
def files(package):
res = '.'
if '.' in package:
package, res = package.split('.', 1)
return path(package, res)

class MultiplexedPath:
def __init__(self, *paths) -> None:
self._paths = list(map(Path, paths))
def iterdir(self):
visited = []
for path in self._paths:
for file in path.iterdir():
if file.name in visited:
continue
visited.append(file.name)
yield file



class ResourcePath(MultiplexedPath):
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def get_numpy_include():
with open(os.path.join(here, 'requirements.txt'), encoding='utf-8') as f:
install_requires = f.readlines()

# If Python version < 3.9, add importlib_resources requirement
if sys.version_info.major == 3 and sys.version_info.minor < 9:
install_requires.append('importlib_resources')

# get extra requirements from setup.cfg
parser = configparser.ConfigParser()
parser.read('%s/setup.cfg' % here)
Expand Down

0 comments on commit a501855

Please sign in to comment.