4. Development

This page covers the relevant aspects for developers.

4.1. Repository

The exporter is on GitHub.

4.2. Code of Conduct

Contribution must follow the Code of Conduct as defined by the Contributor Covenant.

4.3. Contributing

Third party contributions to this project are welcome!

In order to contribute, create a Git pull request, considering this:

  • Test is required.
  • Each commit should only contain one “logical” change.
  • A “logical” change should be put into one commit, and not split over multiple commits.
  • Large new features should be split into stages.
  • The commit message should not only summarize what you have done, but explain why the change is useful.
  • The commit message must follow the format explained below.

What comprises a “logical” change is subject to sound judgement. Sometimes, it makes sense to produce a set of commits for a feature (even if not large). For example, a first commit may introduce a (presumably) compatible API change without exploitation of that feature. With only this commit applied, it should be demonstrable that everything is still working as before. The next commit may be the exploitation of the feature in other components.

For further discussion of good and bad practices regarding commits, see:

4.4. Format of commit messages

A commit message must start with a short summary line, followed by a blank line.

Optionally, the summary line may start with an identifier that helps identifying the type of change or the component that is affected, followed by a colon.

It can include a more detailed description after the summary line. This is where you explain why the change was done, and summarize what was done.

It must end with the DCO (Developer Certificate of Origin) sign-off line in the format shown in the example below, using your name and a valid email address of yours. The DCO sign-off line certifies that you followed the rules stated in DCO 1.1. In short, you certify that you wrote the patch or otherwise have the right to pass it on as an open-source patch.

We use GitCop during creation of a pull request to check whether the commit messages in the pull request comply to this format. If the commit messages do not comply, GitCop will add a comment to the pull request with a description of what was wrong.

Example commit message:

cookies: Add support for delivering cookies

Cookies are important for many people. This change adds a pluggable API for
delivering cookies to the user, and provides a default implementation.

Signed-off-by: Random J Developer <random@developer.org>

Use git commit --amend to edit the commit message, if you need to.

Use the --signoff (-s) option of git commit to append a sign-off line to the commit message with your name and email as known by Git.

If you like filling out the commit message in an editor instead of using the -m option of git commit, you can automate the presence of the sign-off line by using a commit template file:

  • Create a file outside of the repo (say, ~/.git-signoff.template) that contains, for example:

    <one-line subject>
    <detailed description>
    Signed-off-by: Random J Developer <random@developer.org>
  • Configure Git to use that file as a commit template for your repo:

    git config commit.template ~/.git-signoff.template

4.5. Releasing a version

This section shows the steps for releasing a version to PyPI.

Switch to your work directory of the zhmc-prometheus-exporter Git repo (this is where the Makefile is), and perform the following steps in that directory:

  1. Set a shell variable for the version to be released, e.g.:

  2. Verify that your working directory is in a Git-wise clean state:

    git status
  3. Check out the master branch, and update it from upstream:

    git checkout master
    git pull
  4. Create a topic branch for the release, based upon the master branch:

    git checkout -b release-$MNU
  5. Edit the change log and perform the following changes in the top-most section (that is the section for the version to be released):

    vi docs/changes.rst
    • If needed, change the version in the section heading to the version to be released, e.g.:

      Version 0.11.0
    • Change the release date to today’s date, e.g.:

      Released: 2018-08-20
    • Make sure that the change log entries reflect all changes since the previous version, and make sure they are relevant for and understandable by users.

    • In the “Known issues” list item, remove the link to the issue tracker and add any known issues you want users to know about. Just linking to the issue tracker quickly becomes incorrect for released versions:

      **Known issues:**
      * ...
    • Remove all empty list items in the change log section for this release.

  6. Commit your changes and push them upstream:

    git add docs/changes.rst
    git commit -sm "Release $MNU"
    git push --set-upstream origin release-$MNU
  7. On GitHub, create a pull request for branch release-$MNU.

  8. Perform a complete test:

    make test

    This should not fail because the same tests have already been run in the Travis CI. However, run it for additional safety before the release.

    If this test fails, fix any issues until the test succeeds.

  9. Once the CI tests on GitHub are complete, merge the pull request.

  10. Update your local master branch:

    git checkout master
    git pull
  11. Tag the master branch with the release label and push the tag upstream:

    git tag $MNU
    git push --tags
  12. On GitHub, edit the new tag, and create a release description on it. This will cause it to appear in the Release tab.

    You can see the tags in GitHub via Code -> Releases -> Tags.

  13. Upload the package to PyPI:

    make upload

    This will show the package version and will ask for confirmation.

    Attention! This only works once for each version. You cannot release the same version twice to PyPI.

  14. Verify that the released version is shown on PyPI.

  15. On GitHub, close milestone M.N.U.

4.6. Starting a new version

This section shows the steps for starting development of a new version.

Switch to your work directory of the zhmc-prometheus-exporter Git repo (this is where the Makefile is), and perform the following steps in that directory:

  1. Set a shell variable for the version to be started, e.g.:

  2. Check out the branch the new version is based on, make sure it is up to date with upstream, and create a topic branch for the new version:

    git checkout master
    git pull
    git checkout -b start_$MNU
  3. Edit the change log:

    vi docs/changes.rst

    and insert the following section before the top-most section:

    Version 0.20.0
    Released: not yet
    **Incompatible changes:**
    **Bug fixes:**
    **Known issues:**
    * See `list of open issues`_.
    .. _`list of open issues`: https://github.com/zhmcclient/zhmc-prometheus-exporter/issues
  4. Commit your changes and push them upstream:

    git add docs/changes.rst
    git commit -sm "Start $MNU"
    git push --set-upstream origin start_$MNU
  5. On GitHub, create a Pull Request for branch start_M.N.U.

  6. On GitHub, create a milestone for the new version M.N.U.

    You can create a milestone in GitHub via Issues -> Milestones -> New Milestone.

  7. On GitHub, go through all open issues and pull requests that still have milestones for previous releases set, and either set them to the new milestone, or to have no milestone.

  8. On GitHub, once the checks for this Pull Request succeed:

    • Merge the Pull Request (no review is needed)
    • Delete the branch of the Pull Request (start_M.N.U)
  9. Checkout the branch the new version is based on, update it from upstream, and delete the local topic branch you created:

    git checkout master
    git pull
    git branch -d start_$MNU

4.7. Build a package

You can build a binary and a source distribution with

$ make build

You will find the files zhmc_prometheus_exporter-VERSION_NUMBER-py2.py3-none-any.whl and zhmc_prometheus_exporter-VERSION_NUMBER.tar.gz in the dist folder, the former being the binary and the latter being the source distribution.

The binary could then be installed with

$ pip3 install zhmc_prometheus_exporter-VERSION_NUMBER-py2.py3-none-any.whl

The source distribution (a more minimal version of the repository) can be unpacked with

$ tar xfz zhmc_prometheus_exporter-VERSION_NUMBER.tar.gz

4.8. Build the documentation

You can build the documentation as HTML with

$ make builddoc

The root for the built documentation will be docs/_build/index.html.

4.9. Unit & lint testing

You can perform unit tests based on unittest with

$ make test

If you want to speed up test time, you can remove the timeout test.

You can perform lint tests based on flake8 with

$ make lint

4.10. Cleanup processes

The package can be uninstalled with

$ make uninstall

The unnecessary files from the build process can be removed with

$ make clean