Contributing¶
Bug reports, corrections to the chemistry, documentation fixes and new solvers are all welcome.
Report a problem¶
Open an issue with:
- the code you ran,
- what you expected,
- what you got, including the full error message if there was one.
If chemhelper gives a wrong chemistry answer, a textbook reference for the right one helps a great deal.
Set up for development¶
The -e flag installs the package in editable mode, so your changes take
effect without reinstalling.
Project layout¶
chemhelper/
├── src/chemhelper/ the package
│ ├── elements.py periodic table data
│ ├── compounds.py formula parsing, molar mass, composition
│ ├── conversions.py grams, moles, molarity
│ └── ideal_gas.py PV = nRT
├── tests/ the test suite
├── docs/ this documentation, in Markdown
├── tools/
│ ├── docs_examples.py runs every example in the docs
│ └── make_periodic_table.py generates the periodic table page
├── mkdocs.yml documentation site configuration
├── pyproject.toml package metadata
└── CHANGELOG.md
Run the tests¶
This runs the tests in tests/ and every example in the docstrings.
Work on the documentation¶
Preview the site locally. It reloads as you edit:
Examples are executed, not typed¶
Every example in the docs is a fenced pycon block. You write only the input
lines, the ones that start with >>>. A script runs them against the real
package and fills in the output.
After adding or changing an example, or changing the code's behavior:
To check that every example is up to date without changing anything:
The check runs in CI, so documentation cannot drift from the code.
Each page gets one fresh Python session. An import at the top of a page is available to every block below it.
The periodic table page¶
docs/periodic-table.md is generated from the element data. After changing
elements.py, regenerate it:
Add a solver¶
New solvers follow one pattern.
- Write the function that returns the answer. Give it a NumPy-style
docstring with
Parameters,Returns,RaisesandExamplessections. Validate the inputs and raiseValueErrorwith a message that says what is wrong. - Write the
_stepstwin. It takes the same arguments, prints the solution with units, and returns nothing. Its final number must equal what the first function returns. - Round only the final result. Carry full precision through intermediate steps.
- Add tests in
tests/for typical values, edge cases and each error. - Document it: a section in the module's page under
docs/guide/, a row in the tables indocs/guide/index.mdanddocs/getting-started/steps.md, and a line inCHANGELOG.md.
Style¶
- Follow PEP 8. Lines up to 110 characters are fine.
- Name arguments after the chemistry:
mass,moles,volume,chemical. - Keep the dependencies small. The package needs only pandas.
Send a pull request¶
- Create a branch for your change.
- Make sure
pytest,python tools/docs_examples.pyandmkdocs build --strictall pass. - Open a pull request describing what changed and why.
Release checklist¶
For maintainers.
- Update the version in
pyproject.tomlandsrc/chemhelper/__init__.py. - Add the release to
CHANGELOG.md. - Run the tests and the documentation check.
-
Build and upload:
-
Tag the release:
The documentation site is rebuilt and published automatically on every push
to master.