Skip to content

Commit

Permalink
Merge pull request #12 from AMYPAD/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored Dec 30, 2020
2 parents 37a8127 + 0fa5b07 commit 7caa6c0
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 80 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['2.7', '3.7']
python: [2.7, 3.6, 3.9]
name: Check py${{ matrix.python }}
steps:
- uses: actions/checkout@v2
Expand All @@ -27,9 +27,7 @@ jobs:
- uses: reviewdog/action-setup@v1
- if: github.event_name != 'schedule'
run: |
set -o pipefail
pre-commit run -a flake8 | \
reviewdog -f=pep8 -name=flake8 -tee -reporter=github-check -filter-mode nofilter
pre-commit run -a flake8 | reviewdog -f=pep8 -name=flake8 -tee -reporter=github-check -filter-mode nofilter
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: startsWith(matrix.python, '3')
Expand All @@ -40,7 +38,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.7]
python: [2.7, 3.5, 3.6, 3.9]
name: Test py${{ matrix.python }}
steps:
- uses: actions/checkout@v2
Expand All @@ -50,7 +48,10 @@ jobs:
with:
python-version: ${{ matrix.python }}
- run: pip install -U .[dev]
- run: python -m tests --cov-report=term-missing --cov-report=xml
- if: startsWith(matrix.python, '3')
run: pytest --durations-min=1
- if: startsWith(matrix.python, '2')
run: pytest
- run: codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -62,7 +63,7 @@ jobs:
with:
fetch-depth: 0
- run: pip install -U .[dev,cuda]
- run: python -m tests --cov-report=term-missing --cov-report=xml
- run: pytest --durations-min=1
- run: codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions miutil/cuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Options:
-n, --num-devices : print number of devices (ignores `-d`)
-f, --nvcc-flags : print out flags for use nvcc compilation
-c, --compute : print out compute capabilities (strip periods)
-d ID, --dev-id ID : select device ID [default: None:int] for all
"""
import pynvml
Expand Down Expand Up @@ -72,6 +73,9 @@ def main(*args, **kwargs):
if args.nvcc_flags:
print(" ".join(sorted(set(map(nvcc_flags, devices)))[::-1]))
noargs = False
if args.compute:
print(" ".join(sorted({"%d%d" % compute_capability(i) for i in devices})[::-1]))
noargs = False
if noargs:
for dev_id in devices:
print(
Expand Down
14 changes: 10 additions & 4 deletions miutil/fdio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from collections import Iterable
from contextlib import contextmanager
from os import makedirs, path
from shutil import rmtree
Expand All @@ -19,13 +20,18 @@ def create_dir(pth):
try:
makedirs(pth)
except Exception as exc:
log.warn("cannot create:%s:%s" % (pth, exc))
log.warning("cannot create:%s:%s" % (pth, exc))


def is_iter(x):
return isinstance(x, Iterable) and not isinstance(x, (str, bytes))


def hasext(fname, ext):
if ext[0] != ".":
ext = "." + ext
return path.splitext(fspath(fname))[1].lower() == ext.lower()
if not is_iter(ext):
ext = (ext,)
ext = (("" if i[0] == "." else ".") + i.lower() for i in ext)
return fspath(fname).lower().endswith(tuple(ext))


@contextmanager
Expand Down
4 changes: 2 additions & 2 deletions miutil/mlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_engine(name=None):
from matlab import engine
except ImportError:
try:
log.warn(
log.warning(
dedent(
"""\
Python could not find the MATLAB engine.
Expand Down Expand Up @@ -125,5 +125,5 @@ def _install_engine():
try:
return check_output_u8(cmd, cwd=src)
except CalledProcessError:
log.warn("Normal install failed. Attempting `--user` install.")
log.warning("Normal install failed. Attempting `--user` install.")
return check_output_u8(cmd + ["--user"], cwd=src)
9 changes: 6 additions & 3 deletions miutil/mlab/beautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from . import get_engine

log = logging.getLogger(__name__)
MBEAUTIFIER_REV = "73bc3da7df39a60aab859a2cb86dd82b4d284312"
MBEAUTIFIER_REV = "9c3c82387ec3c0fb29e707ebd060e8e2ca9ea6f2"


@lru_cache()
Expand All @@ -26,7 +26,7 @@ def ensure_mbeautifier(*args, **kwargs):
eng = get_engine(*args, **kwargs)
fn = get_file(
"MBeautifier-%s.zip" % MBEAUTIFIER_REV[:7],
"https://github.com/AMYPAD/MBeautifier/archive/%s.zip" % MBEAUTIFIER_REV,
"https://github.com/davidvarga/MBeautifier/archive/%s.zip" % MBEAUTIFIER_REV,
)
outpath = path.join(path.dirname(fn), "MBeautifier-%s" % MBEAUTIFIER_REV)
if not path.exists(outpath):
Expand All @@ -46,7 +46,10 @@ def main(*args, **kwargs):

for fn in tmap(path.abspath, args.mfile):
log.debug("file:%s", fn)
formatter(fn, fn, nargout=0)
try:
formatter(fn, fn, nargout=0)
except Exception as exc:
log.error("file:%s:\n%s", fn, exc)


if __name__ == "__main__": # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ write_to = "miutil/_dist_ver.py"
write_to_template = "__version__ = '{version}'\n"

