You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our Contributor's Guide had a lot of outdated information in it. This updates it to solidly use the modern development workflow based around uv, make, and pre-commit.
Also:
- Update pre-commit to also check TOML files
- Updated "make install" command to use the latest stable version of Python for the virtual environment, downloading that for uv if necessary, and also to install pre-commit hooks as well as prettier from npm.
|[wcwidth](https://pypi.python.org/pypi/wcwidth)|`0.2.10`| Measure the displayed width of unicode |
63
+
64
+
> `macOS` and `Windows` each have an extra dependency to ensure they have a viable alternative to [readline](https://tiswww.case.edu/php/chet/readline/rltop.html) available.
54
65
55
66
#### Additional prerequisites to build and publish cmd2
See the `build` list under the `[dependency-groups]` heading in [pyproject.toml](../pyproject.toml) for a list of dependencies needed for building `cmd2`.
|[setuptools-scm](https://github.com/pypa/setuptools-scm)|`8.0.4`| Manage your versions by scm tags |
75
+
76
+
> [twine](https://github.com/pypa/twine) 5.1 or newer is also needed for publishing releases to PyPI, but that is something only core maintainers need to worry about.
63
77
64
78
#### Additional prerequisites for developing cmd2
65
79
80
+
See the `dev` list under the `[dependency-groups]` heading in [pyproject.toml](../pyproject.toml) for a list of dependencies needed for building `cmd2`.
For doing cmd2 development, it is recommended you create a virtual environment using Conda or Virtualenv and install the
209
-
package from the source.
224
+
For doing `cmd2` development, it is strongly recommended you create a virtual environment `uv` using the instructions in the next section.
210
225
211
226
#### Create a new environment for cmd2 using uv
212
227
@@ -216,18 +231,14 @@ package from the source.
216
231
contains configuration for using `uv` in it's `pyproject.toml` file which makes it extremely easy to setup a `cmd2`
217
232
development environment using `uv`.
218
233
219
-
To create a virtual environment and install everything needed for `cmd2` development using `uv`, do the following
220
-
from a GitHub checkout:
234
+
To create a virtual environment using the latest stable version of Python and install everything needed for `cmd2` development using `uv`,
235
+
do the following from the root of your cloned `cmd2` repository:
221
236
222
237
```sh
223
238
make install
224
239
```
225
240
226
-
To install the recommended Git pre-commit hooks for auto-formatting locally, do the following:
227
-
228
-
```sh
229
-
uv run pre-commit run -a
230
-
```
241
+
This will also install the recommended Git pre-commit hooks for auto-formatting and linting locally.
231
242
232
243
To create a new virtualenv, using a specific version of Python you have installed, use the
233
244
--python VERSION flag, like so:
@@ -264,35 +275,31 @@ testing, rendering documentation, and building and distributing releases. These
264
275
modules can be configured many different ways, which can make it difficult to
265
276
learn the specific incantations required for each project you're familiar with.
266
277
267
-
This project uses `invoke <http://www.pyinvoke.org>` to provide a clean,
268
-
high-level interface for these development tasks. To see the full list of functions
269
-
available:
278
+
This project uses [make]() to provide a clean, high-level interface for these development tasks. To see the full list of make commands available:
270
279
271
280
```sh
272
-
$ uv run inv -l
281
+
$ make help
273
282
```
274
283
275
-
You can run multiple tasks in a single invocation, for example::
284
+
You can run multiple make commands in a single invocation, for example::
276
285
277
286
```sh
278
-
$ uv run inv docs sdist wheel
287
+
$ make testdocs-test
279
288
```
280
289
281
-
That one command will remove all superfluous cache, testing, and build
282
-
files, render the documentation, and build a source distribution and a
283
-
wheel distribution.
290
+
That one command will run all unit and integration tests and also ensure the documentation builds without any warnings.
284
291
285
-
If you want to see the details about what `invoke` is doing under the hood,
286
-
have a look at `tasks.py`.
292
+
If you want to see the details about what any of these commands are doing under the hood, just look at the [Makefile](../Makefile).
287
293
288
294
Now you can check if everything is installed and working:
289
295
290
296
```sh
291
297
$ cd~src/cmd2
292
-
$ uv run inv pytest
298
+
$ make check
293
299
```
294
300
295
-
If the tests are executed it means that dependencies and project are installed successfully.
301
+
This will run all auto-formatters, linters, and type checkers to ensure code quality. You should run this every time before committing any code.
302
+
If this all runs successfully, then your virtual environment is setup and working properly.
296
303
297
304
You can also run the example app and see a prompt that says "(Cmd)" running the command:
298
305
@@ -315,67 +322,71 @@ This bit is up to you!
315
322
The cmd2 project directory structure is pretty simple and straightforward. All
316
323
actual code for cmd2 is located underneath the `cmd2` directory. The code to
317
324
generate the documentation is in the `docs` directory. Unit tests are in the
318
-
`tests` directory. The `examples` directory contains examples of how to use
319
-
cmd2. There are various other files in the root directory, but these are
320
-
primarily related to continuous integration and release deployment.
325
+
`tests` directory. Integration tests are in the `tests_isolated` directory.
326
+
The `examples` directory contains examples of how to use cmd2. There are various
327
+
other files in the root directory, but these are primarily related to continuous
328
+
integration and release deployment.
321
329
322
330
#### Changes to the documentation files
323
331
324
332
If you made changes to any file in the `/docs` directory, you need to build the
325
333
MkDocs documentation and make sure your changes look good:
326
334
327
335
```sh
328
-
$ uv inv docs
336
+
$ make docs-test
329
337
```
330
338
331
-
In order to see the changes, use your web browser of choice to open `~/cmd2/docs/_build/html/index.html`.
339
+
In order to see the changes, use your web browser of choice to open `~/cmd2/build/html/index.html`.
332
340
333
341
If you would rather use a webserver to view the documentation, including
334
342
automatic page refreshes as you edit the files, use:
335
343
336
344
```sh
337
-
$ uv inv livehtml
345
+
$ make docs
338
346
```
339
347
340
348
You will be shown the IP address and port number where the documents are now
341
-
served (usually [http://localhost:8000](http://localhost:8000)).
349
+
served, usually [http://127.0.0.1:8000/](http://127.0.0.1:8000/).
342
350
343
351
### Code Quality Checks
344
352
345
-
You should have some sort of [PEP 8](https://www.python.org/dev/peps/pep-0008/)-based linting running in your editor or
346
-
IDE or at the command line before you commit code. `cmd2` uses [ruff](https://github.com/astral-sh/ruff) as part of
347
-
its continuous integration (CI) process for both linting and auto-formatting.
353
+
You should have idiomatic formatters and linters running in your IDE or at the command line before you commit code.
354
+
`cmd2` uses [ruff](https://github.com/astral-sh/ruff) as part of its continuous integration (CI) process for both linting and auto-formatting of
355
+
Python code. It also uses [prettier](https://prettier.io/) for auto-formatting other file types and [mypy](https://mypy-lang.org/) for doing
356
+
static type checking of Python code based on type annotations.
348
357
349
358
> Please do not ignore any linting errors in code you write or modify, as they are meant to **help** you and to ensure a
350
359
> clean and simple code base. Don't worry about linting errors in code you don't touch though - cleaning up the legacy
351
360
> code is a work in progress.
352
361
353
-
#### Formatting
354
-
355
-
To check if formatting is correct:
362
+
You can quickly run all code quality stuff in one fell swoop using:
356
363
357
364
```sh
358
-
uv run inv format
365
+
make check
359
366
```
360
367
361
-
To automatically fix formatting:
368
+
#### Python Formatting
369
+
370
+
To check if Python formatting is correct:
362
371
363
372
```sh
364
-
uv run ruff format
373
+
make format
365
374
```
366
375
376
+
NOTE: This will automatically fix the formatting, so just run it twice and it should be good.
377
+
367
378
#### Linting
368
379
369
-
To run the linter:
380
+
To run the Python linter:
370
381
371
382
```shell
372
-
uv run inv lint
383
+
make lint
373
384
```
374
385
375
386
#### Static Type Checking
376
387
377
388
```shell
378
-
uv run inv mypy
389
+
make typecheck
379
390
```
380
391
381
392
### Running the test suite
@@ -384,7 +395,7 @@ When you're ready to share your code, run the test suite:
384
395
385
396
```sh
386
397
$ cd~/cmd2
387
-
$ uv run pytest
398
+
$ make test
388
399
```
389
400
390
401
and ensure all tests pass.
@@ -394,9 +405,9 @@ is shown on the screen. A full report is available in `~/cmd2/htmlcov/index.html
394
405
395
406
### Squashing your commits
396
407
397
-
When you make a pull request, it is preferable for all of your changes to be in one commit.
398
-
If you have made more then one commit, then you can _squash_ your commits.
399
-
To do this, see [this article](http://forum.freecodecamp.com/t/how-to-squash-multiple-commits-into-one-with-git/13231).
408
+
While squashing your commits is best practice, don't worry about it. We do this automatically when we merge in Pull Requests (PRs).
409
+
410
+
If you want to understand how to do this manually, see [this article](http://forum.freecodecamp.com/t/how-to-squash-multiple-commits-into-one-with-git/13231).
400
411
401
412
### Creating a pull request
402
413
@@ -515,9 +526,9 @@ how to do it.
515
526
### How we review and merge pull requests
516
527
517
528
cmd2 has a team of volunteer Maintainers. These Maintainers routinely go through open pull requests in a process
518
-
called [Quality Assurance](https://en.wikipedia.org/wiki/Quality_assurance) (QA). We also use multiple continuous
519
-
integration (CI) providers to automatically run all of the unit tests on multiple operating systems and versions of
520
-
Python.
529
+
called [Quality Assurance](https://en.wikipedia.org/wiki/Quality_assurance) (QA). We use [GitHub Actions](https://github.com/features/actions)
530
+
to automatically run all of the unit tests on multiple operating systems and versions of Python and to also run the code quality checks
531
+
on at least one version of Python.
521
532
522
533
1. If your changes can merge without conflicts and all unit tests pass for all OSes and supported versions of Python,
523
534
then your pull request (PR) will have a big green checkbox which says something like "All Checks Passed" next to it.
@@ -601,6 +612,93 @@ excellent support for debugging console applications.
601
612
[PyCharm](https://www.jetbrains.com/pycharm/) is also quite good and has very
One of the best things about **PyCharm** is that it "just works" with essentially no configuration tweaks required. The
618
+
default out-of-the-box experience is excellent.
619
+
620
+
The one plugin we consider essential for PyCharm is [RyeCharm](https://plugins.jetbrains.com/plugin/25230-ryecharm). `RyeCharm` is an all-in-one PyCharm plugin for [Astral](https://astral.sh/)-backed Python tools: [uv](https://github.com/astral-sh/uv), [Ruff](https://github.com/astral-sh/ruff), and [ty](https://github.com/astral-sh/ty). NOTE: `ty` support is provisional as that new type checker is in early alpha developement.
621
+
622
+
#### VSCode Settings
623
+
624
+
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
625
+
number of extenstions and tweak the default configuration for many of them in order to get an optimal developer experience.
626
+
627
+
Recommended VSCode extensions:
628
+
629
+
-[Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) - Python language support with extension access points for IntelliSense (Pylance), Debugging (Python Debugger), linting, formatting, etc.
630
+
-[Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - Code formatter for Markdown and YAML files
631
+
-[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) - Supercharges Git support in VSCode
632
+
-[YAML](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) - YAML language support
633
+
-[Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) - Spell checker for source code
634
+
-[Markdown All in One](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one) - All you need to write Markdown (keyboard shortcuts, table of contents, auto preview and more)
635
+
-[Makefile Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools) - Provide makefile support in VS Code
636
+
-[Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) - Fully-featured TOML support
637
+
-[Markdown Preview Mermaid Support](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid) - Adds Mermaid diagram and flowchart support to VS Code's builtin markdown preview
638
+
-[Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) - Support for the Ruff linter and formatter
639
+
640
+
Depending on what file types you are editing, you may only need a subset of those extensions.
641
+
642
+
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
0 commit comments