Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# AGENTS.md

Guidance for anyone contributing to libCellML, whether a person or an AI coding tool.
It points to the project's documentation, where the rules and the process are written down, and adds notes on setting up a local environment for the checks.

## Where things are written down

| Topic | Where |
| --- | --- |
| Setting up a development machine (Git, CMake 3.26 or later, compiler, libxml2, zlib, SWIG) | `docs/setup.rst` |
| Dependency versions | `docs/versions.rst` |
| Configuring and building | `docs/configure_and_build.rst`, with the CMake options in `docs/dev_configuration_options.rst` |
| Running the tests and every CI check locally, and the rules for writing tests | `docs/testing.rst` |
| The contribution process: issues, topic branches, test-driven development, pull requests, commit messages, review feedback, approvals | `docs/contributing.rst` |
| What reviewers check before merging | `docs/review_process.rst` |
| Coding standards: naming, indentation, spelling, compiler warnings, comments, Doxygen comments, test names, rules checked by the tests | `docs/coding_standards.rst` |
| Developer utilities, such as updating the generator profile SHA-1 values | `docs/dev_utilities.rst` |
| Code formatting | `.clang-format` |
| What CI runs on every pull request | `.github/workflows/ci.yml` and `.github/workflows/spell-check.yml` |
| Code of conduct | `CODE_OF_CONDUCT.rst` |

## The project

libCellML is a C++20 library for reading, validating, analysing and generating code from CellML 2.0 models, with Python bindings (SWIG) and JavaScript bindings (Emscripten).

- `src/`: the library. Public headers are in `src/api/libcellml/`.
- `src/bindings/interface/`: SWIG interface files for the Python bindings.
- `src/bindings/javascript/`: the JavaScript bindings.
- `tests/<area>/`: GoogleTest tests, one folder per area (`parser`, `validator`, `generator`, ...). Each folder lists its source files in `tests.cmake`.
- `tests/resources/`: CellML models and expected output used by the tests.
- `tests/bindings/python/` and `tests/bindings/javascript/`: tests for the bindings.

## A local environment

The project doesn't ship a container or a virtual environment set-up, so use whichever suits your machine. An isolated environment keeps the tools for the checks in `docs/testing.rst` apart from the rest of your system, and an AI coding tool can create one from the notes below. AI tools should prefer such an environment to installing packages system-wide.

- **Python virtual environment.** For the Python bindings, create and activate the virtual environment before configuring CMake, so the bindings are built for the same Python you test with. Install the packages for Python coverage into the same environment.
- **Linux container** (for example Docker with Ubuntu). This matches the Linux CI jobs, and it is the easiest way to run `memcheck` from Windows or macOS, since Valgrind runs on Linux. The checks need a C++20 compiler, CMake, Ninja, the libxml2 and zlib development files, ClangFormat, Valgrind, and Clang with the LLVM tools `llvm-profdata` and `llvm-cov`.
- **Working from Windows.** Check out with LF line endings (`git config core.autocrlf false`). If the source is mounted into a Linux container from a Windows drive, files can appear there as executable, and `test_clang_format` may then report correctly formatted files. Building from a copy inside the container's own file system avoids this.
30 changes: 30 additions & 0 deletions docs/coding_standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ The following is a list of exceptions/deviations from the Google style guide tha
* :wikipedia:`camelCase</Camel_case>` class method names.
* Indent core code four spaces at a time (no tabs); for CMake files use two space indentation.

Spelling and licence
====================

* Use British spelling in code, messages and documentation, for example :code:`analyser`, :code:`behaviour` and :code:`initialise`.
* New source files start with the Apache licence header used in the existing files.

Compiler warnings
=================

* Warnings are treated as errors by default (the :code:`TWAE` CMake option): :code:`-Wall -W -Werror` with GCC and Clang, and :code:`/W4 /WX` with MSVC.
A warning that only one compiler reports fails CI on that platform.

Code comments
=============

* Keep code comments short and only where they add something.
* Public API is documented with Doxygen in the headers, so don't repeat that documentation in the source files.

Doxygen comments
================

Expand All @@ -42,3 +60,15 @@ Weak pointers
=============

* The return value of :code:`std::weak_ptr<T>::lock()` should only be tested if it may be equal to :code:`nullptr`.

Following the CellML specification
==================================

* Validation follows the normative rules of the CellML 2.0 specification.
If an example in the specification disagrees with its rule, follow the rule and point out the difference in the pull request.

Rules checked by the tests
==========================

* Library sources must not include :code:`debug.h`; the :code:`are_debug_utilities_used` test checks this.
* :code:`Issue::ReferenceRule` in :code:`src/api/libcellml/issue.h` and :code:`ruleToInformation` in :code:`src/issue.cpp` must list the same rules in the same order; the :code:`are_issue_reference_rules_consistent` test checks this.
35 changes: 24 additions & 11 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ The issue can be used to discuss the topic and clarify any problems related to i
Once progress has been made towards addressing the issue, a pull request is created that references the issue.

Reviewers provide feedback on the changes by adding comments to the pull request or associated commits.
The :buildbot:`Buildbot<>` :code:`build/test` procedure will run each time changes are pushed to the pull request's branch, and the results are displayed in the pull request view.
The continuous integration (CI) checks run on GitHub Actions each time changes are pushed to the pull request's branch, and the results are displayed in the pull request view.
The checks are defined in :code:`.github/workflows/`.

