Skip to content

Commit c3c5489

Browse files
Merge pull request #998 from A-Baji/black-formatting
Black formatting
2 parents 413e2f9 + c5f0a19 commit c3c5489

Some content is hidden

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

80 files changed

+5421
-3003
lines changed

.github/workflows/development.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33-
pip install flake8
33+
pip install flake8 black
3434
- name: Run syntax tests
3535
run: flake8 datajoint --count --select=E9,F63,F7,F82 --show-source --statistics
3636
- name: Run primary tests
@@ -47,5 +47,7 @@ jobs:
4747
run: docker-compose -f LNX-docker-compose.yml up --build --exit-code-from app
4848
- name: Run style tests
4949
run: |
50-
flake8 --ignore=E121,E123,E126,E226,E24,E704,W503,W504,E722,F401,W605 datajoint \
50+
flake8 --ignore=E203,E722,F401,W503 datajoint \
5151
--count --max-complexity=62 --max-line-length=127 --statistics
52+
black datajoint --check -v
53+
black tests --check -v

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## Release notes
22

3-
### 0.13.4 -- March, 25 2022
3+
### 0.13.4 -- March, 28 2022
44
* Add - Allow reading blobs produced by legacy 32-bit compiled mYm library for matlab. PR #995
55
* Bugfix - Add missing `jobs` argument for multiprocessing PR #997
66
* Add - Test for multiprocessing PR #1008
77
* Bugfix - Fix external store key name doesn't allow '-' (#1005) PR #1006
8+
* Add - Adopted black formatting into code base PR #998
89

910
### 0.13.3 -- Feb 9, 2022
1011
* Bugfix - Fix error in listing ancestors, descendants with part tables.

datajoint/__init__.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,40 @@
1616

1717
__author__ = "DataJoint Contributors"
1818
__date__ = "November 7, 2020"
19-
__all__ = ['__author__', '__version__',
20-
'config', 'conn', 'Connection',
21-
'Schema', 'schema', 'VirtualModule', 'create_virtual_module',
22-
'list_schemas', 'Table', 'FreeTable',
23-
'Manual', 'Lookup', 'Imported', 'Computed', 'Part',
24-
'Not', 'AndList', 'U', 'Diagram', 'Di', 'ERD',
25-
'set_password', 'kill',
26-
'MatCell', 'MatStruct', 'AttributeAdapter',
27-
'errors', 'DataJointError', 'key', 'key_hash']
19+
__all__ = [
20+
"__author__",
21+
"__version__",
22+
"config",
23+
"conn",
24+
"Connection",
25+
"Schema",
26+
"schema",
27+
"VirtualModule",
28+
"create_virtual_module",
29+
"list_schemas",
30+
"Table",
31+
"FreeTable",
32+
"Manual",
33+
"Lookup",
34+
"Imported",
35+
"Computed",
36+
"Part",
37+
"Not",
38+
"AndList",
39+
"U",
40+
"Diagram",
41+
"Di",
42+
"ERD",
43+
"set_password",
44+
"kill",
45+
"MatCell",
46+
"MatStruct",
47+
"AttributeAdapter",
48+
"errors",
49+
"DataJointError",
50+
"key",
51+
"key_hash",
52+
]
2853

2954
from .version import __version__
3055
from .settings import config
@@ -44,6 +69,6 @@
4469
from .errors import DataJointError
4570
from .migrate import migrate_dj011_external_blob_storage_to_dj012
4671

47-
ERD = Di = Diagram # Aliases for Diagram
48-
schema = Schema # Aliases for Schema
49-
create_virtual_module = VirtualModule # Aliases for VirtualModule
72+
ERD = Di = Diagram # Aliases for Diagram
73+
schema = Schema # Aliases for Schema
74+
create_virtual_module = VirtualModule # Aliases for VirtualModule

datajoint/admin.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
from .utils import user_choice
66

77

8-
def set_password(new_password=None, connection=None, update_config=None): # pragma: no cover
8+
def set_password(
9+
new_password=None, connection=None, update_config=None
10+
): # pragma: no cover
911
connection = conn() if connection is None else connection
1012
if new_password is None:
11-
new_password = getpass('New password: ')
12-
confirm_password = getpass('Confirm password: ')
13+
new_password = getpass("New password: ")
14+
confirm_password = getpass("Confirm password: ")
1315
if new_password != confirm_password:
14-
print('Failed to confirm the password! Aborting password change.')
16+
print("Failed to confirm the password! Aborting password change.")
1517
return
1618
connection.query("SET PASSWORD = PASSWORD('%s')" % new_password)
17-
print('Password updated.')
19+
print("Password updated.")
1820

19-
if update_config or (update_config is None and user_choice('Update local setting?') == 'yes'):
20-
config['database.password'] = new_password
21+
if update_config or (
22+
update_config is None and user_choice("Update local setting?") == "yes"
23+
):
24+
config["database.password"] = new_password
2125
config.save_local(verbose=True)
2226

2327

@@ -40,24 +44,32 @@ def kill(restriction=None, connection=None, order_by=None): # pragma: no cover
4044
connection = conn()
4145

4246
if order_by is not None and not isinstance(order_by, str):
43-
order_by = ','.join(order_by)
47+
order_by = ",".join(order_by)
4448

45-
query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()' + (
46-
"" if restriction is None else ' AND (%s)' % restriction) + (
47-
' ORDER BY %s' % (order_by or 'id'))
49+
query = (
50+
"SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
51+
+ ("" if restriction is None else " AND (%s)" % restriction)
52+
+ (" ORDER BY %s" % (order_by or "id"))
53+
)
4854

