Skip to content

Commit

Permalink
Migrate from pkg_resources to importlib.resources (#28) (close #26)
Browse files Browse the repository at this point in the history
* ref: correct doc readme

* ref: migrate from pkg_resources to importlib.resources in codebase

* update CHANGELOG for 0.18.1

* minor lint changes changelog

---------

Co-authored-by: Eoghan O'Connell <[email protected]>
  • Loading branch information
PinkShnack and Eoghan O'Connell authored Jan 9, 2025
1 parent 07ec9bc commit 9899dde
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.18.1
- ref: Migrate from pkg_resources to importlib.resources (#26)
0.18.0
- ref: JPK calibration files are now not ignored anymore
- ref: allow to specify custom metadata for JPK files
Expand Down
19 changes: 11 additions & 8 deletions afmformats/formats/fmt_jpk/jpk_meta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools
import json
from pkg_resources import resource_filename

import importlib.resources as importlib_resources

__all__ = ["get_primary_meta_recipe",
"get_secondary_meta_recipe",
Expand All @@ -10,15 +9,19 @@

@functools.lru_cache()
def get_primary_meta_recipe():
with open(resource_filename("afmformats.formats.fmt_jpk",
"jpk_meta_primary.json")) as fd:
meta_recipe_pri = json.load(fd)
ref = importlib_resources.files(
"afmformats.formats.fmt_jpk") / "jpk_meta_primary.json"
with importlib_resources.as_file(ref) as path:
with open(path) as fd:
meta_recipe_pri = json.load(fd)
return meta_recipe_pri


@functools.lru_cache()
def get_secondary_meta_recipe():
with open(resource_filename("afmformats.formats.fmt_jpk",
"jpk_meta_secondary.json")) as fd:
meta_recipe_sec = json.load(fd)
ref = importlib_resources.files(
"afmformats.formats.fmt_jpk") / "jpk_meta_secondary.json"
with importlib_resources.as_file(ref) as path:
with open(path) as fd:
meta_recipe_sec = json.load(fd)
return meta_recipe_sec
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ To install the requirements for building the documentation, run

To compile the documentation, run

cd docs
sphinx-build . _build

Notes
Expand Down

0 comments on commit 9899dde

Please sign in to comment.