Skip to content

Commit 9fbdd5b

Browse files
committed
docs: updated docs
1 parent 8d7b7b4 commit 9fbdd5b

15 files changed

+149
-90
lines changed

docs/configuration.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ or in a config.json:
6060
}
6161
```
6262

63+
### Create configuration from command line
64+
PyMS has a command line option to create a config file.
65+
You can run the next command in the terminal:
66+
67+
```bash
68+
pyms create-config
69+
```
70+
71+
## Configuration file structure
72+
6373
This file can contain the following keywords:
6474

6575
## pyms - services block
@@ -79,7 +89,7 @@ pyms:
7989
requests: true
8090
```
8191
82-
our `ms` object will have an attribute `requests` that is a instance of our service [requests](services.md).
92+
our `ms` object will have an attribute `requests` that is a instance of our [service requests](services.md).
8393

8494
## pyms - config block
8595
This section contains all keywords used for general [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/), along
@@ -166,7 +176,7 @@ spec:
166176
name: my-microservice-configmap
167177
```
168178

169-
See [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
179+
See [Routing](routing.md) and [Examples](tutorials/examples.md) to continue with this tutorial
170180

171181
## Reload configuration without stopping your services
172182

docs/contributing/index.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Branch workflow
44

5-
**READ BEFORE CREATE A BRANCH OR OPEN A PR/MR**
5+
!!! warning
6+
READ BEFORE CREATE A BRANCH OR OPEN A PR/MR
67

78
- We use [Github Glow](https://guides.github.com/introduction/flow/)
89

@@ -23,30 +24,6 @@ source venv/bin/activate
2324
pip install -e ".[test]"
2425
```
2526

