Skip to content

Commit f77a011

Browse files
author
Peter McDonald
committed
Modifying CICD to use pre-commit
1 parent 7bf179b commit f77a011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+992
-119
lines changed

.editorconfig

+741
Large diffs are not rendered by default.

.github/workflows/mypy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
pip install mypy types-Jinja2
2222
- name: mypy
2323
run: |
24-
mypy monzo/
24+
mypy monzo/

.github/workflows/pre-commit.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
branches:
9+
- 'master'
10+
11+
jobs:
12+
pre-commit:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-python@v2
17+
with:
18+
python-version: '3.9'
19+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: check-case-conflict
11+
12+
- repo: https://github.com/pycqa/isort
13+
rev: 5.10.1
14+
hooks:
15+
- id: isort
16+
name: isort
17+
18+
- repo: https://github.com/pycqa/flake8
19+
rev: 4.0.1
20+
hooks:
21+
- id: flake8
22+
name: flake8
23+
additional_dependencies:
24+
- flake8-bugbear
25+
- flake8-no-pep420
26+
- flake8-comprehensions
27+
- flake8-docstrings
28+
29+
- repo: https://github.com/pre-commit/mirrors-mypy
30+
rev: 'v0.940'
31+
hooks:
32+
- id: mypy
33+
name: mypy

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ Change Log
5757

5858
**0.0.1**
5959

60-
- Initial minimal release
60+
- Initial minimal release

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

docs/source/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Standard blank module __init__."""

docs/source/access_token.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ Open the Monzo app and you will see something like:
180180

181181
Click on "Approve"
182182

183-
Congratulations, you now have credentials that you can use to query the API.
183+
Congratulations, you now have credentials that you can use to query the API.

docs/source/basic_api_queries.rst

-2
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,3 @@ these contain either a fetch or fetchone class method that will carry out
5454
a query and return a list of objects matching your query.
5555

5656
You now have a list of accounts that you can inspect and work with.
57-
58-

docs/source/changelog.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.. include:: ../../CHANGELOG.rst
1+
.. include:: ../../CHANGELOG.rst

docs/source/conf.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# Configuration file for the Sphinx documentation builder.
2-
#
3-
# This file only contains a selection of the most common options. For a full
4-
# list see the documentation:
5-
# https://www.sphinx-doc.org/en/master/usage/configuration.html
1+
"""
2+
Configuration file for the Sphinx documentation builder.
3+
4+
This file only contains a selection of the most common options. For a full
5+
list see the documentation:
6+
https://www.sphinx-doc.org/en/master/usage/configuration.html
7+
"""
68

79
import datetime
810
import os
911
import sys
1012
from configparser import ConfigParser
13+
from typing import List
1114

1215
# -- Path setup --------------------------------------------------------------
1316

@@ -32,15 +35,15 @@
3235
# Add any Sphinx extension module names here, as strings. They can be
3336
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3437
# ones.
35-
extensions = []
38+
extensions: List[str] = []
3639

3740
# Add any paths that contain templates here, relative to this directory.
38-
templates_path = ['_templates']
41+
templates_path: List[str] = ['_templates']
3942

4043
# List of patterns, relative to source directory, that match files and
4144
# directories to ignore when looking for source files.
4245
# This pattern also affects html_static_path and html_extra_path.
43-
exclude_patterns = []
46+
exclude_patterns: List[str] = []
4447

4548

4649
# -- Options for HTML output -------------------------------------------------

docs/source/developers.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ financials.
77

88
The Monzo API package helps simplify usage of the API.
99

10+
CICD and Code Standards
11+
-------------------------------------
12+
13+
We have attempted to reduce the work required to ensure the code conforms to
14+
our coding standards. You can help ensure that any code changes will pass
15+
CICD by making use of pre-commit. The following steps will set this up for you:
16+
17+
.. code-block:: bash
18+
19+
pip install pre-commit
20+
pre-commit install
21+
pre-commit run --all-file
22+
23+
The above commands will create pre-commit hooks, this will test the code prior
24+
to code being committed by Git. Some of the tasks will even correct the data
25+
instead of throwing an error.
26+
27+
If you would like to run the checks without cmmitting code you can run the
28+
following command:
29+
30+
.. code-block:: bash
31+
32+
pre-commit run --all-file
33+
1034
Building Documentation
1135
-------------------------------------
1236

@@ -60,4 +84,3 @@ You can now run the following to upload the package.
6084
git pull
6185
pip install -e .[build]
6286
twine upload dist/*
63-

examples/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Standard blank module __init__."""

examples/auth_step_01.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Example code to authenticate against the Monzo API."""
12
from monzo.authentication import Authentication
23

34
client_id = '' # Client ID obtained when creating Monzo client

examples/auth_step_02.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Code to handle the seconds stage of authentication."""
12
from monzo.authentication import Authentication
23
from monzo.exceptions import MonzoAuthenticationError, MonzoServerError
34

examples/create_feed_item.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Example code for creating a feed item."""
12
from monzo.authentication import Authentication
23
from monzo.endpoints.account import Account
34
from monzo.endpoints.feed_item import FeedItem

examples/get_accounts.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Example code to fetch accounts."""
12
from monzo.authentication import Authentication
23
from monzo.endpoints.account import Account
34
from monzo.exceptions import MonzoError

examples/get_whoami.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Example code for showing who is logged into the Monzo API."""
12
from monzo.authentication import Authentication
23
from monzo.endpoints.whoami import WhoAmI
34
from monzo.exceptions import MonzoError

monzo/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Standard blank module __init__."""

