Skip to content

Commit

Permalink
bump version, merge pull request #32 from AMYPAD/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored May 30, 2023
2 parents feedd52 + 6f3d76e commit 7de60cb
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 116 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
fetch-depth: 0
- name: Run setup-python
run: setup-python -p${{ matrix.python }}
- run: pip install -U .[dev,nii,cuda,web,mbeautify]
- run: pip install -U .[dev,nii,cuda,web,mbeautify] 'setuptools<66' # ignore matlab engine PEP440 non-compliance https://github.com/pypa/setuptools/issues/3772
- run: pytest --durations-min=1
- uses: codecov/codecov-action@v3
- name: Post Run setup-python
Expand All @@ -85,8 +85,7 @@ jobs:
- id: dist
uses: casperdcl/deploy-pypi@v2
with:
requirements: twine setuptools wheel setuptools_scm[toml]
build: true
pip: true
gpg_key: ${{ secrets.GPG_KEY }}
password: ${{ secrets.PYPI_TOKEN }}
upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ repos:
- flake8-comprehensions
- flake8-debugger
- flake8-isort
- flake8-pyproject
- flake8-string-format
- repo: https://github.com/google/yapf
rev: v0.32.0
rev: v0.33.0
hooks:
- id: yapf
args: [-i]
Expand Down
2 changes: 1 addition & 1 deletion LICENCE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2020 AMYPAD
Copyright 2020-23 AMYPAD

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this project except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion miutil/cuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main(*args, **kwargs):
noargs = False
if noargs:
for dev_id in devices:
print("Device {:2d}:{}:compute capability:{:d}.{:d}".format(
print("Device {:2d}:{}:compute capability:{:d}.{:d}".format( # NOQA: P101
dev_id, name(dev_id), *compute_capability(dev_id)))


Expand Down
4 changes: 2 additions & 2 deletions miutil/imio/nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def nii_gzip(imfile, outpath=""):

def getnii(fim, nan_replace=None, output='image'):
"""
Get PET image from NIfTI file.
Get image from NIfTI file.
Arguments:
fim: input file name for the nifty image
fim: input file name for the NIfTI image
nan_replace: the value to be used for replacing the NaNs in the image.
by default no change (None).
output: option for choosing output: image, affine matrix or
Expand Down
33 changes: 23 additions & 10 deletions miutil/mlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@ def get_engine(name=None):
install-matlab-engine-api-for-python-in-nondefault-locations.html
It's likely you need to do:
cd "{matlabroot}\\extern\\engines\\python"
{exe} setup.py build --build-base="BUILDDIR" install
cd "{setup_dir}"
{exe} -m pip install 'setuptools<66'
{exe} setup.py build --build-base="BUILDDIR" install --prefix="{pre}"
- Fill in any temporary directory name for BUILDDIR
(e.g. /tmp/builddir).
- If installation fails due to write permissions, try appending `--user`
to the above command.
Alternatively, use `get_runtime()` instead of `get_engine()`.
""").format(matlabroot=matlabroot(default="matlabroot"), exe=sys.executable))
""").format(
setup_dir=path.join(matlabroot(default="matlabroot"), "extern", "engines",
"python"), exe=sys.executable, pre=sys.prefix))
log.debug("Starting MATLAB")
try:
eng = engine.connect_matlab(name=name or getenv("SPM12_MATLAB_ENGINE", None))
Expand Down Expand Up @@ -126,7 +127,8 @@ def matlabroot(default=None):

def _install_engine():
src = path.join(matlabroot(), "extern", "engines", "python")
with open(path.join(src, "setup.py")) as fd: # check version support
with open(path.join(src, "setup.py")) as fd:
# check version support
supported = literal_eval(
re.search(r"supported_version.*?=\s*(.*?)$", fd.read(), flags=re.M).group(1))
if ".".join(map(str, sys.version_info[:2])) not in map(str, supported):
Expand All @@ -138,10 +140,21 @@ def _install_engine():
with tmpdir() as td:
cmd = [sys.executable, "setup.py", "build", "--build-base", td, "install"]
try:
return check_output_u8(cmd, cwd=src)
return check_output_u8(cmd + ["--prefix", sys.prefix], cwd=src)
except CalledProcessError:
log.warning("Normal install failed. Attempting `--user` install.")
return check_output_u8(cmd + ["--user"], cwd=src)
try:
return check_output_u8(cmd + ["--user"], cwd=src)
except CalledProcessError:
ml_ver = src.split(path.sep)[-4].lstrip("R")
if ml_ver < '2020b':
raise
eng_ver = {
'2020b': '9.9', '2021a': '9.10', '2021b': '9.11', '2022a': '9.12',
'2022b': '9.13', '2023a': '9.14'}
pin = f"=={eng_ver[ml_ver]}.*" if ml_ver in eng_ver else ""
return check_output_u8([
sys.executable, "-m", "pip", "install", "matlabengine" + pin])


@lru_cache()
Expand Down Expand Up @@ -176,8 +189,8 @@ def get_runtime(cache="~/.mcr", version=99):
raise NotImplementedError(
dedent("""\
Don't yet know how to handle
{}
for {!r}.
{0}
for {1!r}.
""").format(fspath(install), system()))
else:
raise IndexError(version)
Expand Down
6 changes: 3 additions & 3 deletions miutil/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, vol, view='t', fig=None, titles=None, order=0, sharexy=None,
3: single volume
4: multiple volumes
5: multiple RGB volumes
but got {}
but got {0}
""".format(ndim)))

