Skip to content

Commit cad21a6

Browse files
authored
Merge pull request #413 from python-cmd2/speedup_import
Defer certain imports
2 parents 5d64ebe + 190fecb commit cad21a6

31 files changed

+630
-480
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* ``cmd2.redirector`` is no longer supported. Output redirection can only be done with '>' or '>>'
3333
* Python 2 no longer supported
3434
* ``cmd2`` now supports Python 3.4+
35+
* Known Issues
36+
* Some developers have noted very slow performance when importing the ``cmd2`` module. The issue
37+
it intermittant, and investigation of the root cause is ongoing.
3538

3639
## 0.8.5 (April 15, 2018)
3740
* Bug Fixes

CONTRIBUTING.md

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Working on your first Pull Request? You can learn how from this *free* series [H
2121
- [Prerequisites](#prerequisites)
2222
- [Forking The Project](#forking-the-project)
2323
- [Create A Branch](#create-a-branch)
24-
- [Setup Linting](#setup-linting)
2524
- [Setup for cmd2 development](#setup-for-cmd2-development)
2625
- [Make Changes](#make-changes)
26+
- [Static Code Analysis](#static-code-analysis)
2727
- [Run The Test Suite](#run-the-test-suite)
2828
- [Squash Your Commits](#squash-your-commits)
2929
- [Creating A Pull Request](#creating-a-pull-request)
@@ -33,6 +33,7 @@ Working on your first Pull Request? You can learn how from this *free* series [H
3333
- [Next Steps](#next-steps)
3434
- [Other resources](#other-resources)
3535
- [Advice](#advice)
36+
- [Developing in an IDE](#developing-in-an-ide)
3637

3738
### Prerequisites
3839

@@ -175,57 +176,44 @@ $ git push origin [name_of_your_new_branch]
175176

176177
##### If you need more help with branching, take a look at _[this](https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches)_.
177178

178-
### Setup Linting
179-
180-
You should have some sort of [PEP8](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. [pylint](https://www.pylint.org) is a good Python linter which can be run at the command-line but also can integrate with many IDEs and editors.
181-
182-
> 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.
183-
184179

185180
### Setup for cmd2 development
186-
Once you have cmd2 cloned, before you start any cmd2 application, you first need to install all of the dependencies:
187-
188-
```bash
189-
# Install cmd2 prerequisites
190-
pip install -U pyperclip
191-
192-
# Install prerequisites for running cmd2 unit tests
193-
pip install -U pytest
194-
195-
# Install prerequisites for building cmd2 documentation
196-
pip install -U sphinx sphinx-rtd-theme
197-
198-
# Install optional prerequisites for doing code coverage analysis
199-
pip install -U pytest-cov
200-
```
201-
202-
For doing cmd2 development, you actually do NOT want to have cmd2 installed as a Python package.
181+
For doing cmd2 development, you actually do NOT want to have cmd2 installed as a Python package.
203182
So if you have previously installed cmd2, make sure to uninstall it:
204183
```bash
205184
pip uninstall cmd2
206185
```
207186

208-
Then you should modify your PYTHONPATH environment variable to include the directory you have cloned the cmd2 repository to.
209-
Add a line similar to the following to your .bashrc, .bashprofile, or to your Windows environment variables:
210-
187+
Assuming you cloned the repository to `~/src/cmd2`:
211188
```bash
212-
# Use cmd2 Python module from GitHub clone when it isn't installed
213-
export PYTHONPATH=$PYTHONPATH:~/src/cmd2
189+
$ cd ~/src/cmd2
190+
$ pip install -e .
214191
```
192+
will install cmd2 in [editable mode](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs).
193+
Changes to the source code are immediately available when the python interpreter
194+
imports `cmd2`, there is no need to re-install the module after every change. This
195+
command will also install all of the runtime dependencies for `cmd2`.
215196

216-
Where `~src/cmd2` is replaced by the directory you cloned your fork of the cmd2 repo to.
197+
Next you should install all the modules used for development of `cmd2`:
198+
```bash
199+
$ cd ~/src/cmd2
200+
$ pip install -e .[dev]
201+
```
217202

218-
Now navigate to your terminal to the directory you cloned your fork of the cmd2 repo to and
219-
try running the example to make sure everything is working:
203+
This will install `pytest` and `tox` for running unit tests, `pylint` for
204+
static code analysis, and `sphinx` for building the documentation.
220205

206+
Now you can check if everything is installed and working:
221207
```bash
222208
cd ~src/cmd2
223209
python examples/example.py
224210
```
225211

226-
If the example app loads, you should see a prompt that says "(Cmd)". You can type `help` to get help or `quit` to quit.
227-
If you see that, then congratulations – you're all set. Otherwise, refer to the cmd2 [Installation Instructions](https://cmd2.readthedocs.io/en/latest/install.html#installing). There also might be an error in the console
228-
of your Bash / Terminal / Command Line that will help identify the problem.
212+
If the example app loads, you should see a prompt that says "(Cmd)". You can
213+
type `help` to get help or `quit` to quit. If you see that, then congratulations
214+
– you're all set. Otherwise, refer to the cmd2 [Installation Instructions](https://cmd2.readthedocs.io/en/latest/install.html#installing).
215+
There also might be an error in the console of your Bash / Terminal / Command Line
216+
that will help identify the problem.
229217

230218
### Make Changes
231219
This bit is up to you!
@@ -246,17 +234,20 @@ make clean html
246234
```
247235
In order to see the changes, use your web browser of choice to open `<cmd2>/docs/_build/html/index.html`.
248236

237+
### Static Code Analysis
238+
239+
You should have some sort of [PEP8](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. [pylint](https://www.pylint.org) is a good Python linter which can be run at the command-line but also can integrate with many IDEs and editors.
240+
241+
> 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.
242+
249243
### Run The Test Suite
250244
When you're ready to share your code, run the test suite:
251-
252245
```shell
253246
cd <cmd2>
254247
py.test
255248
```
256-
257249
and ensure all tests pass.
258250

259-
260251
#### Measuring code coverage
261252

262253
Code coverage can be measured as follows:
@@ -381,7 +372,7 @@ how to do it.
381372

382373
7. Creating the PR causes our continuous integration (CI) systems to automatically run all of the
383374
unit tests on all supported OSes and all supported versions of Python. You should watch your PR
384-
to make sure that all unit tests pass on Both TravisCI (Linux) and AppVeyor (Windows).
375+
to make sure that all unit tests pass on Both TravisCI (Linux) and AppVeyor (Windows).
385376

386377
8. If any unit tests fail, you should look at the details and fix the failures. You can then push
387378
the fix to the same branch in your fork and the PR will automatically get updated and the CI system
@@ -395,7 +386,7 @@ integration (CI) providers to automatically run all of the unit tests on multipl
395386

396387
1. If your changes can merge without conflicts and all unit tests pass for all OSes and supported versions of Python,
397388
then your pull request (PR) will have a big green checkbox which says something like "All Checks Passed" next to it.
398-
If this is not the case, there will be a link you can click on to get details regarding what the problem is.
389+
If this is not the case, there will be a link you can click on to get details regarding what the problem is.
399390
It is your responsibility to make sure all unit tests are passing. Generally a Maintainer will not QA a
400391
pull request unless it can merge without conflicts and all unit tests pass on all supported platforms.
401392

@@ -460,9 +451,9 @@ Here is some advice regarding what makes a good pull request (PR) from the persp
460451
- Code coverage of the unit tests matters, try not to decrease it
461452
- Think twice before adding dependencies to 3rd party libraries (outside of the Python standard library) because it could affect a lot of users
462453

463-
### Developing and Debugging in an IDE
454+
### Developing in an IDE
464455

465-
We recommend using [Visual Studio Code](https://code.visualstudio.com) with the [Python extension](https://code.visualstudio.com/docs/languages/python) and it's [Integrated Terminal](https://code.visualstudio.com/docs/python/debugging) debugger for debugging since it has
456+
We recommend using [Visual Studio Code](https://code.visualstudio.com) with the [Python extension](https://code.visualstudio.com/docs/languages/python) and it's [Integrated Terminal](https://code.visualstudio.com/docs/python/debugging) debugger for debugging since it has
466457
excellent support for debugging console applications.
467458

468459
[PyCharm](https://www.jetbrains.com/pycharm/) is also quite good and has very nice [Code Inspection](https://www.jetbrains.com/help/pycharm/code-inspection.html) capabilities.

cmd2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#
22
# -*- coding: utf-8 -*-
3+
from .cmd2 import __version__, Cmd, CmdResult, Statement, EmptyStatement, categorize
4+
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category

0 commit comments

Comments
 (0)