Skip to content

Commit f9adfb3

Browse files
committed
Merge branch 'master' into dev-1150-underscores
2 parents bb529bd + f357955 commit f9adfb3

17 files changed

+111
-61
lines changed

.github/workflows/development.yaml

+18-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,28 @@ jobs:
9090
run: |
9191
export HOST_UID=$(id -u)
9292
docker-compose -f LNX-docker-compose.yml up --build --exit-code-from app
93+
lint:
94+
runs-on: ubuntu-latest
95+
strategy:
96+
matrix:
97+
py_ver: ["3.11"]
98+
steps:
99+
- uses: actions/checkout@v3
100+
- name: Set up Python ${{matrix.py_ver}}
101+
uses: actions/setup-python@v4
102+
with:
103+
python-version: ${{matrix.py_ver}}
104+
- name: Install dependencies
105+
run: |
106+
python -m pip install --upgrade pip
107+
pip install flake8 black==24.2.0
108+
- name: Run syntax tests
109+
run: flake8 datajoint --count --select=E9,F63,F7,F82 --show-source --statistics
93110
- name: Run style tests
94111
run: |
95112
flake8 --ignore=E203,E722,W503 datajoint \
96113
--count --max-complexity=62 --max-line-length=127 --statistics
97-
black datajoint --check -v
98-
black tests --check -v
99-
black tests_old --check -v
114+
black --required-version '24.2.0' --check -v datajoint tests tests_old
100115
codespell:
101116
name: Check for spelling errors
102117
permissions:

datajoint/autopopulate.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This module defines class dj.AutoPopulate"""
2+
23
import logging
34
import datetime
45
import traceback

datajoint/blob.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,11 @@ def pack_recarray(self, array):
322322
+ "\0".join(array.dtype.names).encode() # number of fields
323323
+ b"\0"
324324
+ b"".join( # field names
325-
self.pack_recarray(array[f])
326-
if array[f].dtype.fields
327-
else self.pack_array(array[f])
325+
(
326+
self.pack_recarray(array[f])
327+
if array[f].dtype.fields
328+
else self.pack_array(array[f])
329+
)
328330
for f in array.dtype.names
329331
)
330332
)

datajoint/connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module contains the Connection class that manages the connection to the database, and
33
the ``conn`` function that provides access to a persistent connection in datajoint.
44
"""
5+
56
import warnings
67
from contextlib import contextmanager
78
import pymysql as client

datajoint/declare.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module hosts functions to convert DataJoint table definitions into mysql table definitions, and to
33
declare the corresponding mysql tables.
44
"""
5+
56
import re
67
import pyparsing as pp
78
import logging
@@ -382,9 +383,7 @@ def _make_attribute_alter(new, old, primary_key):
382383
command=(
383384
"ADD"
384385
if (old_name or new_name) not in old_names
385-
else "MODIFY"
386-
if not old_name
387-
else "CHANGE `%s`" % old_name
386+
else "MODIFY" if not old_name else "CHANGE `%s`" % old_name
388387
),
389388
new_def=new_def,
390389
after="" if after is None else "AFTER `%s`" % after,

datajoint/diagram.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,15 @@ def make_dot(self):
385385
assert issubclass(cls, Table)
386386
description = cls().describe(context=self.context).split("\n")
387387
description = (
388-
"-" * 30
389-
if q.startswith("---")
390-
else q.replace("->", "→")
391-
if "->" in q
392-
else q.split(":")[0]
388+
(
389+
"-" * 30
390+
if q.startswith("---")
391+
else (
392+
q.replace("->", "→")
393+
if "->" in q
394+
else q.split(":")[0]
395+
)
396+
)
393397
for q in description
394398
if not q.startswith("#")
395399
)

datajoint/expression.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ def primary_key(self):
100100

101101
def from_clause(self):
102102
support = (
103-
"(" + src.make_sql() + ") as `$%x`" % next(self._subquery_alias_count)
104-
if isinstance(src, QueryExpression)
105-
else src
103+
(
104+
"(" + src.make_sql() + ") as `$%x`" % next(self._subquery_alias_count)
105+
if isinstance(src, QueryExpression)
106+
else src
107+
)
106108
for src in self.support
107109
)
108110
clause = next(support)
@@ -704,14 +706,16 @@ def make_sql(self, fields=None):
704706
fields=fields,
705707
from_=self.from_clause(),
706708
where=self.where_clause(),
707-
group_by=""
708-
if not self.primary_key
709-
else (
710-
" GROUP BY `%s`" % "`,`".join(self._grouping_attributes)
711-
+ (
712-
""
713-
if not self.restriction
714-
else " HAVING (%s)" % ")AND(".join(self.restriction)
709+
group_by=(
710+
""
711+
if not self.primary_key
712+
else (
713+
" GROUP BY `%s`" % "`,`".join(self._grouping_attributes)
714+
+ (
715+
""
716+
if not self.restriction
717+
else " HAVING (%s)" % ")AND(".join(self.restriction)
718+
)
715719
)
716720
),
717721
)
@@ -773,12 +777,16 @@ def make_sql(self):
773777
# no secondary attributes: use UNION DISTINCT
774778
fields = arg1.primary_key
775779
return "SELECT * FROM (({sql1}) UNION ({sql2})) as `_u{alias}`".format(
776-
sql1=arg1.make_sql()
777-
if isinstance(arg1, Union)
778-
else arg1.make_sql(fields),
779-
sql2=arg2.make_sql()
780-
if isinstance(arg2, Union)
781-
else arg2.make_sql(fields),
780+
sql1=(
781+
arg1.make_sql()
782+
if isinstance(arg1, Union)
783+
else arg1.make_sql(fields)
784+
),
785+
sql2=(
786+
arg2.make_sql()
787+
if isinstance(arg2, Union)
788+
else arg2.make_sql(fields)
789+
),
782790
alias=next(self.__count),
783791
)
784792
# with secondary attributes, use union of left join with antijoin

datajoint/fetch.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,15 @@ def __call__(
244244
]
245245
else:
246246
return_values = [
247-
list(
248-
(to_dicts if as_dict else lambda x: x)(
249-
ret[self._expression.primary_key]
247+
(
248+
list(
249+
(to_dicts if as_dict else lambda x: x)(
250+
ret[self._expression.primary_key]
251+
)
250252
)
253+
if is_key(attribute)
254+
else ret[attribute]
251255
)
252-
if is_key(attribute)
253-
else ret[attribute]
254256
for attribute in attrs
255257
]
256258
ret = return_values[0] if len(attrs) == 1 else return_values
@@ -272,12 +274,14 @@ def __call__(
272274
else np.dtype(
273275
[
274276
(
275-
name,
276-
type(value),
277-
) # use the first element to determine blob type
278-
if heading[name].is_blob
279-
and isinstance(value, numbers.Number)
280-
else (name, heading.as_dtype[name])
277+
(
278+
name,
279+
type(value),
280+
) # use the first element to determine blob type
281+
if heading[name].is_blob
282+
and isinstance(value, numbers.Number)
283+
else (name, heading.as_dtype[name])
284+
)
281285
for value, name in zip(ret[0], heading.as_dtype.names)
282286
]
283287
)
@@ -353,9 +357,11 @@ def __call__(self, *attrs, squeeze=False, download_path="."):
353357
"fetch1 should only return one tuple. %d tuples found" % len(result)
354358
)
355359
return_values = tuple(
356-
next(to_dicts(result[self._expression.primary_key]))
357-
if is_key(attribute)
358-
else result[attribute][0]
360+
(
361+
next(to_dicts(result[self._expression.primary_key]))
362+
if is_key(attribute)
363+
else result[attribute][0]
364+
)
359365
for attribute in attrs
360366
)
361367
ret = return_values[0] if len(attrs) == 1 else return_values

datajoint/heading.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,12 @@ def as_sql(self, fields, include_aliases=True):
193193
represent heading as the SQL SELECT clause.
194194
"""
195195
return ",".join(
196-
"`%s`" % name
197-
if self.attributes[name].attribute_expression is None
198-
else self.attributes[name].attribute_expression
199-
+ (" as `%s`" % name if include_aliases else "")
196+
(
197+
"`%s`" % name
198+
if self.attributes[name].attribute_expression is None
199+
else self.attributes[name].attribute_expression
200+
+ (" as `%s`" % name if include_aliases else "")
201+
)
200202
for name in fields
201203
)
202204

