[DOC] update doc with default spawn class.

This commit is contained in:
Benedek Racz 2020-04-08 16:02:41 +02:00
parent 4687573f3b
commit 8ce9059388
2 changed files with 7 additions and 103 deletions

101
README.md
View File

@ -36,43 +36,13 @@ child.sendline('exit')
For more information see [examples](./examples) folder.
---
## **REFACTOR**
## REFACTOR
The original wexpect has some structural weakness, which leads me to rewrite the whole code. The
first variant of the new structure is delivered with [v3.2.0](https://pypi.org/project/wexpect/3.2.0/).
Note, that the default is the old variant (`legacy_wexpect`), to use the new you need to set the
`WEXPECT_SPAWN_CLASS` environment variable to `SpawnPipe` or `SpawnSocket`, which are the two new
structured spawn class.
### Old vs new
But what is the difference between the old and new and what was the problem with the old?
Generally, wexpect (both old and new) has three processes:
- *host* is our original python script/program, which want to launch the child.
- *console* is a process which started by the host, and launches the child. (This is a python script)
- *child* is the process which want to be launced.
The child and the console has a common Windows console, distict from the host.
The `legacy_wexpect`'s console is a thin script, almost do nothing. It initializes the Windows's
console, and monitors the host and child processes. The magic is done by the host process, which has
the switchTo() and switchBack() functions, which (de-) attaches the *child-console* Windows-console.
The host manipulates the child's console directly. This direct manipuation is the structural weakness.
The following task/usecases are hard/impossibile:
- thread-safe multiprocessing of the host.
- logging (both console and host)
- using in grapichal IDE or with pytest
- This variant is highly depends on the pywin32 package.
The new structure's console is a thik script. The console process do the major console manipulation,
which is controlled by the host via socket (see SpawnSocket) or named-pipe (SpawnPipe). The host
only process the except-loops.
**Refactor has been finished!!!** The default spawn class is `SpawnPipe` from now. For more
information read [history](https://wexpect.readthedocs.io/en/latest/history.html#refactor).
---
## What is it?
## What is wexpect?
Wexpect is a Python module for spawning child applications and controlling
them automatically. Wexpect can be used for automating interactive applications
@ -87,17 +57,6 @@ Original Pexpect should work on any platform that supports the standard Python p
Wexpect works on Windows platforms. The Wexpect interface focuses on ease of use so that simple
tasks are easy.
### History
Wexpect is a one-file code developed at University of Washington. There are several
[copy](https://gist.github.com/anthonyeden/8488763) and
[reference](https://mediarealm.com.au/articles/python-pexpect-windows-wexpect/)
to this code with very few (almost none) documentation nor integration.
This repo tries to fix these limitations, with a few example code and pypi integration.
---
## Dev
@ -117,55 +76,3 @@ See `after_test` section in [appveyor.yml](appveyor.yml) for more details.
The wexpect uses [pbr](https://docs.openstack.org/pbr/latest/) for managing releasing procedures.
The versioning is handled by the pbr. The *"master-version"* is the git tag. Pbr derives the package
version from the git tags.
## Basic behaviour
Let's go through the example code:
```python
import wexpect
child = wexpect.spawn('cmd.exe')
child.expect('>')
child.sendline('ls')
child.expect('>')
print(child.before)
child.sendline('exit')
```
### spawn()
`child = wexpect.spawn('cmd.exe')`
Call trace:
- ::spawn
- spawn_windows::__init__()
- spawn_windows::_spawn()
- Wtty::spawn()
- Wtty::startChild()
- win32process.CreateProcess()
### expect()
`child.expect('>')`
Call trace:
- spawn_windows::expect()
- spawn_windows::expect_list()
- spawn_windows::expect_loop()
- spawn_windows::read_nonblocking()
- Wtty::read_nonblocking()
- Wtty::readConsoleToCursor()
- Wtty::readConsole()
- __consout.ReadConsoleOutputCharacter()
### sendline()
`child.sendline('ls')`
- spawn_windows::sendline()
- spawn_windows::send()
- Wtty::write()

View File

@ -13,12 +13,9 @@ Refactor
The original wexpect was a monolite, one-file code, with several structural weaknesses. This leads
me to rewrite the whole code. The first variant of the new structure is delivered with
`v3.2.0 <https://pypi.org/project/wexpect/3.2.0/>`_.
.. Note::
The default is the old variant (:code:`legacy_wexpect`), to use the new you need to set the
:code:`WEXPECT_SPAWN_CLASS` environment variable to :code:`SpawnPipe` or :code:`SpawnSocket`, which
are the two new structured spawn classes.
`v3.2.0 <https://pypi.org/project/wexpect/3.2.0/>`_. (The default is the old variant
(:code:`legacy_wexpect`) in v3.2.0. :code:`WEXPECT_SPAWN_CLASS` environment variable can choose the
new-structured implementation.) Now :code:`SpawnPipe` is the default spawn class.
Old vs new
^^^^^^^^^^