Skip to content

Refactor code base and add support for hydrogen isotopes -> v1.5.0#21

Merged
molshape merged 1 commit intomainfrom
feature/hydrogen-isotopes
Sep 14, 2025
Merged

Refactor code base and add support for hydrogen isotopes -> v1.5.0#21
molshape merged 1 commit intomainfrom
feature/hydrogen-isotopes

Conversation

@molshape
Copy link
Copy Markdown
Owner

This pull request introduces ChemFormula version 1.5.0, adding hydrogen isotope support and bringing significant improvements to code quality, documentation, and Python compatibility. The highlights include new features for handling hydrogen isotopes, enhanced continuous integration, and improved type safety and code quality tooling. The documentation and examples have been updated to reflect these changes, and tested support for Python 3.9 has been dropped in favor of newer versions.

New Features and Functionality

  • Added support for hydrogen isotopes (deuterium "D" and tritium "T") via a global AllowHydrogenIsotopes flag in chemformula.config, with corresponding documentation and usage examples (README.md, examples/example5.py, src/chemformula/chemformula.py) [1] [2] [3] [4].
  • This new feature closes the feature requests Addition of Named Isotopes #14 and Deuterium and Tritium #20.
  • Introduced .contains_isotopes attribute to the ChemFormula class for detecting specific isotopes in formulas, and updated documentation and examples accordingly (README.md, examples/example5.py, src/chemformula/chemformula.py) [1] [2].

Code Quality, Type Safety and CI Improvements

  • Added type stub files chemformula.pyi, elements.pyi, and config.pyi that provide explicit type signatures for all public methods and properties of the ChemFormula class, enhancing static type checking and editor support.
  • Overhauled the CI workflow: split jobs into code-tests and code-quality, added mypy type checking, and integrated Codecov for coverage reporting (.github/workflows/ci.yml, README.md) [1] [2] [3] [4].
  • Updated development dependencies to include mypy and pinned minimum versions for all dev tools; test coverage options are now set in pyproject.toml [1] [2].

Python Version and Dependency Updates

  • Dropped tested support for Python 3.9 and 3.11, now supporting only Python 3.10 and 3.12+; updated requires-python and classifiers in pyproject.toml [1] [2] [3].
  • Bumped minimum casregnum dependency to >=1.1.2.

Documentation and Example Enhancements

  • Improved README: clarified installation instructions, added isotope usage section, fixed typos, updated attribute names (e.g., .radioactive.is_radioactive), and improved output examples for consistency (README.md, examples/example1.py, examples/example2.py, examples/example_general.py) [1] [2] [3] [4] [5] [6] [7] [8].
  • Added docstrings to all attributes and methods for better documentation.

Packaging and Metadata

  • Added dynamic version retrieval in src/chemformula/__init__.py using importlib.metadata.
  • Updated project version to 1.5.0 in pyproject.toml.

These changes collectively modernize the codebase, improve usability for chemical isotope work, and ensure higher code quality and maintainability.

- Add `mypy` type checking to CI pipeline (`ci.yml`)
- Rename `lint` job to `code-quality`
- Rename `test` job to `code-tests`
- Add and configure pytest options in `pyproject.toml`
- Simplify pytest call in `ci.yml`
- Specify version numbers for dependencies
- Improve type annotations in `chemformula.py` and `elements.py` to comply with mypy
- Add `casregnum.pyi`, `elements.pyi`, and `config.pyi` type stubs for static type checking
- Add `py.typed` marker file to indicate typed package
- Change CI matrix to only two Python versions
- Change property name for radioactivity check from `radioactive` to `is_radioactive` for clarity. Keep `radioactive` for backwards compatibility
- Add support for hydrogen isotopes (Deuterium and Tritium) via a global configuration flag (`AllowHydrogenIsotopes`)
- Introduce `ChemFormulaDict` for better handling of chemical formula dictionaries and simplified error handling and data validation
- Add `example5.py` to demonstrate the new hydrogen isotope functionality
- Enhance documentation for classes and methods, including detailed docstrings
- Add tests for isotope functionality and update existing tests to reflect the property name change
- Update dependencies and classifiers in `pyproject.toml` to support Python 3.10, 3.11, and 3.12
- Improve error handling and validation for CAS registry numbers
- Update `README.md` accordingly
- Bump to version 1.5.0
@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@molshape molshape merged commit 8129256 into main Sep 14, 2025
7 checks passed
@molshape molshape added the enhancement New feature or request label Sep 14, 2025
This was linked to issues Sep 14, 2025
@molshape molshape deleted the feature/hydrogen-isotopes branch September 14, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deuterium and Tritium Addition of Named Isotopes

2 participants