@@ -371,9 +373,11 @@ def _init_from_database(self):
371373
is_blob=category in ("INTERNAL_BLOB", "EXTERNAL_BLOB"),
372374
uuid=category == "UUID",
373375
is_external=category in EXTERNAL_TYPES,
374-
store=attr["type"].split("@")[1]
375-
if category in EXTERNAL_TYPES
376-
else None,
376+
store=(
377+
attr["type"].split("@")[1]
378+
if category in EXTERNAL_TYPES
379+
else None
380+
),
377381
)
378382

379383
if attr["in_key"] and any(

datajoint/preview.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def repr_html(query_expression):
126126
head_template.format(
127127
column=c,
128128
comment=heading.attributes[c].comment,
129-
primary="primary"
130-
if c in query_expression.primary_key
131-
else "nonprimary",
129+
primary=(
130+
"primary" if c in query_expression.primary_key else "nonprimary"
131+
),
132132
)
133133
for c in heading.names
134134
),
@@ -145,7 +145,9 @@ def repr_html(query_expression):
145145
for tup in tuples
146146
]
147147
),
148-
count=("<p>Total: %d</p>" % len(rel))
149-
if config["display.show_tuple_count"]
150-
else "",
148+
count=(
149+
("<p>Total: %d</p>" % len(rel))
150+
if config["display.show_tuple_count"]
151+
else ""
152+
),
151153
)

datajoint/s3.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
AWS S3 operations
33
"""
4+
45
from io import BytesIO
56
import minio # https://docs.minio.io/docs/python-client-api-reference
67
import urllib3

datajoint/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Settings for DataJoint.
33
"""
4+
45
from contextlib import contextmanager
56
import json
67
import os

datajoint/table.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,11 @@ def describe(self, context=None, printout=False):
770770
if do_include:
771771
attributes_declared.add(attr.name)
772772
definition += "%-20s : %-28s %s\n" % (
773-
attr.name
774-
if attr.default is None
775-
else "%s=%s" % (attr.name, attr.default),
773+
(
774+
attr.name
775+
if attr.default is None
776+
else "%s=%s" % (attr.name, attr.default)
777+
),
776778
"%s%s"
777779
% (attr.type, " auto_increment" if attr.autoincrement else ""),
778780
"# " + attr.comment if attr.comment else "",

tests/schema_simple.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
A simple, abstract schema to test relational algebra
33
"""
4+
45
import random
56
import datajoint as dj
67
import itertools

tests/test_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Collection of test cases to test core module.
33
"""
4+
45
from datajoint import DataJointError
56
from datajoint.utils import from_camel_case, to_camel_case
67
import pytest

tests_old/schema_simple.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
A simple, abstract schema to test relational algebra
33
"""
4+
45
import random
56
import datajoint as dj
67
import itertools

tests_old/test_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Collection of test cases to test core module.
33
"""
4+
45
from nose.tools import assert_true, assert_raises, assert_equal
56
from datajoint import DataJointError
67
from datajoint.utils import from_camel_case, to_camel_case

0 commit comments

Comments
 (0)