Skip to content

Commit

Permalink
Merge pull request pydicom#110 from pydicom/add/black
Browse files Browse the repository at this point in the history
Adding black linter, testing github actions for pydicom
  • Loading branch information
vsoch authored Feb 8, 2020
2 parents 2b69ddb + 607dd45 commit 61a3619
Show file tree
Hide file tree
Showing 34 changed files with 1,329 additions and 1,220 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches_ignore: []

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: Setup black environment
run: conda create --quiet --name black black

- name: Check formatting
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate black
black --check --verbose deid
testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: Setup conda environment
run: |
conda create --quiet --name testing
export PATH="/usr/share/miniconda/bin:$PATH"
source activate testing
python setup.py install
- name: Test deid
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate testing
python -m unittest discover -s deid/tests/ -p '[t|T]est*.py'
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ matrix:
include:
- name: "Python 3.5"
python: "3.5"
env: RUN_PYLINT=yes
- name: "Python 2.7"
python: "2.7"
env: RUN_PYLINT=no

install:
- pip install pylint pydicom
- pip install pydicom
- cd $TRAVIS_BUILD_DIR/
- python setup.py sdist
- python setup.py install
- pylint --version

script:
- if [ "${RUN_PYLINT}" == "yes" ]; then pylint deid; fi;
- python -m unittest discover -s $TRAVIS_BUILD_DIR/deid/tests/ -p '[t|T]est*.py'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
Referenced versions in headers are tagged on Github, in parentheses are for pypi.

## [vxx](https://github.com/pydicom/deid/tree/master) (master)
- Adding black formatting, tests run in GitHub actions (0.1.35)
- Adding option to recursively replace sequences (0.1.34)
- adding pylint to clean up code (0.1.33)
- removing dependency that isn't used (simplejson) (0.1.31)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2019 Vanessa Sochat
Copyright (c) 2017-2020 Vanessa Sochat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
include README.md LICENSE
recursive-include deid *
global-exclude __pycache__
global-exclude *.pyc
prune __pycache__
prune *.pyc
prune *.pyc
prune deid/tests
prune *OLD
85 changes: 37 additions & 48 deletions deid/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'''
"""
DeidRecipe
Copyright (c) 2017-2019 Vanessa Sochat
Copyright (c) 2017-2020 Vanessa Sochat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,27 +26,20 @@
user can specify a custom name.
'''
"""

from deid.config.utils import (
load_deid,
get_deid,
load_combined_deid
)
from deid.config.standards import (
actions,
sections,
formats
)
from deid.config.utils import load_deid, get_deid, load_combined_deid
from deid.config.standards import actions, sections, formats

from deid.logger import bot
import os
import re

bot.level = 3


class DeidRecipe:
'''Create and work with a deid recipe to filter and perform operations on
"""Create and work with a deid recipe to filter and perform operations on
a dicom header. Usage typically looks like:
deid = 'dicom.deid'
Expand All @@ -62,30 +55,30 @@ class DeidRecipe:
base: if True, load a default base (default_base) before custom
default_base: the default base to load if "base" is True
'''
def __init__(self, deid=None, base=False, default_base='dicom'):
"""

def __init__(self, deid=None, base=False, default_base="dicom"):

# If deid is None, use the default
if deid is None:
bot.warning('No specification, loading default base deid.%s' % default_base)
bot.warning("No specification, loading default base deid.%s" % default_base)
base = True

self._init_deid(deid, base=base, default_base=default_base)

def __str__(self):
return '[deid]'
return "[deid]"

def __repr__(self):
return '[deid]'
return "[deid]"

def load(self, deid):
'''load a deid recipe into the object. If a deid configuration is
"""load a deid recipe into the object. If a deid configuration is
already defined, append to that.
'''
"""
deid = get_deid(deid)
if deid is not None:

# Update our list of files
self._files.append(deid)
self.files = list(set(self.files))
Expand All @@ -94,38 +87,35 @@ def load(self, deid):
self.deid = load_combined_deid([self.deid, deid])

def _get_section(self, name):
'''return a section (key) in the loaded deid, if it exists
'''
"""return a section (key) in the loaded deid, if it exists
"""
section = None
if self.deid is not None:
if name in self.deid:
section = self.deid[name]
return section


def get_format(self):
'''return the format of the loaded deid, if one exists
'''
return self._get_section('format')

"""return the format of the loaded deid, if one exists
"""
return self._get_section("format")

def get_filters(self, name=None):
'''return all filters for a deid recipe, or a set based on a name
'''
filters = self._get_section('filter')
"""return all filters for a deid recipe, or a set based on a name
"""
filters = self._get_section("filter")
if name is not None and filters is not None:
filters = filters[name]
filters = filters[name]
return filters


def ls_filters(self):
'''list names of filter groups
'''
filters = self._get_section('filter')
"""list names of filter groups
"""
filters = self._get_section("filter")
return list(filters.keys())

def get_actions(self, action=None, field=None):
'''get deid actions to perform on a header, or a subset based on a type
"""get deid actions to perform on a header, or a subset based on a type
A header action is a list with the following:
{'action': 'REMOVE', 'field': 'AssignedLocation'},
Expand All @@ -135,21 +125,20 @@ def get_actions(self, action=None, field=None):
action: if not None, filter to action specified
field: if not None, filter to field specified
'''
header = self._get_section('header')
"""
header = self._get_section("header")
if header is not None:
if action is not None:
action = action.upper()
header = [x for x in header if x['action'].upper() == action]
header = [x for x in header if x["action"].upper() == action]
if field is not None:
field = field.upper()
header = [x for x in header if x['field'].upper() == field]
header = [x for x in header if x["field"].upper() == field]

return header


def _init_deid(self, deid=None, base=False, default_base='dicom'):
'''initalize the recipe with one or more deids, optionally including
def _init_deid(self, deid=None, base=False, default_base="dicom"):
"""initalize the recipe with one or more deids, optionally including
the default. This function is called at init time. If you need to add
or work with already loaded configurations, use add/remove
Expand All @@ -160,7 +149,7 @@ def _init_deid(self, deid=None, base=False, default_base='dicom'):
(later in the list overrides earlier loaded).
default_base: load the default base before the user customizations.
'''
"""
if deid is None:
deid = []

Expand All @@ -173,5 +162,5 @@ def _init_deid(self, deid=None, base=False, default_base='dicom'):
self._files = deid

if len(deid) == 0:
bot.info('You can add custom deid files with .load().')
bot.info("You can add custom deid files with .load().")
self.deid = load_combined_deid(deid)
34 changes: 15 additions & 19 deletions deid/config/standards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
"""
Copyright (c) 2017-2019 Vanessa Sochat
Copyright (c) 2017-2020 Vanessa Sochat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,27 +20,23 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
"""

# Supported formats
formats = ['dicom']
formats = ["dicom"]

# Supported Sections
sections = ['header', 'labels', 'filter']
sections = ["header", "labels", "filter"]

actions = ('ADD',
'BLANK',
'JITTER',
'KEEP',
'REPLACE',
'REMOVE',
'LABEL')
actions = ("ADD", "BLANK", "JITTER", "KEEP", "REPLACE", "REMOVE", "LABEL")

# Valid actions for a filter action
filters = ('contains',
'notcontains',
'equals',
'notequals',
'missing',
'present',
'empty')
filters = (
"contains",
"notcontains",
"equals",
"notequals",
"missing",
"present",
"empty",
)
Loading

0 comments on commit 61a3619

Please sign in to comment.