Skip to content

Commit 1f2cf15

Browse files
committed
Split pub citation and version citation functions
This commit splits the former ij.py.cite() method into cite_publication() and cite_versions() which produce the PyImageJ citation string and the environment packages seperately.
1 parent 9013e7b commit 1f2cf15

File tree

1 file changed

+64
-23
lines changed

1 file changed

+64
-23
lines changed

src/imagej/__init__.py

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import scyjava as sj
4949
import xarray as xr
5050
from jpype import JImplementationFor, setupGuiEnvironment
51+
from jpype import __version__ as _jpype_version
5152
from scyjava.config import find_jars
5253

5354
import imagej.convert as convert
@@ -164,43 +165,83 @@ def argstring(self, args, ij1_style=True):
164165
formatted_args.append(arg)
165166
return " ".join(formatted_args)
166167

167-
def cite(self, show: bool = True) -> str:
168-
"""Generate a citation string and package version numbers.
168+
def cite_publication(self, show: bool = True) -> str:
169+
"""Generate a citation string.
169170
170-
Generate the PyImageJ citation/reference string and fetch
171-
the environments Python and Java versions.
171+
Generate the PyImageJ citation/reference string.
172172
173173
:param show: Print the PyImageJ citation if True, if False
174174
the PyImageJ citation string is returned instead.
175-
:return: A citation and package version numbers
175+
:return: The PyImageJ citation.
176176
"""
177177
# set PyImageJ reference sub strings
178-
authors = "Rueden, C.T., Hiner, M.C., Evans, E.L. et al."
178+
header = "=====PyImageJ Citation====="
179+
authors = "\nRueden, C.T., Hiner, M.C., Evans, E.L. et al."
179180
pub_title = "\nPyImageJ: A library for integrating ImageJ and Python."
180181
journal = "\nNat Methods 19, 1326–1327 (2022)."
181182
doi_link = "\nhttps://doi.org/10.1038/s41592-022-01655-4"
182-
divider = "\n-----------------------"
183-
# collect the current Python version
184-
py_vi = sys.version_info
185-
python_version = f"\nPython version: {py_vi.major}.{py_vi.minor}.{py_vi.micro}"
186-
# collect the current Java version
187-
j_vi = sj.jvm_version()
188-
java_version = f"\nJava version: {j_vi[0]}.{j_vi[1]}.{j_vi[2]}"
189-
# construct final string
190-
citation = (
191-
authors
192-
+ pub_title
193-
+ journal
194-
+ doi_link
195-
+ divider
196-
+ python_version
197-
+ java_version
198-
)
183+
184+
# construct output citation string
185+
citation = header + authors + pub_title + journal + doi_link
199186
if show:
200187
print(citation)
201188
else:
202189
return citation
203190

191+
def cite_versions(self, show: bool = True) -> str:
192+
"""Fetch the current environment's package versions.
193+
194+
Fetch and construct the current environment's package versions.
195+
This function returns the versions for:
196+
- Python
197+
- Java
198+
- pyimagej
199+
- scyjava
200+
- imglyb
201+
- jgo
202+
- jpype
203+
204+
:param show: Print the PyImageJ citation if True, if False
205+
the PyImageJ citation string is returned instead.
206+
:param show: Print the version numbers if True, if False
207+
the environment version number string is returned instead.
208+
:return: The current PyImageJ instance's package versions.
209+
"""
210+
# collect the current isntance's package versions
211+
py_ver = sys.version_info
212+
java_ver = sj.jvm_version()
213+
pyimagej_ver = __version__
214+
scyjava_ver = sj.get_version("scyjava")
215+
imglyb_ver = sj.get_version("imglyb")
216+
jpype_ver = _jpype_version
217+
jgo_ver = sj.get_version("jgo")
218+
219+
# construct version strings
220+
header = "=====Environment package versions====="
221+
python_ver_str = f"\nPython: {py_ver.major}.{py_ver.minor}.{py_ver.micro}"
222+
java_ver_str = f"\nJava: {java_ver[0]}.{java_ver[1]}.{java_ver[2]}"
223+
pyimagej_ver_str = f"\npyimagej: {pyimagej_ver}"
224+
scyjava_ver_str = f"\nscyjava: {scyjava_ver}"
225+
imglyb_ver_str = f"\nimglyb: {imglyb_ver}"
226+
jgo_ver_str = f"\njgo: {jgo_ver}"
227+
jpype_ver_str = f"\njpype: {jpype_ver}"
228+
229+
# construct output version string
230+
versions = (
231+
header
232+
+ python_ver_str
233+
+ java_ver_str
234+
+ pyimagej_ver_str
235+
+ scyjava_ver_str
236+
+ imglyb_ver_str
237+
+ jgo_ver_str
238+
+ jpype_ver_str
239+
)
240+
if show:
241+
print(versions)
242+
else:
243+
return versions
244+
204245
def dtype(self, image_or_type):
205246
"""Get the dtype of the input image as a numpy.dtype object.
206247

0 commit comments

Comments
 (0)