7. CCPP Code Management

7.1. Organization of the Code

This chapter describes the organization of the code, provides instruction on the GitHub workflow and the code review process, and outlines the release procedure. It is assumed that the reader is familiar with using basic GitHub features. A GitHub account is necessary if a user would like to make and contribute code changes.

7.1.1. Authoritative Repositories

There are two authoritative repositories for the CCPP:

https://github.com/NCAR/ccpp-framework

https://github.com/NCAR/ccpp-physics

Users have read-only access to these repositories and as such cannot accidentally destroy any important (shared) branches of these authoritative repositories. Both CCPP repositories are public (no GitHub account required) and may be used directly to read or create forks. Write permission is generally restricted, however.

The following branches are recommended for CCPP developers:

Repository

Branch name

https://github.com/NCAR/ccpp-physics

main

https://github.com/NCAR/ccpp-framework

main

7.1.2. Directory Structure of CCPP Framework

The following is the directory structure for the ccpp-framework repository

(condensed version):

├── doc                    # Documentation for design/implementation and developers guide
│   ├── DevelopersGuide
│   ├── HelloWorld         # Toy model to use of the CCPP Framework
│   └── img
├── loggging               # Logging handler for future capgen.py
├── schema                 # XML scheme for suite definition files
├── schemes                # Example ccpp_prebuild_config.py
│   ├── check
├── scripts                # Scripts for ccpp_prebuild.py, metadata parser, etc.
│   ├── conversion_tools
│   ├── fortran_tools
│   └── parse_tools
├── src                    # CCPP framework source code
├── test                   # Unit/system testing framework for future capgen.py
│   ├── advection_test
│   ├── capgen_test
│   ├── hash_table_tests
│   └── unit_tests
└── tests                  # System testing framework for ccpp_prebuild.py

7.1.3. Directory Structure of CCPP Physics

The following is the directory structure for the ccpp-physics repository (condensed version):

├── physics                 # CCPP physics source code and metadata files
│   ├── docs                # Scientific documentation (doxygen)
│   │   ├── img             # Figures for doxygen
│   │   └── pdftxt          # Text files for documentation
└── tools                   # Tools used by CI system for basic checks (encoding ...)

7.2. GitHub Workflow (setting up development repositories)

The CCPP development practices make use of the GitHub forking workflow. For users not familiar with this concept, this website provides some background information and a tutorial.

7.2.1. Creating Forks

The GitHub forking workflow relies on forks (personal copies) of the shared repositories on GitHub. A personal fork needs to be created only once, and only for repositories that users will contribute changes to. The following steps describe how to create a fork for the example of the ccpp-physics submodule/repository:

Go to https://github.com/NCAR/ccpp-physics and make sure you are signed in to your GitHub account.

Select the “fork” button in the upper right corner.

  • If you have already created a fork, this will take you to your fork.

  • If you have not yet created a fork, this will create one for you.

Note that the repo name in the upper left (blue) will be either “NCAR” or “your GitHub name” which tells you which fork you are looking at.

Note that personal forks are not required until a user wishes to make code contributions. The procedure for how to check out the code laid out below can be followed without having created a fork beforehand.

7.2.2. Checking out the Code

Instructions are provided here for the ccpp-physics repository; the instructions for the ccpp-framework repository are analogous. The process for checking out the CCPP is described in the following, assuming access via https (using a personal access token) rather than ssh. If you are using an ssh key instead, you should replace instances of https://github.com/ with git@github.com: in repository URLs.

Start by checking out the main repository from the NCAR GitHub Organization:

git clone https://github.com/NCAR/ccpp-physics
cd ccpp-physics
git remote rename origin upstream

In the above commands we have also renamed the “origin” repository to “upstream” within this clone. This will be required if you plan on making changes and contributing them back to your fork, but is otherwise unnecessary. This step prevents accidentally pushing changes to the main repository rather than your fork later on.

From here you can view the available branches in the ccpp-physics repository with the git branch command:

git fetch --all
git branch -a

* main
  remotes/upstream/HEAD -> upstream/main
  remotes/upstream/dtc/hwrf-physics
  remotes/upstream/emc_training_march_2019
  remotes/upstream/emc_training_march_2019_rftim
  remotes/upstream/feature/DOE_PBL_project
  remotes/upstream/feature/rrtmgp-doxygen
  remotes/upstream/feature/unified_standard_names
  remotes/upstream/gfs_suite2_physics_test_tag_20190222
  remotes/upstream/gsd_suite4_physics_test_tag_20181210
  remotes/upstream/main
  remotes/upstream/mraerosol
  remotes/upstream/release/P7a
  remotes/upstream/release/P7b
  remotes/upstream/release/public-v4
  remotes/upstream/release/public-v5
  remotes/upstream/release/public-v6

