Skip to content

Commit

Permalink
#155: Add documentation regarding code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Aug 13, 2020
1 parent a22e8f4 commit d7f726d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ICAT API to interface with the Data Gateway
- [Requirements](#requirements)
- [Setup and running the API](#setup-and-running-the-api)
- [Project structure](#project-structure)
- [Main:](#main)
- [Endpoints:](#endpoints)
- [Mapped classes:](#mapped-classes)
- [Main](#main)
- [Endpoints](#endpoints)
- [Mapped classes](#mapped-classes)
- [Querying and filtering](#querying-and-filtering)
- [Swagger Generation](#generating-the-swagger-spec-openapiyaml)
- [Authentication](#authentication)
Expand All @@ -26,7 +26,6 @@ The required python libraries:
- [SQLAlchemy](https://www.sqlalchemy.org/)
- [flask-restful](https://github.com/flask-restful/flask-restful/)
- [pymysql](https://pymysql.readthedocs.io/en/latest/)
- [requests](https://2.python-requests.org/en/master/)
- [pyyaml](https://pyyaml.org/wiki/PyYAMLDocumentation) (For the swagger generation)
- [pip-tools](https://github.com/jazzband/pip-tools) (For generating requirements.txt)

Expand Down Expand Up @@ -112,23 +111,23 @@ This is illustrated below.
├── logs.log
└── config.json
`````
#### Main:
#### Main
`main.py` is where the flask_restful api is set up. This is where each endpoint resource class is generated and mapped
to an endpoint.

Example:
`api.add_resource(get_endpoint(entity_name, endpoints[entity_name]), f"/{entity_name.lower()}")`


#### Endpoints:
#### Endpoints
The logic for each endpoint are within `/src/resources`. They are split into entities, non_entities and
table_endpoints. The entities package contains `entities_map` which maps entity names to their sqlalchemy
model. The `entity_endpoint` module contains the function that is used to generate endpoints at start up.
`table_endpoints` contains the endpoint classes that are table specific. Finally, non_entities contains the
session endpoint.


#### Mapped classes:
#### Mapped classes
The classes mapped from the database are stored in `/common/models/db_models.py`. Each model was
automatically generated using sqlacodegen. A class `EntityHelper` is defined so that each model may
inherit two methods `to_dict()` and `update_from_dict(dictionary)`, both used for returning entities
Expand Down Expand Up @@ -182,4 +181,10 @@ class DataCollectionDatasets(Resource):
## Running Tests
To run the tests use `python -m unittest discover`

## Linter
When writing code for this repository, [Black](https://black.readthedocs.io/en/stable/)
is used as the code linter/formatter to ensure the code is kept Pythonic. Installing
the dev requirements will ensure this package is installed. This repository uses the
default settings for Black; to use, execute the following command on the root directory of this repo:

`black .`
4 changes: 3 additions & 1 deletion dev-requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Faker == 2.0.2
pip-tools == 5.3.1
Faker == 2.0.2
black == 19.10b0
16 changes: 14 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
#
# pip-compile dev-requirements.in
#
faker==2.0.2
appdirs==1.4.4 # via black
attrs==19.3.0 # via black
black==19.10b0 # via -r dev-requirements.in
click==7.1.2 # via black, pip-tools
faker==2.0.2 # via -r dev-requirements.in
pathspec==0.8.0 # via black
pip-tools==5.3.1 # via -r dev-requirements.in
python-dateutil==2.8.0 # via faker
six==1.12.0 # via faker, python-dateutil
regex==2020.7.14 # via black
six==1.12.0 # via faker, pip-tools, python-dateutil
text-unidecode==1.3 # via faker
toml==0.10.1 # via black
typed-ast==1.4.1 # via black

# The following packages are considered to be unsafe in a requirements file:
# pip
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# pip-compile requirements.in
#
aniso8601==8.0.0 # via flask-restful
apispec==3.3.0
apispec==3.3.0 # via -r requirements.in
click==7.0 # via flask
flask-cors==3.0.8
flask-swagger-ui==3.25.0
flask-cors==3.0.8 # via -r requirements.in
flask-swagger-ui==3.25.0 # via -r requirements.in
flask==1.1.1 # via flask-cors, flask-restful, flask-swagger-ui
flask_restful==0.3.7
flask_restful==0.3.7 # via -r requirements.in
itsdangerous==1.1.0 # via flask
jinja2==2.10.1 # via flask
markupsafe==1.1.1 # via jinja2
pymysql==0.9.3
pymysql==0.9.3 # via -r requirements.in
pytz==2019.2 # via flask-restful
pyyaml==5.1.2
pyyaml==5.1.2 # via -r requirements.in
six==1.12.0 # via flask-cors, flask-restful
sqlalchemy==1.3.8
sqlalchemy==1.3.8 # via -r requirements.in
werkzeug==0.16.0 # via flask

0 comments on commit d7f726d

Please sign in to comment.