From 25c128e450618c1f9fb3b04677c0c177f360d596 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Thu, 22 Jun 2023 15:57:15 -0700 Subject: [PATCH 1/2] Replace pkg_resources with ResourcePath --- python/lsst/obs/base/instrument_tests.py | 6 +++--- tests/test_yamlCamera.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/python/lsst/obs/base/instrument_tests.py b/python/lsst/obs/base/instrument_tests.py index e5c6ab8d..53d6067a 100644 --- a/python/lsst/obs/base/instrument_tests.py +++ b/python/lsst/obs/base/instrument_tests.py @@ -41,11 +41,11 @@ from functools import lru_cache from typing import TYPE_CHECKING, Any, ClassVar, Optional, Sequence, Set -import pkg_resources from lsst.daf.butler import CollectionType, DatasetType, Registry, RegistryConfig from lsst.daf.butler.formatters.yaml import YamlFormatter from lsst.obs.base import FilterDefinition, FilterDefinitionCollection, Instrument from lsst.obs.base.yamlCamera import makeCamera +from lsst.resources import ResourcePath from lsst.utils.introspection import get_full_type_name from pydantic import BaseModel @@ -122,8 +122,8 @@ def getObsDataPackageDir(cls) -> Optional[str]: def getCamera(self): # Return something that can be indexed by detector number # but also has to support getIdIter. - filename = pkg_resources.resource_filename("lsst.obs.base", "test/dummycam.yaml") - return makeCamera(filename) + with ResourcePath("resource://lsst.obs.base/test/dummycam.yaml").as_local() as local_file: + return makeCamera(local_file.ospath) def register(self, registry, update=False): """Insert Instrument, physical_filter, and detector entries into a diff --git a/tests/test_yamlCamera.py b/tests/test_yamlCamera.py index 8ea6aad3..6e62e5fc 100644 --- a/tests/test_yamlCamera.py +++ b/tests/test_yamlCamera.py @@ -21,19 +21,20 @@ import unittest -import pkg_resources from lsst.obs.base.yamlCamera import makeCamera +from lsst.resources import ResourcePath class YamlCameraTestCase(unittest.TestCase): """Test the YAML camera geometry.""" def setUp(self): - self.cameraFile = pkg_resources.resource_filename("lsst.obs.base", "test/dummycam.yaml") + self.cameraFile = ResourcePath("resource://lsst.obs.base/test/dummycam.yaml") def test_basics(self): """Basic test of yaml camera construction""" - camera = makeCamera(self.cameraFile) + with self.cameraFile.as_local() as local_file: + camera = makeCamera(local_file.ospath) self.assertEqual(len(camera), 2) self.assertEqual(camera[0].getName(), "RXX_S00") From b2e38607ce946f471a0edb6da8333c7b09d04a3c Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Thu, 22 Jun 2023 15:57:42 -0700 Subject: [PATCH 2/2] Remove pkg_resources from types requirement --- types.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/types.txt b/types.txt index b792f46a..b5e7c4f2 100644 --- a/types.txt +++ b/types.txt @@ -1,5 +1,4 @@ types-requests types-PyYAML -types-pkg_resources types-Deprecated types-python-dateutil