Skip to content

Commit

Permalink
Simplify initialization case logic
Browse files Browse the repository at this point in the history
And fix a bug where the endpoint list was not restored in some cases.
  • Loading branch information
ctrueden committed Jul 27, 2023
1 parent e4e2bf2 commit d7a0ec5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/imagej/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ def _create_jvm(
sj.config.endpoints.append("net.imagej:imagej")

elif isinstance(ij_dir_or_version_or_endpoint, list):
# Assume that this is a list of Maven endpoints.
# Looks like a list of Maven endpoints.
_logger.debug(
"List of Maven coordinates given: %s", ij_dir_or_version_or_endpoint
)
Expand All @@ -1358,7 +1358,7 @@ def _create_jvm(
sj.config.endpoints.extend(ij_dir_or_version_or_endpoint)

elif os.path.isdir(os.path.expanduser(ij_dir_or_version_or_endpoint)):
# Assume path to local ImageJ2 installation.
# Looks like a path to a local ImageJ2 installation.
path = os.path.abspath(os.path.expanduser(ij_dir_or_version_or_endpoint))
_logger.debug("Local path to ImageJ2 installation given: %s", path)
add_legacy = False
Expand All @@ -1385,7 +1385,7 @@ def _create_jvm(
init_failed = True

elif ":" in ij_dir_or_version_or_endpoint:
# Assume endpoint of an artifact.
# Looks like an artifact endpoint.
_logger.debug("Maven coordinate given: %s", ij_dir_or_version_or_endpoint)
# Strip whitespace and split concatenated endpoints.
endpoints = re.sub("\\s*", "", ij_dir_or_version_or_endpoint).split("+")
Expand All @@ -1395,16 +1395,15 @@ def _create_jvm(
add_legacy = False
sj.config.endpoints.extend(endpoints)

elif re.match("\\d+\\.\\d+\\.\\d+", ij_dir_or_version_or_endpoint):
# Looks like an x.y.z-style version of net.imagej:imagej.
_logger.debug("ImageJ2 version given: %s", ij_dir_or_version_or_endpoint)
sj.config.endpoints.append("net.imagej:imagej:" + ij_dir_or_version_or_endpoint)

else:
# Assume string is an x.y.z-style version of net.imagej:imagej.
version = ij_dir_or_version_or_endpoint
if not re.match("\\d+\\.\\d+\\.\\d+", version):
_logger.error("Invalid initialization string: %s", version)
init_failed = True
return False
else:
_logger.debug("ImageJ2 version given: %s", version)
sj.config.endpoints.append("net.imagej:imagej:" + version)
# String is in an unknown form.
_logger.error("Invalid initialization string: %s", ij_dir_or_version_or_endpoint)
init_failed = True

if init_failed:
# Restore any pre-existing endpoints to allow for re-initialization.
Expand Down

0 comments on commit d7a0ec5

Please sign in to comment.