Skip to content

Commit 5da96e1

Browse files
Merge pull request #290 from eclecticiq/add-black-format
Add standard format
2 parents 3b42388 + 1fe3bf5 commit 5da96e1

89 files changed

Lines changed: 1909 additions & 1408 deletions

File tree

Some content is hidden

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

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[flake8]
22
max-line-length=120
33
exclude = docs/*,.tox/*
4+
ignore = E203, W503, W504, E704

.git-blame-ignore-revs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Initial commit to format the codebase with black
2+
e454428fdf5b3d32f8ffbe9bded3878a80e7b169
3+
# Initial commit to sort import on the codebase
4+
2d69e4fb6daf037cb2f4358fde0c6c96e3f7ca16
5+

.github/workflows/format.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Check format
2+
3+
on:
4+
- pull_request
5+
jobs:
6+
check:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Set up Python
11+
uses: actions/setup-python@v5
12+
with:
13+
python-version: "3.10"
14+
- name: Install deps
15+
run: pip install -r requirements-dev.txt
16+
- name: Run black
17+
run: black --check opentaxii/ tests/
18+
- name: Run isort
19+
run: isort --check-only opentaxii/ tests/

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# serve to show the default.
1414

1515
import datetime
16-
import sys
1716
import os
17+
import sys
18+
1819
import sphinx_rtd_theme
1920

2021
# If extensions (or modules to document with autodoc) are in another directory,

docs/update_db_schema_diagram.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
current_dir = os.path.dirname(__file__)
66
sys.path.append(os.path.abspath(os.path.join(current_dir, "..")))
77

8-
from opentaxii.persistence.sqldb.models import Base
98
from sqla_graphs import TableGrapher
109

10+
from opentaxii.persistence.sqldb.models import Base
11+
1112
grapher = TableGrapher(
1213
style={"node_table_header": {"bgcolor": "#000080"}},
1314
graph_options={"size": "30,30!"}, # inches, this maps to 2880px

examples/hooks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
from opentaxii.signals import (
3-
CONTENT_BLOCK_CREATED, INBOX_MESSAGE_CREATED, SUBSCRIPTION_CREATED
3+
CONTENT_BLOCK_CREATED,
4+
INBOX_MESSAGE_CREATED,
5+
SUBSCRIPTION_CREATED,
46
)
57

68

opentaxii/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'''
2-
OpenTAXII, TAXII server implementation from EclecticIQ.
2+
OpenTAXII, TAXII server implementation from EclecticIQ.
33
'''
4+
45
# flake8: noqa
56

67
from ._version import __version__
7-
from .server import TAXIIServer
88
from .config import ServerConfig
99
from .entities import Account
10-
1110
from .local import context
11+
from .server import TAXIIServer

opentaxii/auth/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class OpenTAXIIAuthAPI:
32
'''Abstract class that represents OpenTAXII Authentication API.
43

opentaxii/auth/manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def update_account(self, account, password):
4747
for colname, permission in list(account.permissions.items()):
4848
collection = self.server.servers.taxii1.persistence.get_collection(colname)
4949
if not collection:
50-
log.warning(
51-
"update_account.unknown_collection",
52-
collection=colname)
50+
log.warning("update_account.unknown_collection", collection=colname)
5351
account.permissions.pop(colname)
5452
account = self.api.update_account(account, password)
5553
return account

opentaxii/auth/sqldb/api.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import jwt
44
import structlog
5+
from sqlalchemy.orm import exc
6+
57
from opentaxii.auth import OpenTAXIIAuthAPI
68
from opentaxii.common.sqldb import BaseSQLDatabaseAPI
79
from opentaxii.entities import Account as AccountEntity
8-
from sqlalchemy.orm import exc
910

1011
from .models import Account, Base
1112

@@ -32,16 +33,19 @@ class SQLDatabaseAPI(BaseSQLDatabaseAPI, OpenTAXIIAuthAPI):
3233
BASEMODEL = Base
3334

3435
def __init__(
35-
self,
36-
db_connection,
37-
create_tables=False,
38-
secret=None,
39-
token_ttl_secs=None,
40-
**engine_parameters):
36+
self,
37+
db_connection,
38+
create_tables=False,
39+
secret=None,
40+
token_ttl_secs=None,
41+
**engine_parameters,
42+
):
4143
super().__init__(db_connection, create_tables, **engine_parameters)
4244
if not secret:
43-
raise ValueError('Secret is not defined for %s.%s' % (
44-
self.__module__, self.__class__.__name__))
45+
raise ValueError(
46+
'Secret is not defined for %s.%s'
47+
% (self.__module__, self.__class__.__name__)
48+
)
4549
self.secret = secret
4650
self.token_ttl_secs = token_ttl_secs or 60 * 60 # 60min
4751

@@ -71,18 +75,25 @@ def get_account(self, token):
7175
return account_to_account_entity(account)
7276

7377
def delete_account(self, username):
74-
account = self.db.session.query(Account).filter_by(username=username).one_or_none()
78+
account = (
79+
self.db.session.query(Account).filter_by(username=username).one_or_none()
80+
)
7581
if account:
7682
self.db.session.delete(account)
7783
self.db.session.commit()
7884

7985
def get_accounts(self):
8086
return [
8187
account_to_account_entity(account)
82-
for account in self.db.session.query(Account).all()]
88+
for account in self.db.session.query(Account).all()
89+
]
8390

8491
def update_account(self, obj, password=None):
85-
account = self.db.session.query(Account).filter_by(username=obj.username).one_or_none()
92+
account = (
93+
self.db.session.query(Account)
94+
.filter_by(username=obj.username)
95+
.one_or_none()
96+
)
8697
if not account:
8798
account = Account(username=obj.username)
8899
self.db.session.add(account)
@@ -120,4 +131,5 @@ def account_to_account_entity(account):
120131
id=account.id,
121132
username=account.username,
122133
is_admin=account.is_admin,
123-
permissions=account.permissions)
134+
permissions=account.permissions,
135+
)

0 commit comments

Comments
 (0)