Skip to content

Commit 3b79435

Browse files
committed
update how metadata import works
1 parent 505fe26 commit 3b79435

File tree

8 files changed

+45
-34
lines changed

8 files changed

+45
-34
lines changed

pypet2bids/poetry.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pypet2bids/pypet2bids/helper_functions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
import importlib
4343

4444
try:
45-
import metadata
45+
from importlib import metadata
4646
except ImportError:
47-
from pypet2bids import metadata
48-
49-
parent_dir = pathlib.Path(__file__).parent.resolve()
50-
project_dir = parent_dir.parent.parent
51-
if "PET2BIDS" not in project_dir.parts:
52-
project_dir = parent_dir
47+
import importlib_metadata as metadata
5348

49+
try:
50+
import pet_metadata as metadata
51+
except ImportError:
52+
import pypet2bids.pet_metadata as metadata
5453

5554
# load bids schema
5655
schema = metadata.schema
@@ -287,14 +286,13 @@ def get_version():
287286
"""
288287
# this scripts directory path
289288
scripts_dir = pathlib.Path(os.path.dirname(__file__))
290-
291-
# first try using importlib.metadata.version to determine version
292-
293-
version = importlib.metadata.version("pypet2bids")
289+
try:
290+
version = metadata.version("pypet2bids")
291+
except Exception:
292+
version = None
294293

295294
if not version:
296295
tomlfile = {}
297-
298296
try:
299297
# if this is bundled as a package look next to this file for the pyproject.toml
300298
toml_path = os.path.join(scripts_dir, "pyproject.toml")

pypet2bids/pypet2bids/is_pet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
import helper_functions
1616
import ecat
1717
import dcm2niix4pet
18-
import metadata
18+
import pet_metadata
1919
except ModuleNotFoundError:
2020
import pypet2bids.helper_functions as helper_functions
2121
import pypet2bids.ecat as ecat
2222
import pypet2bids.dcm2niix4pet as dcm2niix4pet
23-
import pypet2bids.metadata
23+
import pypet2bids.pet_metadata as pet_metadata
2424

2525

2626
def spread_sheet_check_for_pet(sourcefile: Union[str, Path], **kwargs):
2727
# load data from spreadsheet
2828
data = helper_functions.open_meta_data(sourcefile)
2929

3030
try:
31-
pet_field_requirements = metadata.PET_metadata
31+
pet_field_requirements = pet_metadata.PET_metadata
3232
except:
3333
pet_field_requirements = {}
3434

pypet2bids/pypet2bids/metadata_spreadsheet_example_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
try:
77
import helper_functions
8-
import metadata
8+
import pet_metadata
99
except ModuleNotFoundError:
1010
import pypet2bids.helper_functions as helper_functions
11-
import pypet2bids.metadata as metadata
11+
import pypet2bids.pet_metadata as pet_metadata
1212

1313

1414
parent_dir = pathlib.Path(__file__).parent.resolve()

pypet2bids/pypet2bids/multiple_spreadsheets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
try:
1111
import pypet2bids.helper_functions as helper_functions
12-
import pypet2bids.metadata as metadata
12+
import pypet2bids.pet_metadata as pet_metadata
1313
except ModuleNotFoundError:
1414
import helper_functions
15-
import metadata
15+
import pet_metadata
1616

1717

1818
def read_multi_subject_spreadsheets(
@@ -43,7 +43,7 @@ def read_multi_subject_spreadsheets(
4343
4444
"""
4545

46-
required_fields = metadata.PET_metadata
46+
required_fields = pet_metadata.PET_metadata
4747

4848
if (
4949
general_metadata_spreadsheet.is_file()

pypet2bids/pypet2bids/metadata.py renamed to pypet2bids/pypet2bids/pet_metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
from types import SimpleNamespace
3+
14
blood_metadata = {
25
"mandatory": [
36
"PlasmaAvail",
@@ -10708,3 +10711,13 @@
1070810711
"whole_blood_radioactivity",
1070910712
],
1071010713
}
10714+
10715+
sys.modules[__name__] = SimpleNamespace(
10716+
blood_metadata=blood_metadata,
10717+
dicom2bids=dicom2bids,
10718+
PET_reconstruction_filters=PET_reconstruction_filters,
10719+
definitions=definitions,
10720+
PET_reconstruction_methods=PET_reconstruction_methods,
10721+
schema=schema,
10722+
PET_metadata=PET_metadata,
10723+
)

pypet2bids/pypet2bids/single_spreadsheet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
try:
99
import helper_functions
10-
import metadata
10+
import pet_metadata as metadata
1111
except ModuleNotFoundError:
1212
import pypet2bids.helper_functions as helper_functions
13-
import pypet2bids.metadata as metadata
13+
import pypet2bids.pet_metadata as metadata
1414

1515
# from pypet2bids.helper_functions import single_spreadsheet_reader, \
1616
# collect_bids_part, open_meta_data, load_pet_bids_requirements_json, ParseKwargs

pypet2bids/pypet2bids/update_json_pet_file.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
try:
1515
import helper_functions
1616
import is_pet
17-
import metadata
17+
import pet_metadata as metadata
1818
except ModuleNotFoundError:
1919
import pypet2bids.helper_functions as helper_functions
2020
import pypet2bids.is_pet as is_pet
21-
import pypet2bids.metadata as metadata
21+
import pypet2bids.pet_metadata as metadata
2222

2323
# import logging
2424
logger = helper_functions.logger("pypet2bids")
@@ -51,7 +51,7 @@ def check_json(
5151
:type spreadsheet_metadata:
5252
:param path_to_json: path to a json file e.g. a BIDS sidecar file created after running dcm2niix
5353
:param items_to_check: a dictionary with items to check for within that json. If None is supplied defaults to the
54-
PET_metadata imported from metadata.PET_metadata
54+
PET_metadata imported from pet_metadata.PET_metadata
5555
:param silent: Raises warnings or errors to stdout if this flag is set to True
5656
:return: dictionary of items existence and value state, if key is True/False there exists/(does not exist) a
5757
corresponding entry in the json the same can be said of value
@@ -181,7 +181,7 @@ def update_json_with_dicom_value(
181181
# purely to clean up the generated read the docs page from sphinx, otherwise the entire json appears in the
182182
# read the docs page.
183183
if dicom2bids_json is None:
184-
dicom2bids_json = metadata_dictionaries["dicom2bids.json"]
184+
dicom2bids_json = metadata_dictionaries["dicom2bids"]
185185

186186
# Units gets written as Unit in older versions of dcm2niix here we check for missing Units and present Unit entity
187187
units = missing_values.get("Units", None)

0 commit comments

Comments
 (0)