3. Developers Guide

3.1. Contributing Guide

Contributions are welcome and greatly appreciated!

3.1.1. Workflow

A bug-fix or enhancement is delivered using a pull request. A good pull request should cover one bug-fix or enhancement feature. This strategy ensures the change set is easier to review and less likely to need major re-work or even be rejected.

The workflow that developers typically use to fix a bug or add enhancements is as follows.

  • Fork the string_to_markdown_id repo into your account.

  • Obtain the source by cloning it onto your development machine.

    $ git clone git@github.com:PROxZIMA/string_to_markdown_id.git
    $ cd string_to_markdown_id
    
  • Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  • Familiarize yourself with the developer convenience rules in the Makefile.

    $ make help
    
  • Create and activate a Python virtual environment for local development. This rule also specifies a project specific prompt label to use once the virtual environment is activated.

    $ make venv
    $ source venv/bin/activate
    (string_to_markdown_id) $
    

    The ‘venv’ directory is is created under the project root directory and is also listed in the ‘.gitignore’ file so that its contents never accidentally get added to a git change set.

    Note

    (string_to_markdown_id) is used to indicate when the commands should be run within the virtual environment containing the development dependencies.

  • Develop fix or enhancement:

    • Make a fix or enhancement (e.g. modify a class, method, function, module, etc).

    • Update an existing unit test or create a new unit test module to verify the change works as expected.

    • Run the test suite.

      (string_to_markdown_id) $ make test
      

      See the Testing section for more information on testing.

    • Check code coverage of the area of code being modified.

      (string_to_markdown_id) $ make coverage
      

      Review the output produced in docs/source/_static/coverage/coverage.html. Add additional test steps, where practical, to improve coverage.

    • The change should be style compliant. Perform style check.

      (string_to_markdown_id) $ make check-style
      

      Run ‘make style’ to automatically apply style fixes if needed. See the Code Style section for more information.

    • The change should pass static analysis checks (linting and type annotations where appropriate). Perform static analysis check.

      (string_to_markdown_id) $ make check-static-analysis
      

      See the Static Analysis section for more information.

    • Fix any errors or regressions.

  • The docs and the change log should be updated for anything but trivial bug fixes. Perform docs check.

    (string_to_markdown_id) $ make docs
    

    See the Documentation section for more information.

  • Commit and push changes to your fork.

    $ git add .
    $ git commit -m "A detailed description of the changes."
    $ git push origin name-of-your-bugfix-or-feature
    

    A pull request should preferably only have one commit upon the current master HEAD, (via rebases and squash).

  • Submit a pull request through the service website (e.g. Github, Gitlab).

  • Check automated continuous integration steps all pass. Fix any problems if necessary and update the pull request.

3.2. Testing

The String to Markdown Id project implements a regression test suite that improves developer productivity by identifying capability regressions early.

Developers implementing fixes or enhancements must ensure that they have not broken existing functionality. The String to Markdown Id project provides some convenience tools so this testing step can be quickly performed.

Use the Makefile convenience rules to run the tests.

(string_to_markdown_id) $ make test

To run tests verbosely use:

(string_to_markdown_id) $ make test-verbose

Alternatively, you may want to run the test suite directly. The following steps assume you are running in a virtual environment in which the string_to_markdown_id package has been installed. If this is not the case then you will likely need to set the PYTHONPATH environment variable so that the string_to_markdown_id package can be found.

(string_to_markdown_id) $ cd tests
(string_to_markdown_id) $ python -m unittest

Individual unit tests can be run also.

(string_to_markdown_id) $ python -m test_version

3.3. Coverage

The coverage tool is used to collect code test coverage metrics. Use the Makefile convenience rule to run the code coverage checks.

(string_to_markdown_id) $ make coverage

The test code coverage report can be found here

3.4. Code Style

Adopting a consistent code style assists with maintenance. This project uses Black to format code and isort to sort imports. Use the Makefile convenience rule to apply code style fixes.

(string_to_markdown_id) $ make style

3.4.1. Code Formatting

A Makefile convenience rule exists to perform just code format fixes.

(string_to_markdown_id) $ make format

3.4.2. Import Sorting

A Makefile convenience rule exists to perform just module import sorting fixes.

(string_to_markdown_id) $ make sort-imports

3.5. Static Analysis

A Makefile convenience rule exists to simplify performing static analysis checks. This will perform linting and type annotations checks.

(string_to_markdown_id) $ make check-static-analysis

3.5.1. Code Linting

A Makefile convenience rule exists to perform code linting checks.

(string_to_markdown_id) $ make check-lint

3.5.2. Type Annotations

The code base contains type annotations to provide helpful type information that can improve code maintenance. A Makefile convenience rule exists to check no type annotations issues are reported.

(string_to_markdown_id) $ make check-types

3.6. Documentation

To rebuild this project’s documentation, developers should use the Makefile in the top level directory. It performs a number of steps to create a new set of sphinx html content.

(string_to_markdown_id) $ make docs

To quickly check consistency of ReStructuredText files use the dummy run which does not actually generate HTML content.

(string_to_markdown_id) $ make check-docs

To quickly view the HTML rendered docs, start a simple web server and open a browser to http://127.0.0.1:8000/.

(string_to_markdown_id) $ make serve-docs

3.7. Release Process

The following steps are used to make a new software release.

The steps assume they are executed from within a development virtual environment.

  • Check that the package version label in __init__.py is correct.

  • Create and push a repo tag to Github. As a convention use the package version number (e.g. YY.MM.MICRO) as the tag.

    $ git checkout master
    $ git tag YY.MM.MICRO -m "A meaningful release tag comment"
    $ git tag  # check release tag is in list
    $ git push --tags origin master
    
    • This will trigger Github to create a release at:

      https://github.com/{username}/string_to_markdown_id/releases/{tag}
      
  • Create the release distribution. This project produces an artefact called a pure Python wheel. The wheel file will be created in the dist directory.

    (string_to_markdown_id) $ make dist
    
  • Test the release distribution. This involves creating a virtual environment, installing the distribution into it and running project tests against the installed distribution. These steps have been captured for convenience in a Makefile rule.

    (string_to_markdown_id) $ make dist-test
    
  • Upload the release to PyPI using

    (string_to_markdown_id) $ make dist-upload
    

    The package should now be available at https://pypi.org/project/string_to_markdown_id/