view = view.lower()
Expand All @@ -100,7 +100,7 @@ def __init__(self, vol, view='t', fig=None, titles=None, order=0, sharexy=None,
self.axs = [axs] if len(vol) == 1 else list(axs.flat)
for ax, i, t in zip(self.axs, vol, self.titles):
ax.imshow(i[self.index], **kwargs)
ax.set_title(t or "slice #{}".format(self.index))
ax.set_title(t or f"slice #{self.index}")
self.vols = vol
# line profiles
self.order = order
Expand Down Expand Up @@ -137,7 +137,7 @@ def set_index(self, index):
self.index = int(index) % self.index_max
for ax, vol, t in zip(self.axs, self.vols, self.titles):
ax.images[0].set_array(vol[self.index])
ax.set_title(t or "slice #{}".format(self.index))
ax.set_title(t or f"slice #{self.index}")
for ann in self._annotes:
ann.remove()
self._annotes = []
Expand Down
88 changes: 88 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,94 @@
[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "miutil/_dist_ver.py"
write_to_template = "__version__ = '{version}'\n"

[tool.setuptools.packages.find]
exclude = ["tests"]

[project.urls]
documentation = "https://github.com/AMYPAD/miutil/#miutil"
repository = "https://github.com/AMYPAD/miutil"
changelog = "https://github.com/AMYPAD/miutil/releases"

[project]
name = "miutil"
dynamic = ["version"]
maintainers = [{name = "Casper da Costa-Luis", email = "casper.dcl@physics.org"}]
description = "Medical imaging utilities for the AMYPAD and NiftyPET projects"
readme = "README.rst"
requires-python = ">=3.7"
keywords = ["fMRI", "PET", "SPECT", "EEG", "MEG"]
license = {text = "Apache-2.0"}
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Environment :: GPU",
"Environment :: GPU :: NVIDIA CUDA",
"Intended Audience :: Education",
"Intended Audience :: Healthcare Industry",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Other Scripting Engines",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: User Interfaces",
"Topic :: System :: Installation/Setup",
"Topic :: Utilities"]
dependencies = ["tqdm>=4.40.0"]

[project.optional-dependencies]
dev = ["pytest>=6", "pytest-cov", "pytest-timeout", "pytest-xdist"]
nii = ["nibabel>=4.0", "numpy"]
plot = ["matplotlib", "numpy", "scipy"]
cuda = ["argopt", "pynvml"]
web = ["requests"]
mbeautify = ["argopt", "tqdm>=4.42.0", "requests"] # web

[project.scripts]
cuinfo = "miutil.cuinfo:main"
mbeautify = "miutil.mlab.beautify:main"

[tool.flake8]
max_line_length = 99
extend_ignore = ["E261"]
exclude = [".git", "__pycache__", "build", "dist", ".eggs"]

[tool.yapf]
spaces_before_comment = [15, 20]
arithmetic_precedence_indication = true
allow_split_before_dict_value = false
coalesce_brackets = true
column_limit = 99
each_dict_entry_on_separate_line = false
space_between_ending_comma_and_closing_bracket = false
split_before_named_assigns = false
split_before_closing_bracket = false
blank_line_before_nested_class_or_def = false

[tool.isort]
profile = "black"
line_length = 99
multi_line_output = 4
known_first_party = ["miutil", "tests"]

[tool.pytest.ini_options]
minversion = "6.0"
timeout = 15
log_level = "INFO"
python_files = ["tests/test_*.py"]
testpaths = ["tests"]
addopts = "-v --tb=short -rxs -W=error --log-level=debug -n=auto --durations=0 --cov=miutil --cov-report=term-missing --cov-report=xml"
92 changes: 0 additions & 92 deletions setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

0 comments on commit 7de60cb

Please sign in to comment.