Skip to content

Commit

Permalink
Updates around importlib_metadata for v1.0 (#48)
Browse files Browse the repository at this point in the history
* Move catalogue.py to module dir

* Update setup

* Add vendored importlib_metadata v3.2.0

* Move tests into package

* Backport changes from #41

* Check for select rather than to-be-deprecated SelectableGroups

* Set version to v1.0.1, update classifiers

* Update CI
  • Loading branch information
adrianeboyd authored Oct 7, 2022
1 parent 88bab21 commit ef4fd81
Show file tree
Hide file tree
Showing 10 changed files with 864 additions and 41 deletions.
79 changes: 53 additions & 26 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,48 @@ jobs:
- job: 'Test'
strategy:
matrix:
Python27Linux:
imageName: 'ubuntu-16.04'
python.version: '2.7'
Python27Mac:
imageName: 'macos-10.13'
python.version: '2.7'
Python35Linux:
imageName: 'ubuntu-16.04'
python.version: '3.5'
Python35Windows:
imageName: 'vs2017-win2016'
python.version: '3.5'
Python35Mac:
imageName: 'macos-10.13'
python.version: '3.5'
Python36Linux:
imageName: 'ubuntu-16.04'
imageName: 'ubuntu-latest'
python.version: '3.6'
Python36Windows:
imageName: 'vs2017-win2016'
python.version: '3.6'
Python36Mac:
imageName: 'macos-10.13'
imageName: 'windows-2019'
python.version: '3.6'
Python37Linux:
imageName: 'ubuntu-latest'
python.version: '3.7'
Python37Windows:
imageName: 'windows-latest'
python.version: '3.7'
Python37Mac:
imageName: 'macos-latest'
python.version: '3.7'
Python38Linux:
imageName: 'ubuntu-16.04'
imageName: 'ubuntu-latest'
python.version: '3.8'
Python38Windows:
imageName: 'vs2017-win2016'
imageName: 'windows-latest'
python.version: '3.8'
Python38Mac:
imageName: 'macos-10.13'
imageName: 'macos-latest'
python.version: '3.8'
Python39Linux:
imageName: 'ubuntu-latest'
python.version: '3.9'
Python39Windows:
imageName: 'windows-latest'
python.version: '3.9'
Python39Mac:
imageName: 'macos-latest'
python.version: '3.9'
Python310Linux:
imageName: 'ubuntu-latest'
python.version: '3.10'
Python310Windows:
imageName: 'windows-latest'
python.version: '3.10'
Python310Mac:
imageName: 'macos-latest'
python.version: '3.10'
maxParallel: 4
pool:
vmImage: $(imageName)
Expand All @@ -53,19 +62,37 @@ jobs:
architecture: 'x64'

- script: |
pip install -U -r requirements.txt
python -m pip install -U pip setuptools wheel
python -m pip install -U -r requirements.txt
python setup.py sdist
displayName: 'Build sdist'
- task: DeleteFiles@1
inputs:
contents: 'catalogue.py'
contents: 'catalogue'
displayName: 'Delete source directory'

- script: |
python -m pip freeze > installed.txt
python -m pip uninstall -y -r installed.txt
displayName: "Uninstall all packages"
- bash: |
SDIST=$(python -c "import os;print(os.listdir('./dist')[-1])" 2>&1)
pip install dist/$SDIST
displayName: 'Install from sdist'
- script: python -m pytest test_catalogue.py
- bash: |
python -c "import catalogue"
displayName: 'Test import'
- script: python -m pip install -U -r requirements.txt
displayName: "Install test requirements"

- script: python -m pytest --pyargs catalogue -Werror
displayName: 'Run tests'

- bash: |
pip install hypothesis
python -c "import catalogue; import hypothesis"
displayName: 'Test for conflicts'
12 changes: 9 additions & 3 deletions catalogue.py → catalogue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try: # Python 3.8
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata
from . import _importlib_metadata as importlib_metadata

if sys.version_info[0] == 2:
basestring_ = basestring # noqa: F821
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_entry_points(self):
RETURNS (Dict[str, Any]): Entry points, keyed by name.
"""
result = {}
for entry_point in AVAILABLE_ENTRY_POINTS.get(self.entry_point_namespace, []):
for entry_point in self._get_entry_points():
result[entry_point.name] = entry_point.load()
return result

Expand All @@ -135,11 +135,17 @@ def get_entry_point(self, name, default=None):
default (Any): The default value to return.
RETURNS (Any): The loaded entry point or the default value.
"""
for entry_point in AVAILABLE_ENTRY_POINTS.get(self.entry_point_namespace, []):
for entry_point in self._get_entry_points():
if entry_point.name == name:
return entry_point.load()
return default

def _get_entry_points(self):
if hasattr(AVAILABLE_ENTRY_POINTS, "select"):
return AVAILABLE_ENTRY_POINTS.select(group=self.entry_point_namespace)
else: # dict
return AVAILABLE_ENTRY_POINTS.get(self.entry_point_namespace, [])


def check_exists(*namespace):
"""Check if a namespace exists.
Expand Down
13 changes: 13 additions & 0 deletions catalogue/_importlib_metadata/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2017-2019 Jason R. Coombs, Barry Warsaw

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit ef4fd81

Please sign in to comment.