|
1 | 1 | [][ci] |
| 2 | +[][pypi] |
| 3 | +[][pypi] |
2 | 4 | [][codecov] |
3 | | -TODO: PyPi Release Badge |
4 | 5 | [][mypy-home] |
5 | 6 | [][black-home] |
6 | 7 |
|
7 | 8 | # Columbo |
8 | 9 |
|
9 | 10 | Specify a dynamic set of questions to ask a user and get their answers. |
10 | 11 |
|
11 | | -## CI |
| 12 | +`columbo`'s feature set allows a program to: |
12 | 13 |
|
13 | | -TODO: Add CI documentation. |
| 14 | +* Ask multiple types of questions: |
| 15 | + * Yes or No |
| 16 | + * Multiple choice |
| 17 | + * Open-ended |
| 18 | +* Validate the response provided by the user. |
| 19 | +* Use answers from earlier questions: |
| 20 | + * As part of the text of a question |
| 21 | + * As part of the text of a default value |
| 22 | + * To decide if a question should be skipped |
| 23 | +* Accept answers from the command line in addition to prompting the user. |
14 | 24 |
|
15 | | -## Usage |
| 25 | +## Example |
16 | 26 |
|
17 | | -TODO: Add usage documentation. |
| 27 | +### User Prompts |
18 | 28 |
|
19 | | -## Develop |
20 | | - |
21 | | -The Columbo project uses Docker to ease setting up a consistent development environment. The Docker documentation has |
22 | | -details on how to [install docker][install-docker] on your computer. |
23 | | - |
24 | | -Once that is configured, the test suite can be run locally: |
25 | | - |
26 | | -```bash |
27 | | -docker-compose run --rm test |
28 | | -``` |
29 | | - |
30 | | -If you want to be able to execute code in the container: |
31 | | - |
32 | | -```bash |
33 | | -docker-compose run --rm devbox |
34 | | -(your code here) |
35 | | -``` |
36 | | - |
37 | | -In the devbox environment you'll be able to enter a python shell and import `columbo` or any dependencies. |
38 | | - |
39 | | -## Debugging |
40 | | - |
41 | | -The docker container has [pdb++][pdbpp-home] install that can be used as a debugger. (However, you are welcome to set up |
42 | | -a different debugger if you would like.) |
43 | | - |
44 | | -This allows you to easily create a breakpoint anywhere in the code. |
| 29 | +The primary use of `columbo` is to define a sequence of interactions that are used to prompt a user to provide answers |
| 30 | +using a terminal. Below is a sample which shows some ways this can be used. |
45 | 31 |
|
46 | 32 | ```python |
47 | | -def my_function(): |
48 | | - breakpoint() |
49 | | - ... |
| 33 | +import columbo |
| 34 | + |
| 35 | +interactions = [ |
| 36 | + columbo.Echo("Welcome to the Columbo example"), |
| 37 | + columbo.Acknowledge( |
| 38 | + "Press enter to start" |
| 39 | + ), |
| 40 | + columbo.BasicQuestion( |
| 41 | + "user", |
| 42 | + "What is your name?", |
| 43 | + default="Patrick", |
| 44 | + ), |
| 45 | + columbo.BasicQuestion( |
| 46 | + "user_email", |
| 47 | + lambda answers: f"""What email address should be used to contact {answers["user"]}?""", |
| 48 | + default="me@example.com" |
| 49 | + ), |
| 50 | + columbo.Choice( |
| 51 | + "mood", |
| 52 | + "How are you feeling today?", |
| 53 | + options=["happy", "sad", "sleepy", "confused"], |
| 54 | + default="happy", |
| 55 | + ), |
| 56 | + columbo.Confirm("likes_dogs", "Do you like dogs?", default=True), |
| 57 | +] |
| 58 | + |
| 59 | +answers = columbo.get_answers(interactions) |
| 60 | +print(answers) |
50 | 61 | ``` |
51 | 62 |
|
52 | | -When your the code, you will drop into an interactive `pdb++` debugger. |
| 63 | +Below shows the output when the user accepts the default values for most of the questions. The user provides a different |
| 64 | +value for the email and explicitly confirms that they like dogs. |
53 | 65 |
|
54 | | -See the documentation on [pdb][pdb-docs] and [pdb++][pdbpp-docs] for more information. |
| 66 | +```text |
| 67 | +Welcome to the Columbo example |
| 68 | +Press enter to start |
| 69 | + |
| 70 | +What is your name? [Patrick]: |
55 | 71 |
|
56 | | -## Testing |
57 | | - |
58 | | -You'll be unable to merge code unless the linting and tests pass. You can run these in your container via: |
59 | | - |
60 | | -```bash |
61 | | -docker-compose run --rm test |
62 | | -``` |
| 72 | +What email address should be used to contact Patrick? [me@example.com]: patrick@example.com |
63 | 73 |
|
64 | | -This will run the same tests, linting, and code coverage that are run by the CI pipeline. The only difference is that, |
65 | | -when run locally, `black` and `isort` are configured to automatically correct issues they detect. |
| 74 | +How are you feeling today? |
| 75 | +1 - happy |
| 76 | +2 - sad |
| 77 | +3 - sleepy |
| 78 | +4 - confused |
| 79 | +Enter the number of your choice [1]: |
66 | 80 |
|
67 | | -Generally we should endeavor to write tests for every feature. Every new feature branch should increase the test |
68 | | -coverage rather than decreasing it. |
| 81 | +Do you like dogs? (Y/n): y |
69 | 82 |
|
70 | | -We use [pytest][pytest-docs] as our testing framework. |
71 | | - |
72 | | -#### Stages |
73 | | - |
74 | | -To customize / override a specific testing stage, please read the documentation specific to that tool: |
75 | | - |
76 | | -1. [PyTest][pytest-docs] |
77 | | -2. [MyPy][mypy-docs] |
78 | | -3. [Black][black-docs] |
79 | | -4. [Isort][isort-docs] |
80 | | -4. [Flake8][flake8-docs] |
81 | | -5. [Bandit][bandit-docs] |
82 | | - |
83 | | -### `setup.py` |
84 | | - |
85 | | -Setuptools is used to packaging the library. |
86 | | - |
87 | | -**`setup.py` must not import anything from the package** When installing from source, the user may not have the |
88 | | -packages dependencies installed, and importing the package is likely to raise an `ImportError`. For this reason, the |
89 | | -**package version should be obtained without importing**. This is explains why `setup.py` uses a regular expression to |
90 | | -grabs the version from `__init__.py` without actually importing. |
91 | | - |
92 | | -### Requirements |
93 | | - |
94 | | -* **requirements.txt** - Lists all direct dependencies (packages imported by the library). |
95 | | -* **Requirements-test.txt** - Lists all direct requirements needed to run the test suite & lints. |
96 | | - |
97 | | -## Publishing the Package |
98 | | - |
99 | | -TODO: Not currently implemented. |
100 | | - |
101 | | -Once the package is ready to be released, there are a few things that need to be done: |
| 83 | +{'user': 'Patrick', 'user_email': 'patrick@example.com', 'mood': 'happy', 'likes_dogs': True} |
| 84 | +``` |
102 | 85 |
|
103 | | -1. Create a new Pull Request that increase the version number from the previous release in `columbo/__init__.py` and |
104 | | - `CHANGELOG.md`. [Semantic versioning][sem-ver] is used to make it clear to people using your package what types of |
105 | | - changes are in the new version. |
106 | | -2. Ensure this change has been merged to the default branch with all the code that should be included in the release. |
107 | | -3. Create a new GitHub release. The tag should be named: `vX.Y.Z` |
| 86 | +### Command Line Answers |
108 | 87 |
|
109 | | -This will trigger the CI system to build a wheel and a source distributions of the package and push them to |
110 | | -[PyPI][pypi]. |
| 88 | +TODO |
111 | 89 |
|
112 | 90 | ## Documentation |
113 | 91 |
|
114 | | -TODO: Use Github Pages to host documentation. |
115 | | -Check out the [project documentation][columbo-docs] |
| 92 | +Check out the [project documentation][columbo-docs]. |
| 93 | + |
| 94 | +For an overview on how repository structure and how to work with the code base, read the |
| 95 | +[Development Guide][development-docs]. |
116 | 96 |
|
117 | 97 | [ci]: https://github.com/wayfair-incubator/columbo/actions |
| 98 | +[pypi]: https://pypi.org/project/columbo/ |
118 | 99 | [codecov]: https://codecov.io/gh/wayfair-incubator/columbo |
119 | 100 | [mypy-home]: http://mypy-lang.org/ |
120 | 101 | [black-home]: https://github.com/psf/black |
121 | | -[install-docker]: https://docs.docker.com/install/ |
122 | | -[pdbpp-home]: https://github.com/pdbpp/pdbpp |
123 | | -[pdb-docs]: https://docs.python.org/3/library/pdb.html |
124 | | -[pdbpp-docs]: https://github.com/pdbpp/pdbpp#usage |
125 | | -[pytest-docs]: https://docs.pytest.org/en/latest/ |
126 | | -[mypy-docs]: https://mypy.readthedocs.io/en/stable/ |
127 | | -[black-docs]: https://black.readthedocs.io/en/stable/ |
128 | | -[isort-docs]: https://pycqa.github.io/isort/ |
129 | | -[flake8-docs]: http://flake8.pycqa.org/en/stable/ |
130 | | -[bandit-docs]: https://bandit.readthedocs.io/en/stable/ |
131 | | -[sem-ver]: https://semver.org/ |
132 | | -[pypi]: https://semver.org/ |
133 | 102 | [columbo-docs]: https://github.com/wayfair-incubator/columbo/ |
| 103 | +[development-docs]: https://github.com/wayfair-incubator/columbo/development-guide/ |
0 commit comments