Skip to main content

Shell-like tool to make it easier to develop python code

Project description

devshell

devshell is a tool to make python development easier.

Key Features

  1. Enables entering an interactive session tied to the docstring of a particular python object. Inputs and responses are automatically recorded and inserted into the docstring as doctests.
  2. Shell-like tool for navigating, inspecting, testing, and making doctests for python objects defined in a project

What are doctests and why should I care?

Doctests are snippets of text that resemble a Python interactive mode session. Doctests can be embedded in the docstrings within your code in order to serve two purposes:

  1. To provide executable examples to users so they can better understand how to use your code

  2. To support automated testing by running these lines and confirming the expected outputs are produced

A docstring is a block of inline text within your code at the start of a module, class, or function to document the function. When the builtin help() function is called on an object, the docstrings for that object's class and methods are displayed. Additionally there are a number of tools, such as sphinx or pdoc that generate polished documentation files by scanning docstrings within a project.

How to use devshell

First open a shell or command line window and navigate to the folder containing the packages and/or modules of interest. Then run:

```
$ python -m devshell

Starting devshell command line interface...
Welcome to the devshell shell. Type help or ? to list commands.

(devshell)$
```

You will then enter the devshell shell, which was designed to look and feel very similar to a unix shell. The big difference is that instead of navigating through actual files/directories, the devshell shell navigates through python packages, modules, classes, and functions. Tab-completion is supported.

In the shell, you can type help to list all the commands.

```
(devshell)$ help
Documented commands (type help <topic>):
========================================
EOF       cp       devshell  h            ls     pwd     quit    run   
cd        debug    edit        help         mkdir  pytest  read    source
chdir     doc      exit        interactive  mv     python  rm    
coverage  doctest  getcwd      listdir      pip    q       rmtree
```

You can also type help followed by a command to get information about that particular command:

```
(devshell)$ help ls

    Help: (devshell)$ ls
        This will show all items contained within the currently targeted item.
            e.g. for a package, this would list the modules
            e.g. for a module, this would list the functions and classes
            etc
        Note that using this command may result in importing the module containing the currently targeted item.
        Note that setup.py files will be purposefully excluded because importing/inspecting them without providing commands results in terminating python.k
```

Use the pwd, cd, and ls commands to navigate through different items:

```
devshell)$ ls
    devshell          package             directory
    test_pkg            package             directory
    tests               package             directory
(devshell)$ cd test_pkg
(devshell)$ cd test_subpkg.test_mod.f
(devshell)$ pwd
/test_pkg.test_subpkg.test_mod.f
```

Once you are navigated to the item of interest, run the devshell command to enter a recorded interactive python session. All items from the containing module of the targeted item will automatically be imported. You essentially just type the doctest inputs, and the interactive session will evaluate them and display the outputs. When done, press Ctrl+D to exit the interactive session. At this point, devshell will write the recorded actions into the docstring of the targeted object. Afterwards, it will run doctests on that object to ensure there are no issues. If any issues are encountered, the original file will be restored and the problematic file will be saved with a special suffix in the same folder.

```
(devshell)$ devshell
Testing doctest execution of original file
...done: Fail count = 0, Total count = 0
Entering interactive console
Doctest insertion targeting object test_pkg.test_subpkg.test_mod.f within /home/mtm/interspace/devshell/test_pkg/test_subpkg/test_mod.py
Press Ctrl+D to stop writing code and incorporate session into the docstring of the targeted object
To abort this session without writing anything into the targeted file, call the exit() function
>>> from test_pkg.test_subpkg.test_mod import * # automatic import by devshell
>>> f(20)
20
>>>
Writing doctest lines to file
Testing doctest execution of new file
...done: Fail count = 0 (old=0), Total count = 1 (old=0)
File successfully updated

```

You can use the doc or source commands to verify the doctest was written in:

```
(devshell)$ doc
>>> f(20)
20

(devshell)$ source
File: /home/mtm/interspace/devshell/test_pkg/test_subpkg/test_mod.py
def f(x):
"""
>>> f(20)
20
"""
return x

```

You can also change the current working directory that the devshell shell is scanning for modules and packages with. You can navigate the filestystem using chdir, listdir, and getcwd, which do the same things as the standard python os module methods of the same name. Tab-completion is supported for chdir and listdir.

To exit the doctest shell, just press Ctrl+D or type the quit command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

devshell-0.0.2.tar.gz (15.5 kB view details)

Uploaded Source

Built Distributions

devshell-0.0.2-py3.8.egg (44.1 kB view details)

Uploaded Source

devshell-0.0.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file devshell-0.0.2.tar.gz.

File metadata

  • Download URL: devshell-0.0.2.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for devshell-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b14f9b8e4e2130f39b661564be0a5f8e789eae95424b09224f9f2e8d72c339ab
MD5 cfd8f1fc6c972a470ab63e8467afc474
BLAKE2b-256 0c8e82f3f4089b7a670621bb84c24ea86a2faecff0179c9f940977e3fdbc5638

See more details on using hashes here.

File details

Details for the file devshell-0.0.2-py3.8.egg.

File metadata

  • Download URL: devshell-0.0.2-py3.8.egg
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.5

File hashes

Hashes for devshell-0.0.2-py3.8.egg
Algorithm Hash digest
SHA256 c8aa2970370ccafc94dc200099a977466b24e76b48d2b88113e27e51deeef6a3
MD5 17ac02e9bfd65eac3c18b95363702b71
BLAKE2b-256 14ae06bf474e424f2fb3777ab65c96db4997f24b72ad334aa6df3ce23a6d0d91

See more details on using hashes here.

File details

Details for the file devshell-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: devshell-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for devshell-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a21d9bbcd120b1905c8f5da156673fdfb463794b19e15d21867057ee2cd03e66
MD5 0fda238d5d800ec18f2e3ab083f4568f
BLAKE2b-256 54c2c5d8d80116266651d88a0ae15bd9556a23778b2cb646b0a8d7e325f3e85c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page