We welcome pull requests from cmd2 users and seasoned Python developers alike! Follow these steps
to contribute:
-
Find an issue that needs assistance by searching for the Help Wanted tag
-
Let us know you're working on it by posting a comment on the issue
-
Follow the Contribution guidelines below to start working on the issue
Remember to feel free to ask for help by leaving a comment within the Issue.
Working on your first pull request? You can learn how from the GitHub Docs.
If you've found a bug that is not on the board, follow these steps.
- Prerequisites
- Forking the project
- Creating a branch
- Setting up for cmd2 development
- Making changes
- Code Quality Checks
- Running the test suite
- Squashing your commits
- Creating a pull request
- Common steps
- How we review and merge pull requests
- How we close stale issues
- Next steps
- Other resources
- Advice
- Developing in an IDE
- Publishing a new release
cmd2 development is heavily based around using uv for Python
package and project management as well as creating and updating a local Python virtual environment.
We also rely on npm for installing a few dependencies like
prettier for formatting non-Python files.
We have a Makefile with commands that make it quick and easy for developers to get everything set up and perform common development tasks.
Nearly all project configuration, including for dependencies and quality tools is in the
pyproject.toml file other than for ruff which is in
ruff.toml.
Updating to the latest releases for all prerequisites via
uvis recommended. This can be done withuv lock --upgradefollowed byuv sync.
See the dependencies list under the [project] heading in pyproject.toml.
| Prerequisite | Minimum Version | Purpose |
|---|---|---|
| prompt-toolkit | 3.0.52 |
Replacement for GNU readline that is cross-platform |
| python | 3.10 |
Python programming language |
| pyperclip | 1.8 |
Cross-platform clipboard functions |
| rich | 14.3.0 |
Add rich text and beautiful formatting in the terminal |
| rich-argparse | 1.7.1 |
A rich-enabled help formatter for argparse |
Python 3.10 depends on backports.strenum to use the
enum.StrEnumclass introduced in Python 3.11.
See the build list under the [dependency-groups] heading in pyproject.toml
for a list of dependencies needed for building cmd2.
| Prerequisite | Minimum Version | Purpose |
|---|---|---|
| build | 1.2.2 |
Python build frontend |
| setuptools | 72.1.0 |
Python package management |
| setuptools-scm | 8.0.4 |
Manage your versions by scm tags |
uv-publish is also needed for publishing releases to PyPI, but that is something only core maintainers need to worry about.
See the dev list under the [dependency-groups] heading in pyproject.toml
for a list of dependencies needed for building cmd2.
| Prerequisite | Minimum Version | Purpose |
|---|---|---|
| codecov | 2.1.13 |
Cover coverage reporting |
| mypy | 1.13.0 |
Static type checker |
| pytest | 3.0.6 |
Unit and integration tests |
| pytest-cov | 6.0.0 |
Pytest code coverage |
| pytest-mock | 3.14.0 |
Pytest mocker fixture |
| mkdocstrings[python] | 0.27.0 |
Zensical plugin for Python AutoDoc |
| ruff | 0.7.3 |
Fast linter and formatter |
| uv | 0.5.1 |
Python package management |
| Zensical | 0.0.17 |
Markdown-based documentation |
If Python is already installed in your machine, run the following commands to validate the versions:
$ python -V
$ pip freeze | grep pyperclipIf your versions are lower than the prerequisite versions, you should update.
If you do not already have Python installed on your machine, we recommend using
uv for all of your Python needs because it is extremely fast,
meets all Python installation and packaging needs, and works on all platforms (Windows, Mac, and
Linux). You can install uv using instructions at the link above.
You can then install multiple versions of Python using uv like so:
uv python install 3.10 3.11 3.12 3.13- Install Git or your favorite Git client. If you aren't comfortable with Git at the command-line, then both SmartGit and GitKraken are excellent cross-platform graphical Git clients.
- (Optional) Set up an SSH key for GitHub.
- Create a parent projects directory on your system. For this guide, it will be assumed that it is
~/src.
- Go to the top-level cmd2 repository: https://github.com/python-cmd2/cmd2
- Click the "Fork" button in the upper right hand corner of the interface (more details here)
- After the repository has been forked, you will be taken to your copy of the cmd2 repo at
yourUsername/cmd2
- Open a terminal / command line / Bash shell in your projects directory (e.g.:
~/src/) - Clone your fork of cmd2, making sure to replace
yourUsernamewith your GitHub username. This will download the entire cmd2 repo to your projects directory.
$ git clone https://github.com/yourUsername/cmd2.git- Change directory to the new cmd2 directory (
cd cmd2) - Add a remote to the official cmd2 repo:
$ git remote add upstream https://github.com/python-cmd2/cmd2.gitCongratulations, you now have a local copy of the cmd2 repo!
Now that you have a copy of your fork, there is work you will need to do to keep it current.
Do this prior to every time you create a branch for a PR:
- Make sure you are on the
mainbranch
$ git status On branch main Your branch is up-to-date with 'origin/main'.
If your aren't on
main, resolve outstanding files and commits and checkout themainbranch
$ git checkout main
- Do a pull with rebase against
upstream
$ git pull --rebase upstream main
This will pull down all of the changes to the official mai branch, without making an additional commit in your local repo.
- (Optional) Force push your updated main branch to your GitHub fork
$ git push origin main --force
This will overwrite the main branch of your fork.
Before you start working, you will need to create a separate branch specific to the issue or feature you're working on. You will push your work to this branch.
Name the branch something like fix/xxx or feature/xxx where xxx is a short description of the
changes or feature you are attempting to add. For example fix/script-files would be a branch where
you fix something specific to script files.
To create a branch on your local machine (and switch to this branch):
$ git checkout -b [name_of_your_new_branch]and to push to GitHub:
$ git push origin [name_of_your_new_branch]this.
For doing cmd2 development, it is strongly recommended you create a virtual environment using uv
by following the instructions in the next section.
cmd2 has support for using uv for development.
uv is single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv,
and more. cmd2 contains configuration for using uv in it's pyproject.toml file which makes it
extremely easy to set up a cmd2 development environment using uv.
To create a virtual environment using the latest stable version of Python and install everything
needed for cmd2 development using uv, do the following from the root of your cloned cmd2
repository:
make installThis will also install the recommended Git pre-commit hooks for auto-formatting and linting locally.
To create a new virtualenv, using a specific version of Python you have installed, use the --python VERSION flag, like so:
uv venv --python 3.12Then you can run commands in this isolated virtual environment using uv like so:
uv run examples/hello_cmd2.pyAlternatively you can activate the virtual environment using the OS-specific command such as this on Linux or macOS:
source .venv/bin/activateAssuming you cloned the repository to ~/src/cmd2 and set up a virtual environment using uv,
cmd2 in this venv is in
editable mode. Changes to the
source code are immediately available when the python interpreter imports cmd2, there is no need
to re-install the module after every change. This command will also install all of the runtime
dependencies for cmd2 and modules used for development of cmd2:
$ cd ~/src/cmd2
$ uv venvThis project uses many python modules for various development tasks, including testing, rendering documentation, and building and distributing releases. These modules can be configured many different ways, which can make it difficult to learn the specific incantations required for each project you're familiar with.
This project uses make to provide a clean, high-level interface for these development tasks. To see the full list of make commands available:
$ make helpYou can run multiple make commands in a single invocation, for example::
$ make test docs-testThat one command will run all unit and integration tests and also ensure the documentation builds without any warnings.
If you want to see the details about what any of these commands are doing under the hood, just look at the Makefile.
Now you can check if everything is installed and working:
$ cd ~src/cmd2
$ make checkThis will run all auto-formatters, linters, and type checkers to ensure code quality. You should run this every time before committing any code. If this all runs successfully, then your virtual environment is set up and working properly.
You can also run the example app and see a prompt that says "(Cmd)" running the command:
$ uv run examples/getting_started.pyYou can type help to get help or quit to quit. If you see that, then congratulations – you're
all set. Otherwise, refer to the cmd2
installation instructions. There
also might be an error in the console of your Bash / terminal / command line that will help identify
the problem.
This bit is up to you!
The cmd2 project directory structure is pretty simple and straightforward. All actual code for cmd2
is located underneath the cmd2 directory. The code to generate the documentation is in the docs
directory. Unit and integration tests are in the tests directory. The examples directory
contains examples of how to use cmd2. There are various other files in the root directory, but these
are primarily related to continuous integration and release deployment.
If you made changes to any file in the /docs directory, you need to build the Zensical
documentation and make sure your changes look good:
$ make docs-testIn order to see the changes, use your web browser of choice to open ~/cmd2/build/html/index.html.
If you would rather use a webserver to view the documentation, including automatic page refreshes as you edit the files, use:
$ make docsYou will be shown the IP address and port number where the documents are now served, usually http://127.0.0.1:8000/.
You should have idiomatic formatters and linters running in your IDE or at the command line before
you commit code. cmd2 uses ruff as part of its continuous
integration (CI) process for both linting and auto-formatting of Python code. It also uses
prettier for auto-formatting other file types and
mypy for doing static type checking of Python code based on type
annotations.
Please do not ignore any linting errors in code you write or modify, as they are meant to help you and to ensure a clean and simple code base. Don't worry about linting errors in code you don't touch though - cleaning up the legacy code is a work in progress.
You can quickly run all code quality stuff in one fell swoop using:
make checkTo check if Python formatting is correct:
make formatNOTE: This will automatically fix the formatting, so just run it twice and it should be good.
To run the Python linter:
make lintmake typecheckWhen you're ready to share your code, run the test suite:
$ cd ~/cmd2
$ make testand ensure all tests pass.
Running the test suite also calculates test code coverage. A summary of coverage is shown on the
screen. A full report is available in ~/cmd2/htmlcov/index.html.
While squashing your commits is best practice, don't worry about it. We do this automatically when we merge in Pull Requests (PRs).
If you want to understand how to do this manually, see this article.
A pull request (PR) is a method of submitting proposed changes to the cmd2 repo (or any repo, for that matter). You will make changes to copies of the files which make up cmd2 in a personal fork, then apply to have them accepted by cmd2 proper.
GitHub has a good guide on how to contribute to open source here.
If you take away only one thing from this document, it should be this: Never, EVER make edits to
the main branch. ALWAYS make a new branch BEFORE you edit files. This is critical, because if your
PR is not accepted, your copy of main will be forever sullied and the only way to fix it is to
delete your fork and re-fork.
There are two methods of creating a pull request for cmd2:
- Editing files on a local clone (recommended)
- Editing files via the GitHub Interface
This is the recommended method. Read about how to set up and maintain a local instance of cmd2.
- Perform the maintenance step of rebasing
main - Ensure you're on the
mainbranch usinggit status:
$ git status
On branch main
Your branch is up-to-date with 'origin/main'.
nothing to commit, working directory clean-
If you're not on main or your working directory is not clean, resolve any outstanding files/commits and checkout main
git checkout main -
Create a branch off of
mainwith git:git checkout -B branch/name-hereNote: Branch naming is important. Use a name likefix/short-fix-descriptionorfeature/short-feature-description. Review the Contribution Guidelines for more detail. -
Edit your file(s) locally with the editor of your choice
-
Check your
git statusto see unstaged files -
Add your edited files:
git add path/to/filename.extYou can also do:git add .to add all unstaged files. Take care, though, because you can accidentally add files you don't want added. Review yourgit statusfirst. -
Commit your edits:
git commit -m "Brief description of commit". Do not add the issue number in the commit message. -
Squash your commits, if there are more than one
-
Push your commits to your GitHub Fork:
git push -u origin branch/name-here -
Go to Common steps
Note: Editing via the GitHub Interface is not recommended, since it is not possible to update your fork via GitHub's interface without deleting and recreating your fork.
If you really want to go this route (which isn't recommended), you can Google for more information on how to do it.
-
Once the edits have been committed, you will be prompted to create a pull request on your fork's GitHub page
-
By default, all pull requests should be against the cmd2 main repo,
mainbranch -
Submit a pull request from your branch to cmd2's
mainbranch -
The title (also called the subject) of your PR should be descriptive of your changes and succinctly indicate what is being fixed
-
Do not add the issue number in the PR title or commit message
-
Examples:
Add test cases for Unicode support;Correct typo in overview documentation
-
-
In the body of your PR include a more detailed summary of the changes you made and why
- If the PR is meant to fix an existing bug/issue, then, at the end of your PR's description,
append the keyword
closesand #xxxx (where xxxx is the issue number). Example:closes #1337. This tells GitHub to close the existing issue if the PR is merged.
- If the PR is meant to fix an existing bug/issue, then, at the end of your PR's description,
append the keyword
-
Indicate what local testing you have done (e.g. what OS and version(s) of Python did you run the unit test suite with)
-
Creating the PR causes our continuous integration (CI) systems to automatically run all of the unit tests on all supported OSes and all supported versions of Python. You should watch your PR to make sure that all unit tests pass on every version of Python for each of Linux, Windows, and macOS.
-
If any unit tests fail, you should look at the details and fix the failures. You can then push the fix to the same branch in your fork. The PR will automatically get updated and the CI system will automatically run all of the unit tests again.
cmd2 has a team of volunteer Maintainers. These Maintainers routinely go through open pull requests in a process called Quality Assurance (QA). We use GitHub Actions to automatically run all of the unit tests on multiple operating systems and versions of Python and to also run the code quality checks on at least one version of Python.
-
If your changes can merge without conflicts and all unit tests pass for all OSes and supported versions of Python, then your pull request (PR) will have a big green checkbox which says something like "All Checks Passed" next to it. If this is not the case, there will be a link you can click on to get details regarding what the problem is. It is your responsibility to make sure all unit tests are passing. Generally a Maintainer will not QA a pull request unless it can merge without conflicts and all unit tests pass on all supported platforms.
-
If a Maintainer QA's a pull request and confirms that the new code does what it is supposed to do without seeming to introduce any new bugs, and doesn't present any backward compatibility issues, they will merge the pull request.
If you would like to apply to join our Maintainer team, message @tleonhardt with links to 5 of your pull requests that have been accepted.
We will close any issues that have been inactive for more than 60 days or pull requests that have been inactive for more than 30 days, except those that match any of the following criteria:
- bugs that are confirmed
- pull requests that are waiting on other pull requests to be merged
- features that are part of a cmd2 GitHub Milestone or Project
Once your PR is accepted, you may delete the branch you created to submit it. This keeps your working fork clean.
You can do this with a press of a button on the GitHub PR interface. You can delete the local copy
of the branch with: git branch -D branch/to-delete-name
Don't despair! You should receive solid feedback from the Maintainers as to why it was rejected and what changes are needed.
Many pull requests, especially first pull requests, require correction or updating. If you have used the GitHub interface to create your PR, you will need to close your PR, create a new branch, and re-submit.
If you have a local copy of the repo, you can make the requested changes and amend your commit with:
git commit --amend This will update your existing commit. When you push it to your fork you will
need to do a force push to overwrite your old commit: git push --force
Be sure to post in the PR conversation that you have made the requested changes.
Here is some advice regarding what makes a good pull request (PR) from the perspective of the cmd2 maintainers:
- Multiple smaller PRs divided by topic are better than a single large PR containing a bunch of unrelated changes
- Maintaining backward compatibility is important
- Good unit/functional tests are very important
- Accurate documentation is also important
- Adding new features is of the lowest importance, behind bug fixes, unit test additions/improvements, code cleanup, and documentation
- It's best to create a dedicated branch for a PR, use it only for that PR, and delete it once the PR has been merged
- It's good if the branch name is related to the PR contents, even if it's just "fix123" or "add_more_tests"
- Code coverage of the unit tests matters, so try not to decrease it
- Think twice before adding dependencies to third-party libraries (outside of the Python standard library) because it could affect a lot of users
We recommend using Visual Studio Code with the Python extension and its Integrated Terminal debugger for debugging since it has excellent support for debugging console applications.
PyCharm is also quite good and has very nice code inspection capabilities.
One of the best things about PyCharm is that it "just works" with essentially no configuration tweaks required. The default out-of-the-box experience is excellent.
The one plugin we consider essential for PyCharm is
RyeCharm. RyeCharm is an all-in-one PyCharm
plugin for Astral-backed Python tools: uv,
Ruff, and ty. NOTE: ty
support is provisional as that new type checker is in early alpha development.
While VSCode is a phenomenal IDE for developing in Python, the out-of-the-box experience leaves a lot to be desired. You will need to install a number of extensions and tweak the default configuration for many of them in order to get an optimal developer experience.
Recommended VSCode extensions:
- Python - Python language support with extension access points for IntelliSense (Pylance), Debugging (Python Debugger), linting, formatting, etc.
- Prettier - Code formatter for Markdown and YAML files
- GitLens - Supercharges Git support in VSCode
- YAML - YAML language support
- Code Spell Checker - Spell checker for source code
- Markdown All in One - All you need to write Markdown (keyboard shortcuts, table of contents, auto preview and more)
- Makefile Tools - Provide makefile support in VS Code
- Even Better TOML - Fully-featured TOML support
- Markdown Preview Mermaid Support - Adds Mermaid diagram and flowchart support to VS Code's builtin markdown preview
- Ruff - Support for the Ruff linter and formatter
Depending on what file types you are editing, you may only need a subset of those extensions.
Here is an example of what your User Settings JSON file in VSCode might look like for a good
experience, take it as a starting point and tweak as you see fit
{
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true,
"editor.largeFileOptimizations": false,
"editor.renderWhitespace": "trailing",
"git.blame.editorDecoration.enabled": false,
"git.openRepositoryInParentFolders": "always",
"gitlens.telemetry.enabled": false,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true
},
"python.analysis.ignore": ["*"],
"python.terminal.shellIntegration.enabled": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"redhat.telemetry.enabled": false,
"ruff.lineLength": 127,
"security.workspace.trust.untrustedFiles": "open",
"telemetry.telemetryLevel": "off",
"[toml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"yaml.schemas": {
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml"
},
"yaml.customTags": [
"!ENV scalar",
"!ENV sequence",
"!relative scalar",
"tag:yaml.org,2002:python/name:material.extensions.emoji.to_svg",
"tag:yaml.org,2002:python/name:material.extensions.emoji.twemoji",
"tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format",
"tag:yaml.org,2002:python/object/apply:pymdownx.slugs.slugify mapping"
],
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}Starting with version 1.0.0, cmd2 has adopted Semantic Versioning.
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJORversion when you make incompatible API changes,MINORversion when you add functionality in a backwards compatible manner, andPATCHversion when you make backwards compatible bug fixes.
We use the main branch for the upcoming PATCH release - i.e. if the current version of cmd2
is 1.0.2, then the main branch contains code which is planned for release in 1.0.3.
If work needs to be done for a MAJOR or MINOR release when we anticipate there will be a PATCH
release in-between, then a branch should be created named for the appropriate version number for the
work, e.g. if the current release of cmd2 is 1.0.2 and a backwards-incompatible change needs to be
committed for an upcoming MAJOR release, then this work should be committed to a 2.0.0 branch
until such a time as we are ready to release version 2.0.0.
Following this strategy, releases are always done from the main branch and MAJOR or MINOR
branches are merged to main immediately prior to doing a release. Once merged to main, the
other branches can be deleted. All releases are tagged so that they can be reproduced if necessary.
Since 0.9.2, the process of publishing a new release of cmd2 to PyPi has been
mostly automated. The manual steps are all git operations. Here's the checklist:
- Make sure you're on the proper branch (almost always main)
- Make sure all the unit tests pass with
make test - Make sure latest year in
LICENSEmatches current year - Make sure
CHANGELOG.mddescribes the version and has the correct release date - Add a git tag representing the version number using
make tag TAG=x.y.z- Where x, y, and z are all small non-negative integers
- (Optional) Run
make publish-testto clean, build, and upload a new release to Test PyPi - Run
make publishto clean, build, and upload a new release to PyPi
Thanks to the good folks at freeCodeCamp for
creating an excellent CONTRIBUTING file which we have borrowed heavily from.