As you can see, you are placed on the main branch by default; this is the most recent version of the development code in the ccpp-physics repository. All new development should start from that point, but if you would like to view code from another branch this is simple with the git checkout command.

git checkout release/public-v6

branch 'release/public-v6' set up to track 'upstream/release/public-v6'.
Switched to a new branch 'release/public-v6'

Note

Never used git or GitHub before? Confused by what all this means or why we do it? Check out this presentation from the UFS SRW Training workshop for a “from basic principles” explanation!

After this command, git has checked out a local copy of the remote branch upstream/release/public-v6 named release/public-v6. To return to the main branch, simply use git checkout main.

If you wish to make changes that you will eventually contribute back to the public code base, you should always create a new “feature” branch that will track those particular changes.

git checkout upstream/main
git checkout -b feature/my_new_local_development_branch

Note

By checking out the remote upstream/main branch directly, you will be left in a so-called ‘detached HEAD’ state. This will prompt git to show you a scary-looking warning message, but it can be ignored so long as you follow it by the second command above to create a new branch.

You can now make changes to the code, and commit those changes locally using git commit in order to track

Once you are ready to contribute the code back to the main (upstream) ccpp-physics repository, you need to create a pull request (PR) (see Creating a pull request). In order to do so, you first need to create your own fork of this repository (see Creating Forks) and configure your fork as an additional remote destination, which we typically label as origin. For example:

git remote add origin https://github.com/YOUR_GITHUB_USER/ccpp-physics
git fetch origin

Then, push your local branch to your fork:

git push origin my_local_development_branch

For each repository/submodule, you can check the configured remote destinations and all existing branches (remote and local):

git remote -v show
git remote update
git branch -a

As opposed to branches without modifications described in step 3, changes to the upstream repository can be brought into the local branch by pulling them down. For example (where a local branch is checked out):

cd ccpp-physics
git remote update
git pull upstream main

7.3. Committing Changes to your Fork

Once you have your fork set up to begin code modifications, you should check that the cloned repositories upstream and origin are set correctly:

git remote -v

This should point to your fork as origin and the repository you cloned as upstream:

origin             https://github.com/YOUR_GITHUB_USER/ccpp-physics (fetch)
origin             https://github.com/YOUR_GITHUB_USER/ccpp-physics (push)
upstream   https://github.com/NCAR/ccpp-physics (fetch)
upstream   https://github.com/NCAR/ccpp-physics (push)

Also check what branch you are working on:

git branch

This command will show what branch you have checked out on your fork:

* features/my_local_development_branch
  main

After making modifications and testing, you can commit the changes to your fork. First check what files have been modified:

git status

This git command will provide some guidance on what files need to be added and what files are “untracked”. To add new files or stage modified files to be committed:

git add filename1 filename2

At this point it is helpful to have a description of your changes to these files documented somewhere, since when you commit the changes, you will be prompted for this information. To commit these changes to your local repository and push them to the development branch on your fork:

git commit
git push origin features/my_local_development_branch

When this is done, you can check the status again:

git status

This should show that your working copy is up to date with what is in the repository:

On branch features/my_local_development_branch
Your branch is up to date with 'origin/features/my_local_development_branch'.
nothing to commit, working tree clean

At this point you can continue development or create a PR as discussed in Creating a Pull Request.

7.4. Contributing Code, Code Review Process

Once your development is mature, and the testing has been completed, you are ready to create a PR using GitHub to propose your changes for review.

7.4.1. Creating a Pull Request

Go to the github.com web interface, and navigate to your repository fork and branch. In most cases, this will be in the ccpp-physics repository, hence the following example:

Navigate to: https://github.com/<yourusername>/ccpp-physics
Use the drop-down menu on the left-side to select a branch to view your development branch
Use the button just right of the branch menu, to start a “New Pull Request”
Fill in a short title (one line)
Fill in a detailed description, including reporting on any testing you did
Click on “Create pull request”

If your development also requires changes in other repositories, you must open PRs in those repositories as well. In the PR message for each repository, please note the associated PRs submitted to other repositories.

Several people (aka CODEOWNERS) are automatically added to the list of reviewers on the right hand side. Once the PR has been approved, the change is merged to main by one of the code owners. If there are pending conflicts, this means that the code is not up to date with the trunk. To resolve those, pull the target branch from upstream as described above, solve the conflicts and push the changes to the branch on your fork (this also updates the PR).

Note

GitHub offers a “Draft pull request” feature that allows users to push their code to GitHub and create a draft PR. Draft PRs cannot be merged and do not automatically initiate notifications to the CODEOWNERS, but allow users to prepare the PR and flag it as “ready for review” once they feel comfortable with it. To open a draft rather than a ready-for-review PR, select the arrow next to the green “Create pull request” button, and select “Create draft pull request”. Then continue the above steps as usual.