Skip to content

Commit f7c552d

Browse files
authored
Merge branch 'main' into fix-missing-schema-json-file
2 parents 456d01c + 35ed478 commit f7c552d

File tree

10 files changed

+10901
-188
lines changed

10 files changed

+10901
-188
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ add:
2626

2727
# copies metadata to path included in pypet2bids project to enable packaging of those files w/ poetry
2828
buildpackage:
29-
@cp -R metadata/ pypet2bids/pypet2bids/metadata
3029
@cp pypet2bids/pyproject.toml pypet2bids/pypet2bids/pyproject.toml
3130
@rm -rf pypet2bids/dist
3231
@cd pypet2bids && poetry lock && poetry build

pypet2bids/poetry.lock

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

pypet2bids/pypet2bids/dcm2niix4pet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def run_dcm2niix(self):
588588
created_path,
589589
check_for_missing,
590590
dicom_header,
591-
dicom2bids_json=metadata_dictionaries["dicom2bids.json"],
591+
dicom2bids_json=metadata_dictionaries["dicom2bids"],
592592
**self.additional_arguments,
593593
)
594594

pypet2bids/pypet2bids/helper_functions.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
import argparse
4040
from typing import Union
4141
from platform import system
42+
import importlib
43+
44+
try:
45+
import metadata
46+
except ImportError:
47+
from pypet2bids import metadata
4248

4349
parent_dir = pathlib.Path(__file__).parent.resolve()
4450
project_dir = parent_dir.parent.parent
@@ -55,14 +61,12 @@
5561
)
5662

5763
# load bids schema
58-
bids_schema_path = os.path.join(metadata_dir, "schema.json")
59-
schema = json.load(open(bids_schema_path, "r"))
64+
schema = metadata.schema
6065

6166
# putting these paths here as they are reused in dcm2niix4pet.py, update_json_pet_file.py, and ecat.py
6267
module_folder = Path(__file__).parent.resolve()
6368
python_folder = module_folder.parent
6469
pet2bids_folder = python_folder.parent
65-
metadata_folder = os.path.join(pet2bids_folder, "metadata")
6670

6771
loggers = {}
6872

@@ -316,27 +320,37 @@ def load_vars_from_config(
316320

317321
def get_version():
318322
"""
319-
Gets the version of this software from the toml file
320-
:return: version number from pyproject.toml
323+
Gets the version of this software
324+
:return: version number
321325
"""
322326
# this scripts directory path
323327
scripts_dir = pathlib.Path(os.path.dirname(__file__))
324328

325-
try:
326-
# if this is bundled as a package look next to this file for the pyproject.toml
327-
toml_path = os.path.join(scripts_dir, "pyproject.toml")
328-
with open(toml_path, "r") as infile:
329-
tomlfile = toml.load(infile)
330-
except FileNotFoundError:
331-
# when in development the toml file with the version is 2 directories above (e.g. where it should actually live)
332-
toml_dir = scripts_dir.parent
333-
toml_path = os.path.join(toml_dir, "pyproject.toml")
334-
with open(toml_path, "r") as infile:
335-
tomlfile = toml.load(infile)
336-
337-
attrs = tomlfile.get("tool", {})
338-
poetry = attrs.get("poetry", {})
339-
version = poetry.get("version", "")
329+
# first try using importlib.metadata.version to determine version
330+
331+
version = importlib.metadata.version("pypet2bids")
332+
333+
if not version:
334+
tomlfile = {}
335+
336+
try:
337+
# if this is bundled as a package look next to this file for the pyproject.toml
338+
toml_path = os.path.join(scripts_dir, "pyproject.toml")
339+
with open(toml_path, "r") as infile:
340+
tomlfile = toml.load(infile)
341+
except FileNotFoundError:
342+
# when in development the toml file with the version is 2 directories above (e.g. where it should actually live)
343+
try:
344+
toml_dir = scripts_dir.parent
345+
toml_path = os.path.join(toml_dir, "pyproject.toml")
346+
with open(toml_path, "r") as infile:
347+
tomlfile = toml.load(infile)
348+
except FileNotFoundError:
349+
pass
350+
351+
attrs = tomlfile.get("tool", {})
352+
poetry = attrs.get("poetry", {})
353+
version = poetry.get("version", "")
340354

341355
return version
342356

@@ -820,9 +834,7 @@ def get_recon_method(ReconstructionMethodString: str) -> dict:
820834
dimension = re.search(search_criteria, ReconMethodName)[0]
821835

822836
# doing some more manipulation of the recon method name to expand it from not so helpful acronyms
823-
possible_names = load_pet_bids_requirements_json(pet_reconstruction_metadata_json)[
824-
"reconstruction_names"
825-
]
837+
possible_names = metadata.PET_reconstruction_methods.get("reconstruction_names", [])
826838

827839
# we want to sort the possible names by longest first that we don't break up an acronym prematurely
828840
sorted_df = pandas.DataFrame(possible_names).sort_values(

0 commit comments

Comments
 (0)