Skip to content

Commit befbb7b

Browse files
committed
update version seeking
1 parent ad631f1 commit befbb7b

File tree

3 files changed

+240
-265
lines changed

3 files changed

+240
-265
lines changed

petdeface/petdeface.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from niworkflows.utils.misc import check_valid_fs_license
2525

2626
from petutils.petutils import collect_anat_and_pet
27+
from importlib.metadata import version
2728

2829

2930
try:
@@ -42,43 +43,15 @@
4243
pathlib.Path(__file__).parent.parent.absolute(),
4344
]
4445

45-
__version__ = "unable to locate version number in pyproject.toml"
46+
__version__ = "unable to locate version number"
4647
# we use the default version at the time of this writing, but the most current version
4748
# can be found in the pyproject.toml file under the [tool.bids] section
4849
__bids_version__ = "1.8.0"
4950

5051

51-
# search for toml file
52-
for place in places_to_look:
53-
for root, folders, files in os.walk(place):
54-
for file in files:
55-
if file.endswith("pyproject.toml") and "petdeface" in os.path.join(
56-
root, file
57-
):
58-
toml_file = os.path.join(root, file)
59-
60-
with open(toml_file, "r") as f:
61-
for line in f.readlines():
62-
if (
63-
"version" in line
64-
and len(line.split("=")) > 1
65-
and "bids_version" not in line
66-
):
67-
__version__ = line.split("=")[1].strip().replace('"', "")
68-
if "bids_version" in line and len(line.split("=")) > 1:
69-
__bids_version__ = (
70-
line.split("=")[1].strip().replace('"', "")
71-
)
72-
# if the version number is found and is formatted with major.minor.patch formating we can break
73-
# we check the version with a regex expression to see if all of the parts are there
74-
if re.match(r"\d+\.\d+\.\d+", __version__):
75-
break
76-
77-
if __version__ != "unable to locate version number in pyproject.toml":
78-
# we try to load the version using import lib
79-
__version__ = importlib.metadata.version("petdeface")
80-
if re.match(r"\d+\.\d+\.\d+", __version__):
81-
break
52+
if __version__ == "unable to locate version number":
53+
# we try to load the version using import lib
54+
__version__ = version(__package__)
8255

8356

8457
def locate_freesurfer_license():
@@ -257,7 +230,9 @@ def deface(args: Union[dict, argparse.Namespace]) -> None:
257230
subject.replace("sub-", "") for subject in args.participant_label_exclude
258231
]
259232
subjects = [
260-
subject for subject in subjects if subject not in args.participant_label_exclude
233+
subject
234+
for subject in subjects
235+
if subject not in args.participant_label_exclude
261236
]
262237

263238
print(f"Subjects remaining in the defacing workflow: {subjects}")

0 commit comments

Comments
 (0)