26-
Well-written tests and maintaining good test coverage is important to this project. While developing, run new and existing tests with:
27-
28-
```sh
29-
pytest --cov=pyms --cov=tests tests/
30-
```
31-
32-
Add the `-s` flag if you have introduced breakpoints into the code for debugging.
33-
Add the `-v` ("verbose") flag to get more detailed test output. For even more detailed output, use `-vv`.
34-
Check out the [pytest documentation](https://docs.pytest.org/en/latest/) for more options and test running controls.
35-
36-
PyMS supports several versions of Python3. To make sure that changes do not break compatibility with any of those versions, we use `tox` to create virtualenvs for each Python version and run tests with that version. To run against all Python versions defined in the `tox.ini` config file, just run:
37-
38-
```sh
39-
tox
40-
```
41-
42-
If you wish to run against a specific version defined in the `tox.ini` file:
43-
44-
```sh
45-
tox -e py36
46-
```
47-
48-
Tox can only use whatever versions of Python are installed on your system. When you create a pull request, Travis will also be running the same tests and report the results, so there is no need for potential contributors to try to install every single version of Python on their own system ahead of time.
49-
5027
## Pipenv
5128

5229
### Advantages over plain pip and requirements.txt
@@ -93,6 +70,51 @@ pipenv install --deploy
9370
pipenv shell
9471
```
9572

73+
## Testing
74+
Well-written tests and maintaining good test coverage is important to this project. While developing, run new and existing tests with:
75+
76+
```sh
77+
pytest --cov=[project/pyms/...] --cov=tests tests/
78+
```
79+
80+
Add the `-s` flag if you have introduced breakpoints into the code for debugging.
81+
Add the `-v` ("verbose") flag to get more detailed test output. For even more detailed output, use `-vv`.
82+
Check out the [pytest documentation](https://docs.pytest.org/en/latest/) for more options and test running controls.
83+
84+
PyMS supports several versions of Python3. To make sure that changes do not break compatibility with any of those versions, we use `tox` to create virtualenvs for each Python version and run tests with that version. To run against all Python versions defined in the `tox.ini` config file, just run:
85+
86+
```sh
87+
tox
88+
```
89+
90+
If you wish to run against a specific version defined in the `tox.ini` file:
91+
92+
```sh
93+
tox -e py36
94+
```
95+
96+
Tox can only use whatever versions of Python are installed on your system. When you create a pull request, Travis will also be running the same tests and report the results, so there is no need for potential contributors to try to install every single version of Python on their own system ahead of time.
97+
98+
## Linters
99+
100+
### MyPy
101+
102+
```
103+
mypy [project/pyms/...]
104+
```
105+
106+
### Flake8
107+
108+
```
109+
flake8 [project/pyms/...] --show-source --statistics --statistics
110+
```
111+
112+
### Pylint
113+
114+
```
115+
pylint --rcfile=pylintrc [project/pyms/...]
116+
```
117+
96118
## Tutorial: Create your own service
97119

98120
See this [tutorial](../tutorial_create_services.md)

docs/quickstart.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ This command uses [cookiecutter](https://github.com/cookiecutter/cookiecutter) t
5757

5858
```bash
5959
pyms startproject
60-
`
61-
``
60+
```
6261

6362
this outputs a lot of options step by step
6463

@@ -86,4 +85,4 @@ When you finish introducing the options, a project will be created in `[project_
8685

8786
## What's next?
8887

89-
See [Configuration](configuration.md), [Routing](routing.md) and [Examples](examples.md) to continue with this tutorial
88+
See [Configuration](configuration.md), [Routing](routing.md) and [Examples](tutorials/examples.md) to continue with this tutorial

docs/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/routing.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Routing
2-
With PyMS you can extend the Microservice with [Connexion](https://github.com/zalando/connexion) and [swagger-ui](https://github.com/sveint/flask-swagger-ui).
2+
With PyMS you can extend the Microservice with [Connexion](https://github.com/zalando/connexion) and
3+
[swagger-ui](https://github.com/sveint/flask-swagger-ui).
34

45
To use connexion, you must set in your config.yaml this:
56
```yaml
@@ -100,15 +101,15 @@ As an example, say you have an endpoint specified as:
100101

101102
```yaml
102103
paths:
103-
/foo:
104-
get:
105-
operationId: api.foo_get
106-
parameters:
107-
- name: message
108-
description: Some message.
109-
in: query
110-
type: string
111-
required: true
104+
/foo:
105+
get:
106+
operationId: api.foo_get
107+
parameters:
108+
- name: message
109+
description: Some message.
110+
in: query
111+
type: string
112+
required: true
112113
```
113114

114115
And the view function:

docs/scaffold/configuration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Configuration
22

3-
Project configuration is loaded using [PyMS](https://github.com/python-microservices/pyms) package based on yml or json file.
4-
Some example files are config.yml, config-docker.yml and tests/config-tests.yml or see [PyMS configuration](configuration.md)
3+
Project configuration is loaded using [PyMS](https://github.com/python-microservices/pyms) package
4+
based on yml or json file. Some example files are config.yml, config-docker.yml and tests/config-tests.yml
5+
or see [PyMS configuration](../configuration.md)
56

67
## Documentation
78
The Microservice create a URL to inspect the Swagger documentation of the api in:

docs/scaffold/quickstart.md

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,80 @@
11
# Installation
22

3-
Clone the project
3+
### Clone the repository
44

5+
```bash
6+
git clone [email protected]:purwowd/microservices-scaffold.git
7+
cd microservices-scaffold
58
```
6-
git clone https://github.com/python-microservices/microservices-scaffold.git
7-
```
8-
9-
Install your virtualenv
109

11-
```
10+
### Install with virtualenv
11+
```bash
1212
virtualenv --python=python[3.6|3.7|3.8] venv
1313
source venv/bin/activate
1414
pip install -r requirements.txt
1515
```
1616

17-
Or install with pipenv
18-
19-
```
17+
### Install with pipenv
18+
```bash
2019
pip install pipenv
2120
pipenv install
2221
```
2322

24-
Run the script
25-
26-
```
23+
### Install on MacOS
24+
```bash
25+
virtualenv -p python3 venv
26+
source venv/bin/activate
27+
pip3 install -r requirements.txt
2728
python manage.py runserver
2829
```
2930

30-
## Check the result
31+
#### Advantages over plain pip and requirements.txt
32+
[Pipenv](https://pipenv.readthedocs.io/en/latest/) generates two files: a `Pipfile`and a `Pipfile.lock`.
33+
* `Pipfile`: Is a high level declaration of the dependencies of your project. It can contain "dev" dependencies (usually test related stuff) and "standard" dependencies which are the ones you'll need for your project to function
34+
* `Pipfile.lock`: Is the "list" of all the dependencies your Pipfile has installed, along with their version and their hashes. This prevents two things: Conflicts between dependencies and installing a malicious module.
3135

32-
Your default endpoint will be in this url:
36+
For a more in-depth explanation please refer to the [official documentation](https://pipenv.readthedocs.io/en/latest/).
3337

38+
## Run your python script
39+
```bash
40+
python manage.py runserver
3441
```
35-
http://127.0.0.1:5000/template/
42+
43+
## Check the result
44+
45+
Your default endpoints will be in this url:
46+
```bash
47+
http://127.0.0.1:5000/films
48+
http://127.0.0.1:5000/actors
3649
```
3750

38-
This URL is setted in your `config.yml`:
51+
This URL is set in your `config.yml`:
3952

4053
```yaml
4154
pyms:
4255
config:
4356
DEBUG: false
4457
TESTING: false
4558
APP_NAME: Template
46-
APPLICATION_ROOT : /template # <!---
59+
APPLICATION_ROOT : "" # <!---
4760
```
4861
49-
You can acceded to a `swagger ui <https://swagger.io/tools/swagger-ui/>`_ in the next url:
50-
51-
```
52-
http://127.0.0.1:5000/template/ui/
62+
You can acceded to a [swagger ui](https://swagger.io/tools/swagger-ui/) in the next url:
63+
```bash
64+
http://127.0.0.1:5000/ui/
5365
```
5466

55-
This PATH is setted in your `config.yml`:
67+
This PATH is set in your `config.yml`:
5668

5769
```yaml
58-
pyms:
59-
services:
60-
swagger:
61-
path: "swagger"
62-
file: "swagger.yaml"
63-
url: "/ui/" # <!---
70+
pyms:
71+
services:
72+
swagger:
73+
path: "swagger"
74+
file: "swagger.yaml"
75+
url: "/ui/" # <!---
6476
```
6577
6678
## Template
67-
You can create your own project from template:
6879
69-
https://github.com/python-microservices/microservices-template
80+
You can create your own project from template: [github.com/python-microservices/microservices-template](https://github.com/python-microservices/microservices-template)

docs/scaffold/runindocker.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Docker
2+
You can dockerize this microservice with these steps:
3+
* Create and push the image
4+
```
5+
docker build -t films -f Dockerfile .
6+
```
7+
8+
* Run the image:
9+
```
10+
docker run -d -p 5000:5000 films
11+
```

docs/services.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ These services are created as an attribute of the [Microservice class](ms_class.
55

66
To add a service check the [configuration section](configuration.md).
77

8-
You can declare a service but activate/deactivate with the keyword `enabled`, like so:
8+
You can declare a service but **activate/deactivate** with the keyword `enabled`, like so:
99

1010
```yaml
1111
pyms:
@@ -26,14 +26,16 @@ You must install `pyms` with `pip install py-ms[all]` or `pip install py-ms[swag
2626

2727
### Configuration
2828

29-
The parameters you can add to your config are the folowing:
29+
The parameters you can add to your config are the following:
3030

3131
* **path:** The relative or absolute route to your swagger yaml file. The default value is the current directory
3232
* **file:** The name of you swagger yaml file. The default value is `swagger.yaml`
3333
* **url:** The url where swagger run in your server. The default value is `/ui/`.
3434
* **project_dir:** Relative path of the project folder to automatic routing,
3535

36-
see [this link for more info](https://github.com/zalando/connexion#automatic-routing). The default value is `project`.
36+
See [this link for more info](https://github.com/zalando/connexion#automatic-routing). The default value is `project`.
37+
38+
See [Routing](routing.md) in this documentation to how configure your Swagger.
3739

3840
### Example
3941

docs/template/index.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ pyms:
115115
url: "/ui/" # <!---
116116
```
117117
118-
Read more info in the documentation page:
119-
https://microservices-scaffold.readthedocs.io/en/latest/
120-
121118
# Docker
122119
You can dockerize this microservice wit this steps:
123120
* Create and push the image
File renamed without changes.

docs/tutorial_create_services.md renamed to docs/tutorials/tutorial_create_services.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tutorial 2: How To contribute, Create your own service
22

3-
* First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
3+
First, you must create a file with the name of your service inside of `pyms.flask.service`, for example,
44
"myawesomesrv":
55

66
pyms/flask/services/myawesomesrv.py
@@ -16,15 +16,23 @@ class Service(DriverService):
1616
}
1717
```
1818

19-
* Now, you can configure your service from `config.yml`
19+
Now, you can configure your service from `config.yml`
2020
```yaml
2121
pyms:
22-
config:
22+
services:
2323
myawesomesrv:
2424
myvalue: 5
25+
myvalue2: 5
2526
```
2627
27-
* Your service will be instanced inside the `ms` object in `flask.current_app` object. For example, with the last config,
28+
All configuration in myawesomesrv (myvalue, myvalue2) is loaded in `self.config`: `self.config.myvalue` and
29+
`self.config.myvalue2`.
30+
31+
When you "call" an attribute of your service, `DriverService` searchs in `self.config`, and `self.config` contains
32+
the key-values that you've defined in your config.yaml for this service. Therefore, each key in your config.yaml
33+
is an attribute of your Service.
34+
35+
Your service will be instanced inside the `ms` object in `flask.current_app` object. For example, with the last config,
2836
you could print the folowing code:
2937

3038
```python
File renamed without changes.

0 commit comments

Comments
 (0)