Skip to content

Commit

Permalink
Removed support for Python 3.7 and added unit testing for 3.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 12, 2024
1 parent 5ee1f15 commit 23580a7
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 98 deletions.
50 changes: 25 additions & 25 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We welcome pull requests from cmd2 users and seasoned Python developers alike! F

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 this *free* series
Working on your first pull request? You can learn how from this *free* series
[How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).

###### If you've found a bug that is not on the board, [follow these steps](README.md#found-a-bug).
Expand Down Expand Up @@ -47,7 +47,7 @@ The tables below list all prerequisites along with the minimum required version

| Prerequisite | Minimum Version |
| --------------------------------------------------- |-----------------|
| [python](https://www.python.org/downloads/) | `3.7` |
| [python](https://www.python.org/downloads/) | `3.8` |
| [pyperclip](https://github.com/asweigart/pyperclip) | `1.6` |
| [setuptools](https://pypi.org/project/setuptools/) | `34.4` |
| [wcwidth](https://pypi.python.org/pypi/wcwidth) | `0.1.7` |
Expand Down Expand Up @@ -81,32 +81,32 @@ $ pip freeze | grep pyperclip

If 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 the
[Anaconda](https://www.continuum.io/downloads) distribution because it provides an excellent out-of-the-box install on
all platforms (Windows, Mac, and Linux) and because it supports having multiple Python environments (versions of Python)
If you do not already have Python installed on your machine, we recommend using the
[Anaconda](https://www.continuum.io/downloads) distribution because it provides an excellent out-of-the-box install on
all platforms (Windows, Mac, and Linux) and because it supports having multiple Python environments (versions of Python)
installed simultaneously.

### Forking the project

#### Setting up your system

1. Install [Git](https://git-scm.com/) or your favorite Git client. If you aren't comfortable with Git at the
command-line, then both [SmartGit](http://www.syntevo.com/smartgit/) and [GitKraken](https://www.gitkraken.com) are
1. Install [Git](https://git-scm.com/) or your favorite Git client. If you aren't comfortable with Git at the
command-line, then both [SmartGit](http://www.syntevo.com/smartgit/) and [GitKraken](https://www.gitkraken.com) are
excellent cross-platform graphical Git clients.
2. (Optional) [Set up an SSH key](https://help.github.com/articles/generating-an-ssh-key/) for GitHub.
3. Create a parent projects directory on your system. For this guide, it will be assumed that it is `~/src`.

#### Forking cmd2

1. Go to the top-level cmd2 repository: <https://github.com/python-cmd2/cmd2>
2. Click the "Fork" button in the upper right hand corner of the interface
2. Click the "Fork" button in the upper right hand corner of the interface
([more details here](https://help.github.com/articles/fork-a-repo/))
3. After the repository has been forked, you will be taken to your copy of the cmd2 repo at `yourUsername/cmd2`

#### Cloning your fork

1. Open a terminal / command line / Bash shell in your projects directory (_e.g.: `~/src/`_)
2. Clone your fork of cmd2, making sure to replace `yourUsername` with your GitHub username. This will download the
2. Clone your fork of cmd2, making sure to replace `yourUsername` with your GitHub username. This will download the
entire cmd2 repo to your projects directory.

```sh
Expand Down Expand Up @@ -164,13 +164,13 @@ Do this prior to every time you create a branch for a PR:
### Creating a branch
Before you start working, you will need to create a separate branch specific to the issue or feature you're working on.
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.
#### Naming your 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
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.
#### Adding your branch
Expand All @@ -191,22 +191,22 @@ $ git push origin [name_of_your_new_branch]


### Setting up for cmd2 development
For doing cmd2 development, it is recommended you create a virtual environment using Conda or Virtualenv and install the
For doing cmd2 development, it is recommended you create a virtual environment using Conda or Virtualenv and install the
package from the source.

#### Create a new environment for cmd2 using Pipenv
`cmd2` has support for using [Pipenv](https://docs.pipenv.org/en/latest/) for development.
`cmd2` has support for using [Pipenv](https://docs.pipenv.org/en/latest/) for development.

`Pipenv` essentially combines the features of `pip` and `virtualenv` into a single tool. `cmd2` contains a Pipfile which
makes it extremely easy to setup a `cmd2` development environment using `pipenv`.
makes it extremely easy to setup a `cmd2` development environment using `pipenv`.

To create a virtual environment and install everything needed for `cmd2` development using `pipenv`, do the following
To create a virtual environment and install everything needed for `cmd2` development using `pipenv`, do the following
from a GitHub checkout:
```sh
pipenv install --dev
```

To create a new virtualenv, using a specific version of Python you have installed (and on your PATH), use the
To create a new virtualenv, using a specific version of Python you have installed (and on your PATH), use the
--python VERSION flag, like so:
```sh
pipenv install --dev --python 3.8
Expand All @@ -219,8 +219,8 @@ pipenv shell

#### Create a new environment for cmd2 using Conda
```sh
$ conda create -n cmd2_py37 python=3.7
$ conda activate cmd2_py37
$ conda create -n cmd2_py38 python=3.8
$ conda activate cmd2_py38
```

#### Create a new environment for cmd using Virtualenv
Expand All @@ -233,15 +233,15 @@ pyenv versions
# Install python version defined
pyenv install 3.8.2
```
With the Python version installed, you can set the virtualenv properly.
With the Python version installed, you can set the virtualenv properly.

```sh
$ cd ~/src/cmd2
$ virtualenv -p $(pyenv root)/versions/3.8.2/ cmd_py38
$ virtualenv -p $(pyenv root)/versions/3.8.2/ cmd_py38
$ source ~/src/cmd2/bin/activate
```

Assuming you cloned the repository to `~/src/cmd2` you can install cmd2 in
Assuming you cloned the repository to `~/src/cmd2` you can install cmd2 in
[editable mode](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs).
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
Expand Down Expand Up @@ -326,9 +326,9 @@ served (usually [http://localhost:8000](http://localhost:8000)).

### Static code analysis

You should have some sort of [PEP 8](https://www.python.org/dev/peps/pep-0008/)-based linting running in your editor or
You should have some sort of [PEP 8](https://www.python.org/dev/peps/pep-0008/)-based linting running in your editor or
IDE or at the command line before you commit code. `cmd2` uses [flake8](http://flake8.pycqa.org/en/latest/) as part of
its continuous integration (CI) process. [pylint](https://www.pylint.org) is another good Python linter which can be
its continuous integration (CI) process. [pylint](https://www.pylint.org) is another good Python linter which can be
run at the command line but also can integrate with many IDEs and editors.

> 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.
Expand Down Expand Up @@ -579,7 +579,7 @@ mostly automated. The manual steps are all git operations. Here's the checklist:
1. Make sure all the unit tests pass with `invoke pytest` or `py.test`
1. Make sure latest year in `LICENSE` matches current year
1. Make sure `CHANGELOG.md` describes the version and has the correct release date
1. Add a git tag representing the version number using ``invoke tag x.y.z``
1. Add a git tag representing the version number using ``invoke tag x.y.z``
* Where x, y, and z are all small non-negative integers
1. (Optional) Run `invoke pypi-test` to clean, build, and upload a new release to [Test PyPi](https://test.pypi.org)
1. Run `invoke pypi` to clean, build, and upload a new release to [PyPi](https://pypi.org/)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
python-version: ["3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
python-version: ["3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
python-version: ["3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
python-version: ["3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## 2.5.0 (TBD)
* Breaking Change
* `cmd2` 2.5 supports Python 3.7+ (removed support for Python 3.6)
* `cmd2` 2.5 supports Python 3.8+ (removed support for Python 3.6 and 3.7)
* Bug Fixes
* Fixed issue where persistent history file was not saved upon SIGHUP and SIGTERM signals.
* Enhancements
* Removed dependency on `attrs` and replaced with [dataclasses](https://docs.python.org/3/library/dataclasses.html)
* add `allow_clipboard` initialization parameter and attribute to disable ability to
add output to the operating system clipboard
* Updated unit tests to be Python 3.12 compliant.
* Deletions (potentially breaking changes)
* Removed `apply_style` from `Cmd.pwarning()`.

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ The developers toolbox
![system schema](https://raw.githubusercontent.com/python-cmd2/cmd2/master/.github/images/graph.drawio.png)


When creating solutions developers have no shortage of tools to create rich and smart user interfaces.
System administrators have long been duct taping together brittle workflows based on a menagerie of simple command line tools created by strangers on github and the guy down the hall.
Unfortunately, when CLIs become significantly complex the ease of command discoverability tends to fade quickly.
On the other hand, Web and traditional desktop GUIs are first in class when it comes to easily discovering functionality.
When creating solutions developers have no shortage of tools to create rich and smart user interfaces.
System administrators have long been duct taping together brittle workflows based on a menagerie of simple command line tools created by strangers on github and the guy down the hall.
Unfortunately, when CLIs become significantly complex the ease of command discoverability tends to fade quickly.
On the other hand, Web and traditional desktop GUIs are first in class when it comes to easily discovering functionality.
The price we pay for beautifully colored displays is complexity required to aggregate disperate applications into larger systems.
`cmd2` fills the niche between high [ease of command discovery](https://clig.dev/#ease-of-discovery) applications and smart workflow automation systems.
`cmd2` fills the niche between high [ease of command discovery](https://clig.dev/#ease-of-discovery) applications and smart workflow automation systems.

The `cmd2` framework provides a great mixture of both worlds. Application designers can easily create complex applications and rely on the cmd2 library to offer effortless user facing help and extensive tab completion.
The `cmd2` framework provides a great mixture of both worlds. Application designers can easily create complex applications and rely on the cmd2 library to offer effortless user facing help and extensive tab completion.
When users become comfortable with functionality, cmd2 turns into a feature rich library enabling a smooth transition to full automation. If designed with enough forethought, a well implemented cmd2 application can serve as a boutique workflow tool. `cmd2` pulls off this flexibility based on two pillars of philosophy:

* Tab Completion
Expand Down Expand Up @@ -78,7 +78,7 @@ On all operating systems, the latest stable version of `cmd2` can be installed u
pip install -U cmd2
```

cmd2 works with Python 3.7+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies.
cmd2 works with Python 3.8+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies.

For information on other installation options, see
[Installation Instructions](https://cmd2.readthedocs.io/en/latest/overview/installation.html) in the cmd2
Expand All @@ -97,7 +97,7 @@ The best way to learn the cmd2 api is to delve into the example applications loc
Tutorials
---------

* PyOhio 2019 presentation:
* PyOhio 2019 presentation:
* [video](https://www.youtube.com/watch?v=pebeWrTqIIw)
* [slides](https://github.com/python-cmd2/talks/blob/master/PyOhio_2019/cmd2-PyOhio_2019.pdf)
* [example code](https://github.com/python-cmd2/talks/tree/master/PyOhio_2019/examples)
Expand Down Expand Up @@ -161,4 +161,4 @@ Projects using cmd2
Possibly defunct but still good examples

* [JSShell](https://github.com/Den1al/JSShell)
* [FLASHMINGO](https://github.com/fireeye/flashmingo)
* [FLASHMINGO](https://github.com/fireeye/flashmingo)
15 changes: 2 additions & 13 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,32 +257,21 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
List,
NoReturn,
Optional,
Protocol,
Sequence,
Set,
Tuple,
Type,
Union,
cast,
runtime_checkable,
)

from . import (
ansi,
constants,
)

try:
from typing import (
Protocol,
runtime_checkable,
)
except ImportError:
# Remove these imports when we no longer support Python 3.7
from typing_extensions import ( # type: ignore[assignment]
Protocol,
runtime_checkable,
)


if TYPE_CHECKING: # pragma: no cover
from .argparse_completer import (
ArgparseCompleter,
Expand Down
5 changes: 2 additions & 3 deletions docs/features/argument_processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ Here's what it looks like::
.. warning::

It is important that each command which uses the ``@with_argparser``
decorator be passed a unique instance of a parser. This limitation is due
to bugs in CPython prior to Python 3.7 which make it impossible to make a
deep copy of an instance of a ``argparse.ArgumentParser``.
decorator be passed a unique instance of a parser since command-specific
changes could be made to it.


.. note::
Expand Down
4 changes: 2 additions & 2 deletions docs/overview/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Installation Instructions
.. _setuptools: https://pypi.org/project/setuptools
.. _PyPI: https://pypi.org

``cmd2`` works on Linux, macOS, and Windows. It requires Python 3.7 or
``cmd2`` works on Linux, macOS, and Windows. It requires Python 3.8 or
higher, pip_, and setuptools_. If you've got all that, then you can just:

.. code-block:: shell
Expand All @@ -30,7 +30,7 @@ higher, pip_, and setuptools_. If you've got all that, then you can just:
Prerequisites
-------------

If you have Python 3 >=3.7 installed from `python.org
If you have Python 3 >=3.8 installed from `python.org
<https://www.python.org>`_, you will already have pip_ and setuptools_, but may
need to upgrade to the latest versions:

Expand Down
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nox


@nox.session(python=['3.11'])
@nox.session(python=['3.12'])
def docs(session):
session.install(
'sphinx',
Expand All @@ -17,7 +17,7 @@ def docs(session):
)


@nox.session(python=['3.7', '3.8', '3.9', '3.10', '3.11'])
@nox.session(python=['3.8', '3.9', '3.10', '3.11', '3.12'])
@nox.parametrize('plugin', [None, 'ext_test', 'template', 'coverage'])
def tests(session, plugin):
if plugin is None:
Expand All @@ -41,7 +41,7 @@ def tests(session, plugin):
)


@nox.session(python=['3.8', '3.9', '3.10', '3.11'])
@nox.session(python=['3.8', '3.9', '3.10', '3.11', '3.12'])
@nox.parametrize('step', ['mypy', 'flake8'])
def validate(session, step):
session.install('invoke', './[validate]')
Expand Down
4 changes: 2 additions & 2 deletions plugins/ext_test/build-pyenvs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# version numbers are: major.minor.patch
#
# this script will delete and recreate existing virtualenvs named
# cmd2-3.7, etc. It will also create a .python-version
# cmd2-3.8, etc. It will also create a .python-version
#
# Prerequisites:
# - *nix-ish environment like macOS or Linux
Expand All @@ -23,7 +23,7 @@
# virtualenvs will be added to '.python-version'. Feel free to modify
# this list, but note that this script intentionally won't install
# dev, rc, or beta python releases
declare -a pythons=("3.7" "3.8" "3.9", "3.10", "3.11")
declare -a pythons=("3.8" "3.9", "3.10", "3.11", "3.12")

# function to find the latest patch of a minor version of python
function find_latest_version {
Expand Down
8 changes: 1 addition & 7 deletions plugins/ext_test/cmd2_ext_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
Allows developers to exercise their cmd2 application using the PyScript interface
"""

try:
# For python 3.8 and later
import importlib.metadata as importlib_metadata
except ImportError: # pragma: no cover
# Remove this import when we no longer support Python 3.7
# MyPy Issue # 1153 causes a spurious error that must be ignored
import importlib_metadata # type: ignore
import importlib.metadata as importlib_metadata

try:
__version__ = importlib_metadata.version(__name__)
Expand Down
2 changes: 1 addition & 1 deletion plugins/ext_test/noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nox


@nox.session(python=['3.7', '3.8', '3.9', '3.10', '3.11'])
@nox.session(python=['3.8', '3.9', '3.10', '3.11', '3.12'])
def tests(session):
session.install('invoke', './[test]')
session.run('invoke', 'pytest', '--junit', '--no-pty')
Loading

0 comments on commit 23580a7

Please sign in to comment.