[tool.black]
target-version = ['py27', 'py36']
target_version = ["py27", "py36", "py38"]
54 changes: 26 additions & 28 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[metadata]
name = miutil
description = Medical imaging utilities for the AMYPAD and NiftyPET projects
long_description = file: README.rst
long_description_content_type = text/x-rst
license = Apache 2.0
license_file = LICENCE.md
url = https://github.com/AMYPAD/miutil
project_urls =
name=miutil
description=Medical imaging utilities for the AMYPAD and NiftyPET projects
long_description=file: README.rst
long_description_content_type=text/x-rst
license=Apache 2.0
license_file=LICENCE.md
url=https://github.com/AMYPAD/miutil
project_urls=
Changelog = https://github.com/AMYPAD/miutil/releases
Documentation = https://github.com/AMYPAD/miutil/#miutil
maintainer = Casper da Costa-Luis
maintainer_email = casper.dcl@physics.org
keywords = fMRI, PET, SPECT, EEG, MEG
platforms = any
provides = miutil
classifiers =
maintainer=Casper da Costa-Luis
maintainer_email=casper.dcl@physics.org
keywords=fMRI, PET, SPECT, EEG, MEG
platforms=any
provides=miutil
classifiers=
Development Status :: 4 - Beta
Intended Audience :: Developers
Environment :: GPU
Expand All @@ -41,14 +41,11 @@ classifiers =
Topic :: System :: Installation/Setup
Topic :: Utilities
[options]
zip_safe = False
setup_requires = setuptools>=42; setuptools_scm[toml]>=3.4
install_requires =
argparse; python_version == "2.6"
include_package_data = True
packages = find:
setup_requires=setuptools>=42; wheel; setuptools_scm[toml]>=3.4
packages=find:
python_requires=>=2.7
[options.extras_require]
dev =
dev=
pre-commit
twine
wheel
Expand All @@ -66,17 +63,18 @@ mbeautify = argopt; %(web)s
console_scripts =
cuinfo = miutil.cuinfo:main
mbeautify = miutil.mlab.beautify:main
[options.package_data]
* = *.md, *.rst, *.m

[bdist_wheel]
universal = 1

[flake8]
max_line_length = 88
extend-ignore = E203,P1
exclude = .git,__pycache__,build,dist,.eggs
max_line_length=88
extend-ignore=E203,P1
exclude=.git,__pycache__,build,dist,.eggs

[isort]
profile = black
known_first_party = miutil,tests
profile=black
known_first_party=miutil,tests

[tool:pytest]
addopts=-v --tb=short -rxs -W=error --log-level=debug -n=auto --durations=0 --cov=miutil --cov-report=term-missing --cov-report=xml
21 changes: 0 additions & 21 deletions tests/__main__.py

This file was deleted.

4 changes: 4 additions & 0 deletions tests/test_cuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ def test_cuinfo_cli(capsys):
cuinfo.main(["--nvcc-flags"])
out, _ = capsys.readouterr()
assert not devices or out.startswith("-gencode=")

cuinfo.main(["--compute"])
out, _ = capsys.readouterr()
assert not devices or all(map(int, out.split(" ")))
16 changes: 8 additions & 8 deletions tests/test_fdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@

def test_create_dir(tmp_path, caplog):
tmpdir = tmp_path / "create_dir"
assert not path.exists(fdio.fspath(tmpdir))
assert not tmpdir.exists()
fdio.create_dir(tmpdir)
tmpdir = fdio.fspath(tmpdir)
assert path.exists(tmpdir)
rmtree(tmpdir, True)
assert tmpdir.exists() and tmpdir.is_dir()
rmtree(fdio.fspath(tmpdir), True)

with open(tmpdir, "w") as fd:
with open(fdio.fspath(tmpdir), "w") as fd:
fd.write("dummy file")
with caplog.at_level(logging.INFO):
assert "cannot create" not in caplog.text
fdio.create_dir(tmpdir)
assert "cannot create" in caplog.text

assert path.exists(tmpdir)
assert tmpdir.exists()


def test_hasext():
for fname, ext in [
(".baz", ".baz"),
("foo.bar", ".bar"),
("foo.bar", "bar"),
("foo.bar.baz", "baz"),
("foo.bar.baz", "bar.baz"),
("foo/bar.baz", "baz"),
("foo.bar.baz", "baz"),
]:
assert fdio.hasext(fname, ext)

for fname, ext in [
("foo.bar", "baz"),
("foo.bar.baz", "bar.baz"),
("foo", "foo"),
]:
assert not fdio.hasext(fname, ext)
Expand Down
8 changes: 2 additions & 6 deletions tests/test_web.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from os import path

from pytest import importorskip

from miutil import fspath

web = importorskip("miutil.web")


def test_get_file(tmp_path):
tmpdir = tmp_path / "get_file"
assert not path.exists(fspath(tmpdir))
assert not tmpdir.exists()
web.get_file(
"README.rst",
"https://github.com/AMYPAD/miutil/raw/master/README.rst",
cache_dir=tmpdir,
)
assert path.exists(fspath(tmpdir / "README.rst"))
assert (tmpdir / "README.rst").is_file()

0 comments on commit 7caa6c0

Please sign in to comment.