From b9e320713b700cf7cb096006086dc1fe81c39272 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 5 Jan 2024 16:00:49 -0500 Subject: [PATCH] pkg_resources -> importlib.resources --- CHANGELOG.md | 15 ++++++++++----- src/pyEQL/__init__.py | 10 ++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b93d864e..688eef3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Removed deprecated `pkg_resources` import in favor of `importlib.resources` + ## [0.11.1] - 2023-12-23 ### Added @@ -204,7 +210,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - - `pyEQL.unit` was renamed to `pyEQL.ureg` (short for `UnitRegistry`) for consistency with the `pint` documentation and tutorials. ## [v0.6.0] - 2023-08-15 @@ -224,7 +229,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `pymatgen`, `monty`, and `maggma` as dependencies - Add `pre-commit` configuration - Add pull request template, new GitHub actions, and `tox -e autodocs` environment to serve and update docs in real time -- Add pre-commit configuration and lint with `ruff` using rulesets mostly borrowed from `pymatgen` +- Add pre-commit configuration and lint with `ruff` using rulesets mostly borrowed from `pymatgen` - Add more comprehensive platform testing via `tox` ### Changed @@ -254,9 +259,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.5.2] - 2020-04-21 - - Fix breaking bug introduced by upstream pint change to avogadro_number - - Format project with black - - Misc. linting and docstring changes +- Fix breaking bug introduced by upstream pint change to avogadro_number +- Format project with black +- Misc. linting and docstring changes ## [0.5.0] 2018-09-19 diff --git a/src/pyEQL/__init__.py b/src/pyEQL/__init__.py index fc4bdae4..7ac6c8f5 100644 --- a/src/pyEQL/__init__.py +++ b/src/pyEQL/__init__.py @@ -6,11 +6,10 @@ :license: LGPL, see LICENSE for more details. """ from importlib.metadata import PackageNotFoundError, version # pragma: no cover -from pathlib import Path +from importlib.resources import files from maggma.stores import JSONStore from pint import UnitRegistry -from pkg_resources import resource_filename try: # Change here if project is renamed and does not equal the package name @@ -31,7 +30,7 @@ # see https://pint.readthedocs.io/en/0.22/user/nonmult.html?highlight=offset#temperature-conversion ureg.autoconvert_offset_to_baseunit = True # append custom unit definitions and contexts -fname = resource_filename("pyEQL", "pint_custom_units.txt") +fname = files("pyEQL") / "pint_custom_units.txt" ureg.load_definitions(fname) # activate the "chemistry" context globally ureg.enable_contexts("chem") @@ -39,9 +38,8 @@ ureg.default_format = "P~" # create a Store for the default database -database_dir = resource_filename("pyEQL", "database") -json = Path(database_dir) / "pyeql_db.json" -IonDB = JSONStore(str(json), key="formula") +json_db_file = files("pyEQL") / "database" / "pyeql_db.json" +IonDB = JSONStore(str(json_db_file), key="formula") # By calling connect on init, we get the expensive JSON reading operation out # of the way. Subsequent calls to connect will bypass this and access the already- # instantiated Store in memory, which should speed up instantiation of Solution objects.