Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

Commit 30fa8a9

Browse files
authored
Merge pull request #8 from Natim/add-flake8
Add flake8
2 parents 248709e + 8b40e23 commit 30fa8a9

15 files changed

Lines changed: 67 additions & 18 deletions

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ repos:
2222
rev: v4.3.21
2323
hooks:
2424
- id: isort
25+
26+
- repo: https://gitlab.com/pycqa/flake8
27+
rev: 3.7.9
28+
hooks:
29+
- id: flake8
30+
args: [--max-line-length=99]
31+
language_version: python3.7

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ black: install-dev
4242
isort: install-dev
4343
$(VENV)/bin/isort --recursive setup.py alma
4444

45+
flake8: install-dev
46+
$(VENV)/bin/flake8 setup.py alma
47+
4548
build-requirements:
4649
$(VIRTUALENV) $(TEMPDIR)
4750
$(TEMPDIR)/bin/pip install -U pip

alma/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# flake8: noqa
2+
3+
import pkg_resources
4+
15
from . import endpoints, entities
26
from .api_modes import ApiModes
37
from .client import Client
48

5-
import pkg_resources
6-
79
__version__ = pkg_resources.get_distribution(__package__).version

alma/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def __init__(self, api_key, **options):
2323
}
2424

2525
if type(options["api_root"]) is str:
26-
options["api_root"] = {ApiModes.TEST: options["api_root"], ApiModes.LIVE: options["api_root"]}
26+
options["api_root"] = {
27+
ApiModes.TEST: options["api_root"],
28+
ApiModes.LIVE: options["api_root"],
29+
}
2730
elif type(options["api_root"]) is not dict:
2831
raise TypeError("`api_root` option must be a dict or a string")
2932

alma/endpoints/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# flake8: noqa
2+
13
from .base import Base
24
from .merchants import Merchants
35
from .orders import Orders

alma/endpoints/payments.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ def add_orders_to(self, payment_id, order_data: Union[List[dict], dict]) -> List
5151
Adds one or several orders to the given payment
5252
5353
:param payment_id: ID of the payment to add the order(s) to
54-
:param order_data: Either a dict of attributes for a single order, or a list of such dicts for several
54+
:param order_data: Either a dict of attributes for a single order,
55+
or a list of such dicts for several
5556
:return: List of Order instances that were added to the payment
5657
"""
5758
if type(order_data) is dict:
5859
order_data = [order_data]
5960

6061
response = (
61-
self.request(f"{self.PAYMENTS_PATH}/{payment_id}/orders").set_body({"orders": order_data}).put()
62+
self.request(f"{self.PAYMENTS_PATH}/{payment_id}/orders")
63+
.set_body({"orders": order_data})
64+
.put()
6265
)
6366

6467
return [Order(o) for o in response.json]
@@ -68,14 +71,17 @@ def set_orders_for(self, payment_id, order_data: Union[List[dict], dict]) -> Lis
6871
Sets one or several orders on the given payment (replacing existing ones)
6972
7073
:param payment_id: ID of the payment to add the order(s) to
71-
:param order_data: Either a dict of attributes for a single order, or a list of such dicts for several
74+
:param order_data: Either a dict of attributes for a single order,
75+
or a list of such dicts for several
7276
:return: List of Order instances that were added to the payment
7377
"""
7478
if type(order_data) is dict:
7579
order_data = [order_data]
7680

7781
response = (
78-
self.request(f"{self.PAYMENTS_PATH}/{payment_id}/orders").set_body({"orders": order_data}).post()
82+
self.request(f"{self.PAYMENTS_PATH}/{payment_id}/orders")
83+
.set_body({"orders": order_data})
84+
.post()
7985
)
8086

8187
return [Order(o) for o in response.json]
@@ -86,12 +92,14 @@ def get_orders_for(self, payment_id) -> List[Order]:
8692

8793
def refund(self, payment_id: str, amount: int, full_refund: bool = False, **params) -> Payment:
8894
"""
89-
Refunds given payment of the given amount (in cents). If `full_refund` is `True`, `amount` is ignored
95+
Refunds given payment of the given amount (in cents).
96+
If `full_refund` is `True`, `amount` is ignored
9097
to trigger a full refund of the payment, including potential customer fees.
9198
9299
:param payment_id: ID of the payment to refund
93100
:param amount: Amount, in cents, to be refunded on the payment
94-
:param full_refund: True if the full payment should be refunded (with customer fees). Default: false.
101+
:param full_refund: True if the full payment should be refunded (with customer fees).
102+
Default: false.
95103
:return: Updated payment object
96104
"""
97105
req = self.request(f"{self.PAYMENTS_PATH}/{payment_id}/refund")
@@ -109,8 +117,8 @@ def send_sms(self, payment_id: str):
109117
"""
110118
Sends a payment link via SMS, to the customer's saved mobile phone number.
111119
112-
Will raise RequestError if the SMS API is not activated on your account or in case of any other error,
113-
otherwise returns True.
120+
Will raise RequestError if the SMS API is not activated on your account or
121+
in case of any other error, otherwise returns True.
114122
"""
115123
self.request(f"{self.PAYMENTS_PATH}/{payment_id}/send-sms").post()
116124

alma/entities/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# flake8: noqa
2+
13
from .base import Base
24
from .eligibility import Eligibility
35
from .installment import Installment, InstallmentState

alma/entities/installment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def __init__(self, data):
1818
try:
1919
self.state = InstallmentState(state)
2020
except ValueError:
21-
# Pass on unrecognized state values - they will be accessible as-is in the Installment data
21+
# Pass on unrecognized state values
22+
# they will be accessible as-is in the Installment data
2223
pass
2324

2425
super(Installment, self).__init__(data)

alma/entities/payment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class PaymentState(Enum):
2727
LATE_DUNNING = "late_dunning"
2828
# Next installment is very late, between 8 and 15 days. Contacting customer with email and SMS
2929
LATE_CONTACT_CUSTOMER = "late_contact_customer"
30-
# More than 15 days late, payment is considered in default: (i) claim is opened and (ii) payments
31-
# switches to judiciary collection
30+
# More than 15 days late, payment is considered in default:
31+
# (i) claim is opened and (ii) payments switches to judiciary collection
3232
DEFAULT = "default"
3333
# After default, we may recover part of the payment through judiciary collection.
3434
# Once collection has been completed, this stage is reached and nothing happens anymore
@@ -50,7 +50,8 @@ def __init__(self, data):
5050
try:
5151
self.state = PaymentState(state)
5252
except ValueError:
53-
# Pass on unrecognized state values - they will be accessible as-is in the Payment data
53+
# Pass on unrecognized state values
54+
# they will be accessible as-is in the Payment data
5455
pass
5556

5657
orders = data.pop("orders", [])

alma/paginated_results.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
class PaginatedResults(Sequence, Iterable):
8-
def __init__(self, data: dict, entity: Union[None, Type[BaseEntity]], next_page: Union[None, Callable]):
8+
def __init__(
9+
self, data: dict, entity: Union[None, Type[BaseEntity]], next_page: Union[None, Callable]
10+
):
911
self._data = data
1012
self._entities = [entity(d) for d in data.get("data", [])]
1113
self._next_page = next_page

0 commit comments

Comments
 (0)