|
18 | 18 | from ..utils import listify |
19 | 19 | from .writing import build_path, write_to_file |
20 | 20 | from ..config import get_option |
21 | | -from .utils import BIDSMetadata |
| 21 | +from .utils import BIDSMetadata, PaddedInt |
22 | 22 |
|
23 | 23 | Base = declarative_base() |
24 | 24 |
|
@@ -71,6 +71,9 @@ def _sanitize_init_args(self, kwargs): |
71 | 71 |
|
72 | 72 | return kwargs |
73 | 73 |
|
| 74 | + def __repr__(self): |
| 75 | + return f"<LayoutInfo {self.root}>" |
| 76 | + |
74 | 77 |
|
75 | 78 | class Config(Base): |
76 | 79 | """Container for BIDS configuration information. |
@@ -162,6 +165,9 @@ def load(self, config, session=None): |
162 | 165 |
|
163 | 166 | return Config(session=session, **config) |
164 | 167 |
|
| 168 | + def __repr__(self): |
| 169 | + return f"<Config {self.name}>" |
| 170 | + |
165 | 171 |
|
166 | 172 | class BIDSFile(Base): |
167 | 173 | """Represents a single file or directory in a BIDS dataset. |
@@ -531,12 +537,18 @@ def __init__(self, name, pattern=None, mandatory=False, directory=None, |
531 | 537 |
|
532 | 538 | self._init_on_load() |
533 | 539 |
|
| 540 | + def __repr__(self): |
| 541 | + return f"<Entity {self.name} (pattern={self.pattern}, dtype={self.dtype})>" |
| 542 | + |
534 | 543 | @reconstructor |
535 | 544 | def _init_on_load(self): |
536 | 545 | if self._dtype not in ('str', 'float', 'int', 'bool'): |
537 | 546 | raise ValueError("Invalid dtype '{}'. Must be one of 'int', " |
538 | 547 | "'float', 'bool', or 'str'.".format(self._dtype)) |
539 | | - self.dtype = eval(self._dtype) |
| 548 | + if self._dtype == "int": |
| 549 | + self.dtype = PaddedInt |
| 550 | + else: |
| 551 | + self.dtype = eval(self._dtype) |
540 | 552 | self.regex = re.compile(self.pattern) if self.pattern is not None else None |
541 | 553 |
|
542 | 554 | def __iter__(self): |
@@ -684,6 +696,9 @@ def _init_on_load(self): |
684 | 696 | if self._dtype == 'json': |
685 | 697 | self.value = json.loads(self._value) |
686 | 698 | self.dtype = 'json' |
| 699 | + elif self._dtype == 'int': |
| 700 | + self.dtype = PaddedInt |
| 701 | + self.value = self.dtype(self._value) |
687 | 702 | else: |
688 | 703 | self.dtype = eval(self._dtype) |
689 | 704 | self.value = self.dtype(self._value) |
|
0 commit comments