Skip to content

Commit

Permalink
Merge pull request #30 from AMYPAD/devel
Browse files Browse the repository at this point in the history
next release v0.11.0
  • Loading branch information
casperdcl authored Mar 10, 2023
2 parents 93dee7c + 39734cf commit feedd52
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 99 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/comment-bot.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name: Comment Bot
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issue_comment: {types: [created]}
pull_request_review_comment: {types: [created]}
jobs:
tag: # /tag <tagname> <commit>
if: startsWith(github.event.comment.body, '/tag ')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: React Seen
uses: actions/github-script@v2
uses: actions/github-script@v6
with:
script: |
const perm = await github.repos.getCollaboratorPermissionLevel({
const perm = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner, repo: context.repo.repo,
username: context.payload.comment.user.login})
post = (context.eventName == "issue_comment"
? github.reactions.createForIssueComment
: github.reactions.createForPullRequestReviewComment)
? github.rest.reactions.createForIssueComment
: github.rest.reactions.createForPullRequestReviewComment)
if (!["admin", "write"].includes(perm.data.permission)){
post({
owner: context.repo.owner, repo: context.repo.repo,
Expand All @@ -40,12 +38,12 @@ jobs:
BODY: ${{ github.event.comment.body }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: React Success
uses: actions/github-script@v2
uses: actions/github-script@v6
with:
script: |
post = (context.eventName == "issue_comment"
? github.reactions.createForIssueComment
: github.reactions.createForPullRequestReviewComment)
? github.rest.reactions.createForIssueComment
: github.rest.reactions.createForPullRequestReviewComment)
post({
owner: context.repo.owner, repo: context.repo.repo,
comment_id: context.payload.comment.id, content: "rocket"})
Expand Down
56 changes: 24 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ name: Test
on:
push:
pull_request:
schedule:
- cron: '15 23 * * 6' # M H d m w (Sat at 23:15)
schedule: [{cron: '15 23 * * 6'}] # M H d m w (Sat at 23:15)
jobs:
check:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: set PYSHA
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PYSHA }}|${{ hashFiles('.pre-commit-config.yaml') }}
Expand All @@ -40,36 +41,33 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.6, 3.9]
python: [3.7, 3.11]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- run: pip install -U .[dev,nii,web]
- if: startsWith(matrix.python, '3')
run: pytest --durations-min=1
- if: startsWith(matrix.python, '2')
run: pytest
- uses: codecov/codecov-action@v1
- run: pytest --durations-min=1
- uses: codecov/codecov-action@v3
cuda_matlab:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
name: CUDA MATLAB py${{ matrix.python }}
runs-on: [self-hosted, python, cuda, matlab]
strategy:
matrix:
python: [3.7, 3.9]
python: [3.7, 3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run setup-python
run: setup-python -p${{ matrix.python }}
- run: pip install -U .[dev,nii,cuda,web,mbeautify]
- run: pytest --durations-min=1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
- name: Post Run setup-python
run: setup-python -p${{ matrix.python }} -Dr
if: ${{ always() }}
Expand All @@ -78,10 +76,12 @@ jobs:
name: PyPI Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- id: dist
uses: casperdcl/deploy-pypi@v2
with:
Expand All @@ -90,19 +90,11 @@ jobs:
gpg_key: ${{ secrets.GPG_KEY }}
password: ${{ secrets.PYPI_TOKEN }}
upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
- id: meta
name: Changelog
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD > _CHANGES.md
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: softprops/action-gh-release@v1
name: Release
run: |
changelog=$(git log --pretty='format:%d%n- %s%n%b---' $(git tag --sort=v:refname | tail -n2 | head -n1)..HEAD)
tag="${GITHUB_REF#refs/tags/}"
gh release create --title "miutil $tag beta" --draft --notes "$changelog" "$tag" dist/${{ steps.dist.outputs.whl }} dist/${{ steps.dist.outputs.whl_asc }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
name: miutil ${{ steps.meta.outputs.tag }} beta
body_path: _CHANGES.md
draft: true
files: |
dist/${{ steps.dist.outputs.whl }}
dist/${{ steps.dist.outputs.whl_asc }}
GH_TOKEN: ${{ github.token }}
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -25,8 +25,8 @@ repos:
entry: TODO
types: [text]
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [-j8]
Expand All @@ -44,6 +44,6 @@ repos:
args: [-i]
additional_dependencies: [toml]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To install extras and their dependencies,
use the package name ``miutil[option1,option2]``.


.. |Tests| image:: https://img.shields.io/github/workflow/status/AMYPAD/miutil/Test?logo=GitHub
.. |Tests| image:: https://img.shields.io/github/actions/workflow/status/AMYPAD/miutil/test.yml?branch=master&logo=GitHub
:target: https://github.com/AMYPAD/miutil/actions
.. |Coverage| image:: https://codecov.io/gh/AMYPAD/miutil/branch/master/graph/badge.svg
:target: https://codecov.io/gh/AMYPAD/miutil
Expand Down
6 changes: 5 additions & 1 deletion miutil/cuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def memory(dev_id=-1):

def name(dev_id=-1):
"""returns device name"""
return pynvml.nvmlDeviceGetName(get_handle(dev_id)).decode("U8")
res = pynvml.nvmlDeviceGetName(get_handle(dev_id))
try:
return res.decode("U8") # pynvml<11.5
except AttributeError:
return res


def nvcc_flags(dev_id=-1):
Expand Down
20 changes: 4 additions & 16 deletions miutil/fdio.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import logging
import re
from collections.abc import Iterable
from contextlib import contextmanager
from os import makedirs
from os import fspath, makedirs
from pathlib import Path
from shutil import copyfileobj, rmtree
from tempfile import mkdtemp
from zipfile import ZipFile

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
try:
from os import fspath
except ImportError:
fspath = str
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

from tqdm.auto import tqdm
from tqdm.utils import CallbackIOWrapper

Expand All @@ -32,7 +21,7 @@ def create_dir(pth):
try:
makedirs(fspath(pth))
except Exception as exc:
log.warning("cannot create:%s:%s" % (pth, exc))
log.warning("cannot create:%s:%s", pth, exc)


def is_iter(x):
Expand Down Expand Up @@ -78,7 +67,6 @@ def extractall(fzip, dest, desc="Extracting"):

def nsort(fnames):
"""Sort a file list, automatically detecting embedded numbers"""

def path2parts(fname):
parts = re.split(r"([0-9][0-9.]*e[-+][0-9]+|[0-9]+\.[0-9]+|[0-9]+)", fname)
parts[1::2] = map(float, parts[1::2])
Expand Down
2 changes: 1 addition & 1 deletion miutil/imio/nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def array2nii(im, A, fnii, descrip="", trnsp=None, flip=None, storage_as=None):
if len(flip) == 3:
im = im[::-flip[0], ::-flip[1], ::-flip[2], ...]

res = nib.Nifti1Image(im, A)
res = nib.Nifti1Image(im, A, dtype=im.dtype)
hdr = res.header
hdr.set_sform(None, code='scanner')
hdr['cal_max'] = np.max(im) # np.percentile(im, 90) #
Expand Down
32 changes: 14 additions & 18 deletions miutil/mlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import re
import sys
from ast import literal_eval
from functools import lru_cache
from os import getenv, path
from platform import system
from subprocess import STDOUT, CalledProcessError, check_output
from textwrap import dedent

try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
try:
FileNotFoundError
except NameError:
Expand Down Expand Up @@ -52,9 +49,9 @@ def check_output_u8(*args, **kwargs):

def env_prefix(key, dir):
try:
os.environ[key] = "%s%s%s" % (os.environ[key], os.pathsep, fspath(dir))
os.environ[key] = f"{os.environ[key]}{os.pathsep}{fspath(dir)}"
except KeyError:
os.environ[key] = str(fspath(dir))
os.environ[key] = fspath(dir)


@lru_cache()
Expand Down Expand Up @@ -91,14 +88,13 @@ def get_engine(name=None):
Alternatively, use `get_runtime()` instead of `get_engine()`.
""").format(matlabroot=matlabroot(default="matlabroot"), exe=sys.executable))
started = engine.find_matlab()
notify = False
if not started or (name and name not in started):
notify = True
log.debug("Starting MATLAB")
eng = engine.connect_matlab(name=name or getenv("SPM12_MATLAB_ENGINE", None))
if notify:
log.debug("MATLAB started")
log.debug("Starting MATLAB")
try:
eng = engine.connect_matlab(name=name or getenv("SPM12_MATLAB_ENGINE", None))
except engine.EngineError:
log.error("MATLAB hasn't properly cleaned up. Try restarting your computer.")
raise
log.debug("MATLAB started")
return eng


Expand Down Expand Up @@ -152,7 +148,7 @@ def _install_engine():
def get_runtime(cache="~/.mcr", version=99):
cache = Path(cache).expanduser()
mcr_root = cache
i = mcr_root / ("v%d"%version)
i = mcr_root / f"v{version}"
if i.is_dir():
mcr_root = i
else:
Expand All @@ -174,8 +170,8 @@ def get_runtime(cache="~/.mcr", version=99):
if system() == "Linux":
install.chmod(0o755)
check_output_u8([
fspath(install), "-P",
'bean421.installLocation="%s"' % fspath(cache), "-silent"])
fspath(install), "-P", f'bean421.installLocation="{fspath(cache)}"',
"-silent"])
else:
raise NotImplementedError(
dedent("""\
Expand All @@ -185,7 +181,7 @@ def get_runtime(cache="~/.mcr", version=99):
""").format(fspath(install), system()))
else:
raise IndexError(version)
mcr_root /= "v%d" % version
mcr_root /= f"v{version}"
log.info("Installed")

# bin
Expand Down
6 changes: 3 additions & 3 deletions miutil/mlab/beautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
def ensure_mbeautifier(*args, **kwargs):
eng = get_engine(*args, **kwargs)
fn = get_file(
"MBeautifier-%s.zip" % MBEAUTIFIER_REV[:7],
"https://github.com/davidvarga/MBeautifier/archive/%s.zip" % MBEAUTIFIER_REV,
f"MBeautifier-{MBEAUTIFIER_REV[:7]}.zip",
f"https://github.com/davidvarga/MBeautifier/archive/{MBEAUTIFIER_REV}.zip",
)
outpath = path.join(path.dirname(fn), "MBeautifier-%s" % MBEAUTIFIER_REV)
outpath = path.join(path.dirname(fn), f"MBeautifier-{MBEAUTIFIER_REV}")
if not path.exists(outpath):
with ZipFile(fn) as fd:
fd.extractall(path=path.dirname(outpath))
Expand Down
4 changes: 2 additions & 2 deletions miutil/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_file(fname, origin, cache_dir=None, chunk_size=None):
fpath = path.join(cache_dir, fname)

if not path.exists(fpath):
log.debug("Downloading %s from %s" % (fpath, origin))
log.debug("Downloading %s from %s", fpath, origin)
try:
d = requests.get(origin, stream=True)
with tqdm(
Expand Down Expand Up @@ -93,7 +93,7 @@ def urlopen_cached(url, outdir, fname=None, mode="rb"):
if fname is None:
fname = Path(urlparse(url).path).name
fout = outdir / fname
cache = outdir / (fspath(fname) + ".url")
cache = outdir / f"{fspath(fname)}.url"
if not fout.is_file() or not cache.is_file() or cache.read_text().strip() != url:
fi = urlopen(url)
with fout.open("wb") as raw:
Expand Down
Loading

0 comments on commit feedd52

Please sign in to comment.