Skip to content

Commit

Permalink
Merge pull request #230 from bjodah/bump-dev-version-to-0.9.x
Browse files Browse the repository at this point in the history
Bump dev version to 0.9.x
  • Loading branch information
bjodah authored Apr 23, 2024
2 parents 578bfb1 + 05c923f commit 9792c65
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- run: bandit --recursive --skip B101,B102,B110,B112,B307,B404,B603,B607 .
- run: black --check . || true
- run: codespell --ignore-words-list="ans,claus,fith,nam,nd,ond,serie,te"
- run: flake8 . --count --max-complexity=66 --max-line-length=118
- run: flake8 . --count --max-complexity=66 --max-line-length=129
--show-source --statistics
- run: pip install flake8-bugbear flake8-comprehensions flake8-return flake8-simplify
- run: flake8 . --count --exit-zero --max-complexity=66 --max-line-length=118
- run: flake8 . --count --exit-zero --max-complexity=66 --max-line-length=129
--show-source --statistics
- run: isort --check-only --profile black . || true
- run: pip install setuptools
Expand Down
1 change: 1 addition & 0 deletions .woodpecker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ steps:
- export CPATH=$SUNDBASE/include:$CPATH
- export LIBRARY_PATH=$SUNDBASE/lib
- export LD_LIBRARY_PATH=$SUNDBASE/lib
- python3 -m pip install --cache-dir $CACHE_ROOT/pip_cache --user --upgrade-strategy=eager --upgrade cython
- python3 -m pip install --cache-dir $CACHE_ROOT/pip_cache --user -e .[all]
- python3 -c "import pycvodes; import pyodesys; import pygslodeiv2" # debug this CI config
- git fetch -tq
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ If you make use of ChemPy in e.g. academic work you may cite the following peer-
Depending on what underlying solver you are using you should also cite the appropriate paper
(you can look at the list of references in the JOSS article). If you need to reference,
in addition to the paper, a specific point version of ChemPy (for e.g. reproducibility)
you can get per-version DOIs from the zendodo archive:
you can get per-version DOIs from the zenodo archive:

.. image:: https://zenodo.org/badge/8840/bjodah/chempy.svg
:target: https://zenodo.org/badge/latestdoi/8840/bjodah/chempy
Expand Down
2 changes: 1 addition & 1 deletion chempy/_release.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.1.dev0+git"
__version__ = "0.9.0.dev0+git"
24 changes: 17 additions & 7 deletions chempy/util/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _get_formula_parser():
| '{' formula '}'
| '[' formula ']' ) count prime charge?
formula :: term+
hydrate :: '.' count? formula
hydrate :: ( '..' | '\u00B7' ) count? formula
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
compound :: count formula hydrate? state?
Expand All @@ -114,7 +114,7 @@ def _get_formula_parser():
| '{' formula '}'
| '[' formula ']' ) count prime charge?
formula :: term+
hydrate :: '..' count? formula
hydrate :: ( '..' | '\u00B7' ) count? formula
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
compound :: count formula hydrate? state?
"""
Expand Down Expand Up @@ -334,7 +334,7 @@ def _parse_stoich(stoich):

_unicode_mapping = {k + "-": v + "-" for k, v in zip(_greek_letters, _greek_u)}
_unicode_mapping["."] = "⋅"
_unicode_infix_mapping = {"..": "·"}
_unicode_infix_mapping = {"..": "\u00b7"} # 0x00b7: '·'

_html_mapping = {k + "-": "&" + k + ";-" for k in _greek_letters}
_html_mapping["."] = "⋅"
Expand Down Expand Up @@ -379,14 +379,19 @@ def formula_to_composition(
True
>>> formula_to_composition('Na2CO3..7H2O') == {11: 2, 6: 1, 8: 10, 1: 14}
True
>>> formula_to_composition('UO2.3') == {92: 1, 8: 2.3}
True
"""
if prefixes is None:
prefixes = _latex_mapping.keys()

stoich_tok, chg_tok = _formula_to_parts(formula, prefixes, suffixes)[:2]
tot_comp = {}
parts = stoich_tok.split("..")
if '\u00b7' in stoich_tok:
parts = stoich_tok.split('\u00b7')
else:
parts = stoich_tok.split("..")

