Skip to content

Commit

Permalink
Fixed circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
Beliy Nikita committed Sep 12, 2024
1 parent 6c3104d commit bff98eb
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- bidsmap/bidsmap: For `__unknown__` and `__ignore__` modalities, the model will be fixed to `__unknown__`
- mapper: If suffix is not defined, an error will be shown, and no further vqalidations will be performed on that file
- BidsTable: Updated `lineterminator` parameter, making it compatible with modern (>1.4) Pandas, and Pythons up to 3.12
- Modules: Base module class selector has been moved into tools, new modalities are no longer decalred in `selector.py`


## [1.7.1] - 2024-09-05
Expand Down
4 changes: 2 additions & 2 deletions bidsme/Modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from bidsme.bidsMeta import BidsSession
from bidsme.schema.BIDSschema import BIDSschema

from bidsme.bidsmap import Run
# from bidsme.bidsmap import Run


from ._constants import ignoremodality, unknownmodality
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def bidsify(self, bidsfolder: str) -> None:
self.rec_BIDSfields.DumpDefinitions(scans_json)
return os.path.join(outdir, bidsname + ext)

def setLabels(self, run: Run = None):
def setLabels(self, run=None):
"""
Set the BIDS tags (labels) according to given run
Expand Down
3 changes: 2 additions & 1 deletion bidsme/bidsify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@

from bidsme.tools import paths
from bidsme.tools import tools
from bidsme.tools import selector
from bidsme.tools import type_selector
from bidsme.bidsmap import Bidsmap
from bidsme.bidsMeta import BidsSession
from bidsme.bidsMeta import BidsTable

logger = logging.getLogger(__name__)
selector = type_selector()


def coin(destination: str,
Expand Down
3 changes: 2 additions & 1 deletion bidsme/bidsmap/_bidsmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@

from bidsme.tools import info
from bidsme.tools.yaml import yaml
from bidsme.tools import selector
from bidsme.tools import type_selector

from ._run import Run
from bidsme import Modules

logger = logging.getLogger(__name__)
selector = type_selector()


class Bidsmap(object):
Expand Down
3 changes: 2 additions & 1 deletion bidsme/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from bidsme import plugins
from bidsme import Modules

from bidsme.tools import selector
from bidsme.tools import type_selector
from bidsme.tools import paths
from bidsme.tools import info
from bidsme.tools import tools
Expand All @@ -45,6 +45,7 @@
from .Modules._constants import ignoremodality, unknownmodality

logger = logging.getLogger(__name__)
selector = type_selector()


def createmap(destination,
Expand Down
4 changes: 2 additions & 2 deletions bidsme/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

from bidsme import exceptions
from bidsme import plugins
from bidsme import Modules

from bidsme.tools import selector
from bidsme.tools import type_selector
from bidsme.tools import tools
from bidsme.tools import paths

Expand All @@ -40,6 +39,7 @@


logger = logging.getLogger(__name__)
selector = type_selector()


def sortsession(outfolder: str,
Expand Down
3 changes: 2 additions & 1 deletion bidsme/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from bidsme import plugins
from bidsme import Modules

from bidsme.tools import selector
from bidsme.tools import type_selector
from bidsme.tools import paths
from bidsme.tools import tools

Expand All @@ -41,6 +41,7 @@
from bidsme.bidsMeta import BidsTable

logger = logging.getLogger(__name__)
selector = type_selector()


def coin(destination: str,
Expand Down
19 changes: 17 additions & 2 deletions bidsme/tools/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
##############################################################################
from types import ModuleType

from .. import Modules
from bidsme import Modules


class type_selector(object):
__slots__ = ["types_list"]

def __init__(self):

"""
Class guessing the module and file format based on
path or folder
"""
self.types_list = {}
for i in dir(Modules):
obj = getattr(Modules, i)
Expand All @@ -52,6 +55,10 @@ def select(self, folder: str, module: str = ""):
module: str
restrict type of class
"""
if module and module not in self.types_list:
raise KeyError("Module {} is not one of supported modules {}"
.format(module, self.types_list.keys()))

if module == "":
for m in self.types_list:
for cls in self.types_list[m]:
Expand All @@ -74,6 +81,10 @@ def selectFile(self, file: str, module: str = ""):
module: str
restrict type of class
"""
if module and module not in self.types_list:
raise KeyError("Module {} is not one of supported modules {}"
.format(module, self.types_list.keys()))

if module == "":
for m in self.types_list:
for cls in self.types_list[m]:
Expand All @@ -96,6 +107,10 @@ def selectByName(self, name: str, module: str = ""):
module: str
restrict type of class
"""
if module and module not in self.types_list:
raise KeyError("Module {} is not one of supported modules {}"
.format(module, self.types_list.keys()))

if module == "":
for m in self.types_list:
for cls in self.types_list[m]:
Expand Down

0 comments on commit bff98eb

Please sign in to comment.