|
39 | 39 | import argparse |
40 | 40 | from typing import Union |
41 | 41 | from platform import system |
| 42 | +import importlib |
| 43 | + |
| 44 | +try: |
| 45 | + import metadata |
| 46 | +except ImportError: |
| 47 | + from pypet2bids import metadata |
42 | 48 |
|
43 | 49 | parent_dir = pathlib.Path(__file__).parent.resolve() |
44 | 50 | project_dir = parent_dir.parent.parent |
|
55 | 61 | ) |
56 | 62 |
|
57 | 63 | # 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 |
60 | 65 |
|
61 | 66 | # putting these paths here as they are reused in dcm2niix4pet.py, update_json_pet_file.py, and ecat.py |
62 | 67 | module_folder = Path(__file__).parent.resolve() |
63 | 68 | python_folder = module_folder.parent |
64 | 69 | pet2bids_folder = python_folder.parent |
65 | | -metadata_folder = os.path.join(pet2bids_folder, "metadata") |
66 | 70 |
|
67 | 71 | loggers = {} |
68 | 72 |
|
@@ -316,27 +320,37 @@ def load_vars_from_config( |
316 | 320 |
|
317 | 321 | def get_version(): |
318 | 322 | """ |
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 |
321 | 325 | """ |
322 | 326 | # this scripts directory path |
323 | 327 | scripts_dir = pathlib.Path(os.path.dirname(__file__)) |
324 | 328 |
|
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", "") |
340 | 354 |
|
341 | 355 | return version |
342 | 356 |
|
@@ -820,9 +834,7 @@ def get_recon_method(ReconstructionMethodString: str) -> dict: |
820 | 834 | dimension = re.search(search_criteria, ReconMethodName)[0] |
821 | 835 |
|
822 | 836 | # 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", []) |
826 | 838 |
|
827 | 839 | # we want to sort the possible names by longest first that we don't break up an acronym prematurely |
828 | 840 | sorted_df = pandas.DataFrame(possible_names).sort_values( |
|
0 commit comments