Skip to content

Commit 205747a

Browse files
authored
Merge pull request #220 from lsst/tickets/DM-32437
DM-32437: format with black and isort
2 parents 6fda105 + 8c8a5a7 commit 205747a

51 files changed

Lines changed: 2304 additions & 1660 deletions

Some content is hidden

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

.github/workflows/formatting.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: check Python formatting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.8
19+
20+
- name: Install isort and black
21+
run: pip install isort black
22+
23+
- name: Run isort
24+
run: isort --check-only python/ tests/
25+
26+
- name: Run black
27+
run: black --check --verbose --diff python/ tests/

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 21.11b1
10+
hooks:
11+
- id: black
12+
# It is recommended to specify the latest version of Python
13+
# supported by your project here, or alternatively use
14+
# pre-commit's default_language_version, see
15+
# https://pre-commit.com/#top_level-default_language_version
16+
language_version: python3.8
17+
- repo: https://github.com/pycqa/isort
18+
rev: 5.10.1
19+
hooks:
20+
- id: isort
21+
name: isort (python)

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@
3636
directory = "removal"
3737
name = "An API Removal or Deprecation"
3838
showcontent = false
39+
40+
[tool.black]
41+
line-length = 110
42+
target-version = ["py38"]
43+
44+
[tool.isort]
45+
profile = "black"
46+
line_length = 110

python/lsst/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import pkgutil
2+
23
import lsstimport
4+
35
__path__ = pkgutil.extend_path(__path__, __name__)

python/lsst/pipe/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import pkgutil
2+
23
import lsstimport
4+
35
__path__ = pkgutil.extend_path(__path__, __name__)

python/lsst/pipe/base/__init__.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
from .version import *
1+
from . import connectionTypes, pipelineIR
2+
from ._status import *
3+
from ._task_metadata import *
24
from .argumentParser import *
3-
from .struct import *
4-
from .task import *
5+
from .butlerQuantumContext import *
56
from .cmdLineTask import *
6-
from .timer import *
77
from .config import *
8-
from .pipelineTask import *
9-
from .pipeline import *
8+
from .connections import *
9+
from .executionButlerBuilder import *
1010
from .graph import *
1111
from .graphBuilder import *
12-
from .taskFactory import *
12+
from .pipeline import *
13+
from .pipelineTask import *
14+
from .struct import *
15+
from .task import *
1316
from .task_logging import getTaskLogger
14-
from .connections import *
15-
from .butlerQuantumContext import *
16-
from . import connectionTypes
17-
from . import pipelineIR
18-
from .executionButlerBuilder import *
19-
from ._status import *
20-
from ._task_metadata import *
17+
from .taskFactory import *
18+
from .timer import *
19+
from .version import *

python/lsst/pipe/base/_datasetQueryConstraints.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626

2727
__all__ = ("DatasetQueryConstraintVariant",)
2828

29-
from typing import Type, Protocol, Iterable, Iterator
30-
3129
import warnings
30+
from typing import Iterable, Iterator, Protocol, Type
3231

3332

3433
class DatasetQueryConstraintVariant(Iterable, Protocol):
@@ -54,9 +53,10 @@ class DatasetQueryConstraintVariant(Iterable, Protocol):
5453
Variants can be directly used, or automatically be selected by using the
5554
`fromExpression` class method given a valid string.
5655
"""
57-
ALL: 'Type[_ALL]'
58-
OFF: 'Type[_OFF]'
59-
LIST: 'Type[_LIST]'
56+
57+
ALL: "Type[_ALL]"
58+
OFF: "Type[_OFF]"
59+
LIST: "Type[_LIST]"
6060

6161
@classmethod
6262
def __subclasshook__(cls, subclass):
@@ -65,7 +65,7 @@ def __subclasshook__(cls, subclass):
6565
return False
6666

6767
@classmethod
68-
def fromExpression(cls, expression: str) -> 'DatasetQueryConstraintVariant':
68+
def fromExpression(cls, expression: str) -> "DatasetQueryConstraintVariant":
6969
"""Select and return the correct Variant that corresponds to the input
7070
expression.
7171
@@ -75,15 +75,15 @@ def fromExpression(cls, expression: str) -> 'DatasetQueryConstraintVariant':
7575
"""
7676
if not isinstance(expression, str):
7777
raise ValueError("Expression must be a string")
78-
elif expression == 'all':
78+
elif expression == "all":
7979
return cls.ALL
80-
elif expression == 'off':
80+
elif expression == "off":
8181
return cls.OFF
8282
else:
8383
if " " in expression:
8484
warnings.warn("Witespace found in expression will be trimmed", RuntimeWarning)
85-
expression = expression.replace(' ', '')
86-
members = expression.split(',')
85+
expression = expression.replace(" ", "")
86+
members = expression.split(",")
8787
return cls.LIST(members)
8888

8989

@@ -143,8 +143,10 @@ def __eq__(self, o: object) -> bool:
143143

144144

145145
def suppressInit(self):
146-
raise NotImplementedError("DatasetQueryConstraintVariants cannot be directly instantiated. "
147-
"Please use the variants or the fromExpression class method")
146+
raise NotImplementedError(
147+
"DatasetQueryConstraintVariants cannot be directly instantiated. "
148+
"Please use the variants or the fromExpression class method"
149+
)
148150

149151

150152
DatasetQueryConstraintVariant.__init__ = suppressInit

python/lsst/pipe/base/_task_metadata.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
__all__ = ["TaskMetadata"]
2323

24-
import numbers
2524
import itertools
25+
import numbers
2626
import warnings
2727
from collections.abc import Sequence
28-
from deprecated.sphinx import deprecated
28+
from typing import Any, Collection, Dict, List, Mapping, Protocol, Union
2929

30-
from typing import Dict, List, Union, Any, Mapping, Protocol, Collection
31-
from pydantic import BaseModel, StrictInt, StrictFloat, StrictBool, StrictStr, Field
30+
from deprecated.sphinx import deprecated
31+
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr
3232

3333
_DEPRECATION_REASON = "Will be removed after v25."
3434
_DEPRECATION_VERSION = "v24"
@@ -73,8 +73,9 @@ class TaskMetadata(BaseModel):
7373
"""
7474

