Skip to content

Commit

Permalink
pkg_resources -> importlib.resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Jan 5, 2024
1 parent d75378d commit b9e3207
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions src/pyEQL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,17 +30,16 @@
# 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")
# set the default string formatting for pint quantities
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.
Expand Down

0 comments on commit b9e3207

Please sign in to comment.