4955
while True:
50-
print(' ID USER HOST STATE TIME INFO')
51-
print('+--+ +----------+ +-----------+ +-----------+ +-----+')
52-
cur = ({k.lower(): v for k, v in elem.items()}
53-
for elem in connection.query(query, as_dict=True))
56+
print(" ID USER HOST STATE TIME INFO")
57+
print("+--+ +----------+ +-----------+ +-----------+ +-----+")
58+
cur = (
59+
{k.lower(): v for k, v in elem.items()}
60+
for elem in connection.query(query, as_dict=True)
61+
)
5462
for process in cur:
5563
try:
56-
print('{id:>4d} {user:<12s} {host:<12s} {state:<12s} {time:>7d} {info}'.format(**process))
64+
print(
65+
"{id:>4d} {user:<12s} {host:<12s} {state:<12s} {time:>7d} {info}".format(
66+
**process
67+
)
68+
)
5769
except TypeError:
5870
print(process)
5971
response = input('process to kill or "q" to quit > ')
60-
if response == 'q':
72+
if response == "q":
6173
break
6274
if response:
6375
try:
@@ -66,9 +78,9 @@ def kill(restriction=None, connection=None, order_by=None): # pragma: no cover
6678
pass # ignore non-numeric input
6779
else:
6880
try:
69-
connection.query('kill %d' % pid)
81+
connection.query("kill %d" % pid)
7082
except pymysql.err.InternalError:
71-
print('Process not found')
83+
print("Process not found")
7284

7385

7486
def kill_quick(restriction=None, connection=None):
@@ -86,13 +98,17 @@ def kill_quick(restriction=None, connection=None):
8698
if connection is None:
8799
connection = conn()
88100

89-
query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()' + (
90-
"" if restriction is None else ' AND (%s)' % restriction)
101+
query = (
102+
"SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
103+
+ ("" if restriction is None else " AND (%s)" % restriction)
104+
)
91105

92-
cur = ({k.lower(): v for k, v in elem.items()}
93-
for elem in connection.query(query, as_dict=True))
106+
cur = (
107+
{k.lower(): v for k, v in elem.items()}
108+
for elem in connection.query(query, as_dict=True)
109+
)
94110
nkill = 0
95111
for process in cur:
96-
connection.query('kill %d' % process['id'])
112+
connection.query("kill %d" % process["id"])
97113
nkill += 1
98114
return nkill

datajoint/attribute_adapter.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,62 @@ class AttributeAdapter:
77
"""
88
Base class for adapter objects for user-defined attribute types.
99
"""
10+
1011
@property
1112
def attribute_type(self):
1213
"""
1314
:return: a supported DataJoint attribute type to use; e.g. "longblob", "blob@store"
1415
"""
15-
raise NotImplementedError('Undefined attribute adapter')
16+
raise NotImplementedError("Undefined attribute adapter")
1617

1718
def get(self, value):
1819
"""
1920
convert value retrieved from the the attribute in a table into the adapted type
2021
:param value: value from the database
2122
:return: object of the adapted type
2223
"""
23-
raise NotImplementedError('Undefined attribute adapter')
24+
raise NotImplementedError("Undefined attribute adapter")
2425

2526
def put(self, obj):
2627
"""
2728
convert an object of the adapted type into a value that DataJoint can store in a table attribute
2829
:param obj: an object of the adapted type
2930
:return: value to store in the database
3031
"""
31-
raise NotImplementedError('Undefined attribute adapter')
32+
raise NotImplementedError("Undefined attribute adapter")
3233

3334

3435
def get_adapter(context, adapter_name):
3536
"""
3637
Extract the AttributeAdapter object by its name from the context and validate.
3738
"""
3839
if not _support_adapted_types():
39-
raise DataJointError('Support for Adapted Attribute types is disabled.')
40-
adapter_name = adapter_name.lstrip('<').rstrip('>')
40+
raise DataJointError("Support for Adapted Attribute types is disabled.")
41+
adapter_name = adapter_name.lstrip("<").rstrip(">")
4142
try:
42-
adapter = (context[adapter_name] if adapter_name in context
43-
else type_plugins[adapter_name]['object'].load())
43+
adapter = (
44+
context[adapter_name]
45+
if adapter_name in context
46+
else type_plugins[adapter_name]["object"].load()
47+
)
4448
except KeyError:
4549
raise DataJointError(
46-
"Attribute adapter '{adapter_name}' is not defined.".format(adapter_name=adapter_name))
50+
"Attribute adapter '{adapter_name}' is not defined.".format(
51+
adapter_name=adapter_name
52+
)
53+
)
4754
if not isinstance(adapter, AttributeAdapter):
4855
raise DataJointError(
4956
"Attribute adapter '{adapter_name}' must be an instance of datajoint.AttributeAdapter".format(
50-
adapter_name=adapter_name))
51-
if not isinstance(adapter.attribute_type, str) or not re.match(r'^\w', adapter.attribute_type):
52-
raise DataJointError("Invalid attribute type {type} in attribute adapter '{adapter_name}'".format(
53-
type=adapter.attribute_type, adapter_name=adapter_name))
57+
adapter_name=adapter_name
58+
)
59+
)
60+
if not isinstance(adapter.attribute_type, str) or not re.match(
61+
r"^\w", adapter.attribute_type
62+
):
63+
raise DataJointError(
64+
"Invalid attribute type {type} in attribute adapter '{adapter_name}'".format(
65+
type=adapter.attribute_type, adapter_name=adapter_name
66+
)
67+
)
5468
return adapter

0 commit comments

Comments
 (0)