7575
scalars: Dict[str, Union[StrictFloat, StrictInt, StrictBool, StrictStr]] = Field(default_factory=dict)
76-
arrays: Dict[str, Union[List[StrictFloat], List[StrictInt], List[StrictBool],
77-
List[StrictStr]]] = Field(default_factory=dict)
76+
arrays: Dict[str, Union[List[StrictFloat], List[StrictInt], List[StrictBool], List[StrictStr]]] = Field(
77+
default_factory=dict
78+
)
7879
metadata: Dict[str, "TaskMetadata"] = Field(default_factory=dict)
7980

8081
@classmethod
@@ -175,8 +176,11 @@ def add(self, name, value):
175176

176177
self.metadata[key0].add(".".join(keys), value)
177178

178-
@deprecated(reason="Cast the return value to float explicitly. " + _DEPRECATION_REASON,
179-
version=_DEPRECATION_VERSION, category=FutureWarning)
179+
@deprecated(
180+
reason="Cast the return value to float explicitly. " + _DEPRECATION_REASON,
181+
version=_DEPRECATION_VERSION,
182+
category=FutureWarning,
183+
)
180184
def getAsDouble(self, key):
181185
"""Return the value cast to a `float`.
182186
@@ -288,7 +292,7 @@ def names(self, topLevelOnly: bool = True):
288292
for k, v in self.items():
289293
names.add(k) # Always include the current level
290294
if isinstance(v, TaskMetadata):
291-
names.update({k + '.' + item for item in v.names(topLevelOnly=topLevelOnly)})
295+
names.update({k + "." + item for item in v.names(topLevelOnly=topLevelOnly)})
292296
return names
293297

294298
def paramNames(self, topLevelOnly):
@@ -318,14 +322,20 @@ def paramNames(self, topLevelOnly):
318322
paramNames.add(k)
319323
return paramNames
320324

321-
@deprecated(reason="Use standard assignment syntax. " + _DEPRECATION_REASON,
322-
version=_DEPRECATION_VERSION, category=FutureWarning)
325+
@deprecated(
326+
reason="Use standard assignment syntax. " + _DEPRECATION_REASON,
327+
version=_DEPRECATION_VERSION,
328+
category=FutureWarning,
329+
)
323330
def set(self, key, item):
324331
"""Set the value of the supplied key."""
325332
self.__setitem__(key, item)
326333

327-
@deprecated(reason="Use standard del dict syntax. " + _DEPRECATION_REASON,
328-
version=_DEPRECATION_VERSION, category=FutureWarning)
334+
@deprecated(
335+
reason="Use standard del dict syntax. " + _DEPRECATION_REASON,
336+
version=_DEPRECATION_VERSION,
337+
category=FutureWarning,
338+
)
329339
def remove(self, key):
330340
"""Remove the item without raising if absent."""
331341
try:
@@ -354,7 +364,7 @@ def _getKeys(key):
354364
Raised if the key is not a string.
355365
"""
356366
try:
357-
keys = key.split('.')
367+
keys = key.split(".")
358368
except Exception:
359369
raise KeyError(f"Invalid key '{key}': only string keys are allowed") from None
360370
return keys
@@ -518,8 +528,10 @@ def _validate_value(self, value):
518528
type0 = type(value[0])
519529
for i in value:
520530
if type(i) != type0:
521-
raise ValueError("Type mismatch in supplied list. TaskMetadata requires all"
522-
f" elements have same type but see {type(i)} and {type0}.")
531+
raise ValueError(
532+
"Type mismatch in supplied list. TaskMetadata requires all"
533+
f" elements have same type but see {type(i)} and {type0}."
534+
)
523535

524536
if type0 not in _ALLOWED_PRIMITIVE_TYPES:
525537
# Must check to see if we got numpy floats or something.
@@ -528,8 +540,10 @@ def _validate_value(self, value):
528540
elif isinstance(value[0], numbers.Real):
529541
type_cast = float
530542
else:
531-
raise ValueError(f"Supplied list has element of type '{type0}'. "
532-
"TaskMetadata can only accept primitive types in lists.")
543+
raise ValueError(
544+
f"Supplied list has element of type '{type0}'. "
545+
"TaskMetadata can only accept primitive types in lists."
546+
)
533547

534548
value = [type_cast(v) for v in value]
535549

0 commit comments

Comments
 (0)