for idx, stoich in enumerate(parts):
if idx == 0:
Expand Down Expand Up @@ -532,7 +537,10 @@ def _formula_to_format(
suffixes=("(s)", "(l)", "(g)", "(aq)"),
):
parts = _formula_to_parts(formula, prefixes.keys(), suffixes)
stoichs = parts[0].split("..")
if '\u00b7' in parts[0]:
stoichs = parts[0].split('\u00b7')
else:
stoichs = parts[0].split("..")
string = ""
for idx, stoich in enumerate(stoichs):
if idx == 0:
Expand Down Expand Up @@ -600,9 +608,11 @@ def formula_to_latex(formula, prefixes=None, infixes=None, **kwargs):
)


_unicode_sub = {}
_unicode_sub = {
".": ".",
}

for k, v in enumerate("₀₁₂₃₄₅₆₇₈₉"):
for k, v in enumerate("₀₁₂₃₄₅₆₇₈₉."):
_unicode_sub[str(k)] = v

_unicode_sup = {
Expand Down
43 changes: 43 additions & 0 deletions chempy/util/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
parsing_library,
to_reaction,
)

from ..testing import requires


Expand Down Expand Up @@ -625,6 +626,22 @@ def test_formula_to_latex_caged(species, latex):
("[Fe(H2O)6][Fe(CN)6]..19H2O(aq)", r"[Fe(H₂O)₆][Fe(CN)₆]·19H₂O(aq)"),
("[Fe(CN)6]-3", r"[Fe(CN)₆]³⁻"),
("[Fe(CN)6]-3(aq)", r"[Fe(CN)₆]³⁻(aq)"),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6",
r"Ca₂.₈₃₂Fe₀.₆₂₈₅Mg₅.₃₉₅(CO₃)₆",
),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6(s)",
r"Ca₂.₈₃₂Fe₀.₆₂₈₅Mg₅.₃₉₅(CO₃)₆(s)",
),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6..8H2O(s)",
r"Ca₂.₈₃₂Fe₀.₆₂₈₅Mg₅.₃₉₅(CO₃)₆·8H₂O(s)",
),
(
"Zn(NO3)2..6H2O",
r"Zn(NO₃)₂·6H₂O",
),
],
)
@requires(parsing_library)
Expand Down Expand Up @@ -692,6 +709,26 @@ def test_formula_to_unicode_caged(species, unicode):
),
("[Fe(CN)6]-3", r"[Fe(CN)<sub>6</sub>]<sup>3-</sup>"),
("[Fe(CN)6]-3(aq)", r"[Fe(CN)<sub>6</sub>]<sup>3-</sup>(aq)"),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6",
r"Ca<sub>2.832</sub>Fe<sub>0.6285</sub>Mg<sub>5.395</sub>(CO<sub>3</sub>)<sub>6</sub>",
),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6(s)",
r"Ca<sub>2.832</sub>Fe<sub>0.6285</sub>Mg<sub>5.395</sub>(CO<sub>3</sub>)<sub>6</sub>(s)",
),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6..8H2O(s)",
r"Ca<sub>2.832</sub>Fe<sub>0.6285</sub>Mg<sub>5.395</sub>(CO<sub>3</sub>)<sub>6</sub>&sdot;8H<sub>2</sub>O(s)",
),
(
"Ca2.832Fe0.6285Mg5.395(CO3)6..8H2O(s)",
r"Ca<sub>2.832</sub>Fe<sub>0.6285</sub>Mg<sub>5.395</sub>(CO<sub>3</sub>)<sub>6</sub>&sdot;8H<sub>2</sub>O(s)",
),
(
"Zn(NO3)2..6H2O",
r"Zn(NO<sub>3</sub>)<sub>2</sub>&sdot;6H<sub>2</sub>O",
),
],
)
@requires(parsing_library)
Expand All @@ -712,3 +749,9 @@ def test_formula_to_html(species, html):
def test_formula_to_html_caged(species, html):
"""Should produce HTML for cage species."""
assert formula_to_html(species) == html


def test_composition_dot_as_crystal_water_chempy08x():
ref = {30: 1, 7: 2, 8: 12, 1: 12}
assert formula_to_composition('Zn(NO3)2{}6H2O'.format('\u00B7')) == ref
assert formula_to_composition('Zn(NO3)2..6H2O') == ref
17 changes: 0 additions & 17 deletions postBuild

This file was deleted.

0 comments on commit 9792c65

Please sign in to comment.