Once all the changes and reviews are complete, one of the :term:`prime repository` owners will merge the pull request into the prime repository, onto the :code:`develop` branch.
Once all the changes and reviews are complete, one of the :term:`prime repository` owners will merge the pull request into the prime repository, onto the :code:`main` branch.

Note that a bug is just a type of issue, and that resolving the bug should have both the implementation to fix the bug and a test that triggers the bug.

Expand Down Expand Up @@ -66,7 +67,7 @@ Topic branches

A topic or feature branch is a branch that is local to you (and anyone you collaborate with), it is a branch that will not be available from the :term:`prime repository`.
All development work should be carried out on a topic branch, for example any major feature that you work on or minor bug fix.
Before creating a local topic branch, pull the latest changes from the :term:`prime repository` :code:`develop` branch, to make sure that you're working from the most up-to-date version of the code.
Before creating a local topic branch, pull the latest changes from the :term:`prime repository` :code:`main` branch, to make sure that you're working from the most up-to-date version of the code.

.. figure:: ./images/libCellMLProcesses-GitBranching.png
:align: center
Expand All @@ -75,13 +76,13 @@ Before creating a local topic branch, pull the latest changes from the :term:`pr

How branching in a Git repository works.

Following this process will make it easier to have multiple topic branches at once and keep them in-sync with the :term:`prime repository` :code:`develop` branch, which will in turn make it easier to manage multiple pull requests.
Following this process will make it easier to have multiple topic branches at once and keep them in-sync with the :term:`prime repository` :code:`main` branch, which will in turn make it easier to manage multiple pull requests.

The following Git commands show an example of how to create a topic branch for fixing a (hypothetical) bug described in `issue #123`::

git fetch prime develop
git checkout develop # Not required if already on develop branch
git merge prime/develop
git fetch prime main
git checkout main # Not required if already on main branch
git merge prime/main
git checkout -b issue123


Expand All @@ -102,10 +103,13 @@ For simple or obvious bugs which have fallen through the testing gaps, simply su
GitHub pull requests
====================
Once some changes have been made and local commits committed, push your changes to your Github libCellML repository (refer to :numref:`git_branching`).
From there, create a pull request from your topic branch to the :term:`prime repository` :code:`develop` branch.
From there, create a pull request from your topic branch to the :term:`prime repository` :code:`main` branch.
When creating the pull request, make sure to add in the comment :code:`Addresses issue #123` (of course, replace the number 123 with the actual number of the issue you are addressing), or something to that effect.
This will create a link between the issue and the pull request enabling other people to see that you are working on this issue and comment on your work.

The title of the pull request becomes its line in the changelog, which is generated from pull request titles at release time.
Write the title as a short description of the change, and don't edit the files in :code:`docs/changelogs/` by hand.

The following Git commands show an example of how to add all files, commit the changes, and push them to a Github repository for the first time::

git add .
Expand All @@ -116,7 +120,11 @@ The following Git commands show an example of how to add all files, commit the c
The :code:`git add` and :code:`git commit` commands should be obvious, the :code:`git push` command sets the local branch :code:`issue123` to be linked with the remote branch :code:`issue123` in the origin (the default shorthand for your libCellML repository on Github) repository.
This branch will be created in the origin repository if it does not already exist.

Commit messages are short sentences ending with a full stop.
Some start with the area they change, for example :code:`Generator: add parentheses around the NOT operand, if needed.`

To create a pull request from one Github repository to another, follow the instructions for :github_help:`creating Github pull requests</articles/creating-a-pull-request/>`.
For contributors from outside the organisation, GitHub may hold the CI runs until a repository owner approves them.

Reviewing
=========
Expand All @@ -128,12 +136,17 @@ Satisfying the feedback
=======================
It is important to respond to all feedback appropriately, the review process will check to make sure that all comments have been dealt with.
Feel free to respond to comments as appropriate, e.g. through code changes, posting a direct reply, etc.
Where you need to change code in response to a comment, be sure to include the commit code (a 7 digit hex number) in your reply, so that others can see where and how the changes were made.
Where you need to change code in response to a comment, be sure to include the commit code (a 7 digit hex number) in your reply, so that others can see where and how the changes were made.
The commit code on its own is enough, as reviewers can see what changed.

The repository owners may merge :code:`main` into your branch to keep it up to date.
Pull before you push, and don't force-push a branch that is under review.

Completing
==========
To complete the process, it is required to have two owners of the :term:`prime repository` comment on the pull request that they are satisfied that the work on the issue is complete and also that the feedback has been addressed, in essence that they are happy to merge the submission.
For small submissions, it is sufficient for the second owner to show satisfaction by performing the merge.
To complete the process, two owners of the :term:`prime repository` need to approve the pull request on GitHub, to show that they are satisfied that the work on the issue is complete and also that the feedback has been addressed, in essence that they are happy to merge the submission.
GitHub requires both approvals before the pull request can be merged.
Pushing new commits dismisses earlier approvals, so the owners approve again after the last push.
For larger submissions one of the owners will post a comment on the issue notifying subscribers that they intend to merge the pull request.
If no further objections are raised, the pull request will be merged and closed.

Expand Down
Loading
Loading