pytractoviz 0.2.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytractoviz/__init__.py +11 -0
- pytractoviz/__main__.py +14 -0
- pytractoviz/_internal/__init__.py +0 -0
- pytractoviz/_internal/cli.py +59 -0
- pytractoviz/_internal/debug.py +110 -0
- pytractoviz/html.py +845 -0
- pytractoviz/py.typed +0 -0
- pytractoviz/utils.py +220 -0
- pytractoviz/viz.py +4272 -0
- pytractoviz-0.2.14.dist-info/METADATA +53 -0
- pytractoviz-0.2.14.dist-info/RECORD +14 -0
- pytractoviz-0.2.14.dist-info/WHEEL +4 -0
- pytractoviz-0.2.14.dist-info/entry_points.txt +5 -0
- pytractoviz-0.2.14.dist-info/licenses/LICENSE +21 -0
pytractoviz/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""pyTractoViz package.
|
|
2
|
+
|
|
3
|
+
Python tools for diffusion tractography visualization
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from pytractoviz._internal.cli import get_parser, main
|
|
9
|
+
from pytractoviz.html import create_quality_check_html
|
|
10
|
+
|
|
11
|
+
__all__: list[str] = ["create_quality_check_html", "get_parser", "main"]
|
pytractoviz/__main__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Entry-point module, in case you use `python -m pytractoviz`.
|
|
2
|
+
|
|
3
|
+
Why does this file exist, and why `__main__`? For more info, read:
|
|
4
|
+
|
|
5
|
+
- https://www.python.org/dev/peps/pep-0338/
|
|
6
|
+
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from pytractoviz._internal.cli import main
|
|
12
|
+
|
|
13
|
+
if __name__ == "__main__":
|
|
14
|
+
sys.exit(main(sys.argv[1:]))
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Why does this file exist, and why not put this in `__main__`?
|
|
2
|
+
#
|
|
3
|
+
# You might be tempted to import things from `__main__` later,
|
|
4
|
+
# but that will cause problems: the code will get executed twice:
|
|
5
|
+
#
|
|
6
|
+
# - When you run `python -m pytractoviz` python will execute
|
|
7
|
+
# `__main__.py` as a script. That means there won't be any
|
|
8
|
+
# `pytractoviz.__main__` in `sys.modules`.
|
|
9
|
+
# - When you import `__main__` it will get executed again (as a module) because
|
|
10
|
+
# there's no `pytractoviz.__main__` in `sys.modules`.
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import sys
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from pytractoviz._internal import debug
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _DebugInfo(argparse.Action):
|
|
22
|
+
def __init__(self, nargs: int | str | None = 0, **kwargs: Any) -> None:
|
|
23
|
+
super().__init__(nargs=nargs, **kwargs)
|
|
24
|
+
|
|
25
|
+
def __call__(self, *args: Any, **kwargs: Any) -> None: # noqa: ARG002
|
|
26
|
+
debug._print_debug_info()
|
|
27
|
+
sys.exit(0)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_parser() -> argparse.ArgumentParser:
|
|
31
|
+
"""Return the CLI argument parser.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
An argparse parser.
|
|
36
|
+
"""
|
|
37
|
+
parser = argparse.ArgumentParser(prog="pytractoviz")
|
|
38
|
+
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {debug._get_version()}")
|
|
39
|
+
parser.add_argument("--debug-info", action=_DebugInfo, help="Print debug information.")
|
|
40
|
+
return parser
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main(args: list[str] | None = None) -> int:
|
|
44
|
+
"""Run the main program.
|
|
45
|
+
|
|
46
|
+
This function is executed when you type `pytractoviz` or `python -m pytractoviz`.
|
|
47
|
+
|
|
48
|
+
Parameters
|
|
49
|
+
----------
|
|
50
|
+
args: Arguments passed from the command line.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
An exit code.
|
|
55
|
+
"""
|
|
56
|
+
parser = get_parser()
|
|
57
|
+
opts = parser.parse_args(args=args)
|
|
58
|
+
print(opts)
|
|
59
|
+
return 0
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
import sys
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from importlib import metadata
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class _Variable:
|
|
12
|
+
"""Dataclass describing an environment variable."""
|
|
13
|
+
|
|
14
|
+
name: str
|
|
15
|
+
"""Variable name."""
|
|
16
|
+
value: str
|
|
17
|
+
"""Variable value."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class _Package:
|
|
22
|
+
"""Dataclass describing a Python package."""
|
|
23
|
+
|
|
24
|
+
name: str
|
|
25
|
+
"""Package name."""
|
|
26
|
+
version: str
|
|
27
|
+
"""Package version."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class _Environment:
|
|
32
|
+
"""Dataclass to store environment information."""
|
|
33
|
+
|
|
34
|
+
interpreter_name: str
|
|
35
|
+
"""Python interpreter name."""
|
|
36
|
+
interpreter_version: str
|
|
37
|
+
"""Python interpreter version."""
|
|
38
|
+
interpreter_path: str
|
|
39
|
+
"""Path to Python executable."""
|
|
40
|
+
platform: str
|
|
41
|
+
"""Operating System."""
|
|
42
|
+
packages: list[_Package]
|
|
43
|
+
"""Installed packages."""
|
|
44
|
+
variables: list[_Variable]
|
|
45
|
+
"""Environment variables."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _interpreter_name_version() -> tuple[str, str]:
|
|
49
|
+
if hasattr(sys, "implementation"):
|
|
50
|
+
impl = sys.implementation.version
|
|
51
|
+
version = f"{impl.major}.{impl.minor}.{impl.micro}"
|
|
52
|
+
kind = impl.releaselevel
|
|
53
|
+
if kind != "final":
|
|
54
|
+
version += kind[0] + str(impl.serial)
|
|
55
|
+
return sys.implementation.name, version
|
|
56
|
+
return "", "0.0.0"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _get_version(dist: str = "pytractoviz") -> str:
|
|
60
|
+
"""Get version of the given distribution.
|
|
61
|
+
|
|
62
|
+
Parameters
|
|
63
|
+
----------
|
|
64
|
+
dist: A distribution name.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
A version number.
|
|
69
|
+
"""
|
|
70
|
+
try:
|
|
71
|
+
return metadata.version(dist)
|
|
72
|
+
except metadata.PackageNotFoundError:
|
|
73
|
+
return "0.0.0"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _get_debug_info() -> _Environment:
|
|
77
|
+
"""Get debug/environment information.
|
|
78
|
+
|
|
79
|
+
Returns
|
|
80
|
+
-------
|
|
81
|
+
Environment information.
|
|
82
|
+
"""
|
|
83
|
+
py_name, py_version = _interpreter_name_version()
|
|
84
|
+
packages = ["pytractoviz"]
|
|
85
|
+
variables = ["PYTHONPATH", *[var for var in os.environ if var.startswith("PYTRACTOVIZ")]]
|
|
86
|
+
return _Environment(
|
|
87
|
+
interpreter_name=py_name,
|
|
88
|
+
interpreter_version=py_version,
|
|
89
|
+
interpreter_path=sys.executable,
|
|
90
|
+
platform=platform.platform(),
|
|
91
|
+
variables=[_Variable(var, val) for var in variables if (val := os.getenv(var))], # ty: ignore[invalid-argument-type]
|
|
92
|
+
packages=[_Package(pkg, _get_version(pkg)) for pkg in packages],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _print_debug_info() -> None:
|
|
97
|
+
"""Print debug/environment information."""
|
|
98
|
+
info = _get_debug_info()
|
|
99
|
+
print(f"- __System__: {info.platform}")
|
|
100
|
+
print(f"- __Python__: {info.interpreter_name} {info.interpreter_version} ({info.interpreter_path})")
|
|
101
|
+
print("- __Environment variables__:")
|
|
102
|
+
for var in info.variables:
|
|
103
|
+
print(f" - `{var.name}`: `{var.value}`")
|
|
104
|
+
print("- __Installed packages__:")
|
|
105
|
+
for pkg in info.packages:
|
|
106
|
+
print(f" - `{pkg.name}` v{pkg.version}")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
_print_debug_info()
|