monzo/authentication.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Class to allow authentication on the Monzo API."""
12
import logging
23
import os
34
from pathlib import Path, PurePath
@@ -21,6 +22,7 @@ class Authentication(object):
2122
Class provides methods to authenticate to the Monzo API and to make relevant queries. An instantiated
2223
copy of this class is usually passed to each action
2324
"""
25+
2426
__slots__ = [
2527
'_access_token',
2628
'_access_token_expiry',
@@ -41,7 +43,7 @@ def __init__(
4143
refresh_token: str = ''
4244
):
4345
"""
44-
Standard init.
46+
Initialize Authentication.
4547
4648
Args:
4749
client_id: Client ID generated at https://developers.monzo.com
@@ -83,9 +85,7 @@ def authenticate(self, authorization_token: str, state_token: str) -> None:
8385
self._exchange_token(authorization_token=authorization_token)
8486

8587
def logout(self) -> None:
86-
"""
87-
Invalidates the access token.
88-
"""
88+
"""Invalidate the access token."""
8989
logging.debug('Invalidating token')
9090
self.make_request(path='/oauth2/logout')
9191

@@ -99,7 +99,7 @@ def make_request(
9999
timeout: int = DEFAULT_TIMEOUT
100100
) -> REQUEST_RESPONSE_TYPE:
101101
"""
102-
Makes an API call to Monzo.
102+
Make an API call to Monzo.
103103
104104
Args:
105105
path: Path for the API call
@@ -212,7 +212,7 @@ def refresh_token(self) -> str:
212212
@property
213213
def state_token(self) -> str:
214214
"""
215-
Generates or returns a previously generated state token.
215+
Generate or returns a previously generated state token.
216216
217217
Returns:
218218
A state token used for authentication requests.
@@ -255,7 +255,7 @@ def _exchange_token(self, authorization_token: str) -> None:
255255

256256
def _populate_tokens(self, response: REQUEST_RESPONSE_TYPE) -> None:
257257
"""
258-
Populates tokens after a token request.
258+
Populate tokens after a token request.
259259
260260
Args:
261261
response: Response from an auth request.
@@ -278,7 +278,7 @@ def _populate_tokens(self, response: REQUEST_RESPONSE_TYPE) -> None:
278278

279279
def register_callback_handler(self, handler: Storage) -> None:
280280
"""
281-
Registers a new callback handler for handling new token details.
281+
Register a new callback handler for handling new token details.
282282
283283
Args:
284284
handler: Credential handler implementing Storage

monzo/endpoints/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Standard blank module __init__."""

monzo/endpoints/account.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Class to manage Accounts."""
12
from __future__ import annotations
23

34
from datetime import datetime
@@ -29,11 +30,12 @@ class Account(Monzo):
2930
Class provides methods to fetch accounts and related information. To properly utilise the
3031
class the fetch class method should be utilised.
3132
"""
33+
3234
__slots__ = ['_account_id', '_auth', '_balance', '_created', '_description', '_has_balance']
3335

3436
def __init__(self, auth: Authentication, account_id: str, description: str, created: datetime):
3537
"""
36-
Standard init
38+
Initialize Account.
3739
3840
Args:
3941
account_id: ID of the account
@@ -108,7 +110,7 @@ def description(self) -> str:
108110
@classmethod
109111
def fetch(cls, auth: Authentication, account_type: str = None) -> List[Account]:
110112
"""
111-
Implements and instantiates a Account object
113+
Implement and instantiates a Account object.
112114
113115
Args:
114116
auth: Monzo authentication object

monzo/endpoints/attachment.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Class to manage Attachments."""
12
from __future__ import annotations
23

34
from datetime import datetime
@@ -22,6 +23,7 @@ class Attachment(Monzo):
2223
2324
Class provides methods to manage attachments.
2425
"""
26+
2527
__slots__ = [
2628
'_attachment_id',
2729
'_user_id',
@@ -42,7 +44,7 @@ def __init__(
4244
created: datetime
4345
):
4446
"""
45-
Standard init.
47+
Initialize Attachment.
4648
4749
Args:
4850
auth: Monzo authentication object
@@ -112,9 +114,7 @@ def created(self) -> datetime:
112114
return self._created
113115

114116
def delete(self) -> None:
115-
"""
116-
Delete the attachment.
117-
"""
117+
"""Delete the attachment."""
118118
data = {
119119
'id': self.attachment_id
120120
}
@@ -189,7 +189,6 @@ def _upload_file(cls, auth: Authentication, url: str, file_type: str) -> str:
189189
Returns:
190190
URL of the uploaded file
191191
"""
192-
193192
if not isfile(url):
194193
raise MonzoGeneralError('File does not exist')
195194
content_length = getsize('url')

monzo/endpoints/balance.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Class to manage balance."""
12
from __future__ import annotations
23

34
from monzo.authentication import Authentication
@@ -12,11 +13,12 @@ class Balance(Monzo):
1213
utilised along with the balance property. Otherwise you can fetch an accounts balance utilising the fetch
1314
class method.
1415
"""
16+
1517
__slots__ = ['_balance', '_total_balance', '_currency', '_spend_today']
1618

1719
def __init__(self, auth: Authentication, balance: int, total_balance: int, currency: str, spend_today: str):
1820
"""
19-
Standard init
21+
Initialize Balance.
2022
2123
Args:
2224
balance: Balance of the account
@@ -73,7 +75,7 @@ def spend_today(self) -> str:
7375
@classmethod
7476
def fetch(cls, auth: Authentication, account_id: str) -> Balance:
7577
"""
76-
Implements and instantiates a Account object.
78+
Implement and instantiates a Account object.
7779
7880
Args:
7981
auth: Monzo authentication object

0 commit comments

Comments
 (0)