Skip to content

Commit

Permalink
RF: os.linesep -> '\n'
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Feb 6, 2017
1 parent 043085f commit 92ee14c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 36 deletions.
10 changes: 6 additions & 4 deletions eelbrain/_data_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -5252,11 +5252,13 @@ def __unicode__(self):
return self.__repr__()

maxn = preferences['dataset_str_n_cases']
txt = unicode(self.as_table(maxn, '%.5g', midrule=True, lfmt=True))
if self.n_cases > maxn:
note = "... (use .as_table() method to see the whole Dataset)"
txt = os.linesep.join((txt, note))
return txt
caption = "... (use .as_table() method to see the whole Dataset)"
else:
caption = None
txt = self.as_table(maxn, '%.5g', midrule=True, caption=caption,
lfmt=True)
return unicode(txt)

def _check_n_cases(self, X, empty_ok=True):
"""Check that an input argument has the appropriate length.
Expand Down
8 changes: 4 additions & 4 deletions eelbrain/_experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def show_fields(self, str_out=False):
if not values:
lines.append(line)

table = os.linesep.join(lines)
table = '\n'.join(lines)
if str_out:
return table
else:
Expand Down Expand Up @@ -793,8 +793,8 @@ def show_tree(self, root='root', fields=None):
name_len = max(len(n) for n, _ in nodes)
path_len = max(len(p) for _, p in nodes)
pad = ' ' * (80 - name_len - path_len)
print(os.linesep.join(n.ljust(name_len) + pad + p.ljust(path_len)
for n, p in nodes))
print('\n'.join(n.ljust(name_len) + pad + p.ljust(path_len) for
n, p in nodes))

def store_state(self):
"""Store the current state
Expand Down Expand Up @@ -1276,7 +1276,7 @@ def rename_field(self, temp, field, old, new, exclude=False, **kwargs):
lines.append('')
msg = 'Legend m: source is missing; o: will overwite a file'
lines.append(msg)
print(os.linesep.join(lines))
print('\n'.join(lines))
rename = tuple(item for item in items if item[0] == ' ')
if not rename:
return
Expand Down
8 changes: 4 additions & 4 deletions eelbrain/_experiment/mne_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ def __init__(self, root=None, find_subjects=True, **state):
msg.extend(sorted(' ' + relpath(f, root) for f in files))
else:
msg.append("No cache files affected.")
log.debug(os.linesep.join(msg))
log.debug('\n'.join(msg))
# don't print same message to the screen twice
if self._screen_log_level <= logging.DEBUG:
msg = []
Expand All @@ -1543,9 +1543,9 @@ def __init__(self, root=None, find_subjects=True, **state):
if self.auto_delete_cache is False:
msg.append("Automatic cache management disabled. Either "
"revert changes, or set e.auto_delete_cache=True")
raise RuntimeError(os.linesep.join(msg))
raise RuntimeError('\n'.join(msg))
elif self.auto_delete_cache == 'debug':
print(os.linesep.join(msg))
print('\n'.join(msg))
print("delete: delete invalid cache files\n"
"abort: raise an error (debugger can be used)\n"
"ignore: proceed without doing anything\n"
Expand Down Expand Up @@ -2907,7 +2907,7 @@ def load_evoked(self, subject=None, baseline=False, ndvar=True, cat=None,
alens = np.array(lens)
for l in ulens:
err.append('%i: %r' % (l, ds['subject', alens == l].cells))
raise DimensionMismatchError(os.linesep.join(err))
raise DimensionMismatchError('\n'.join(err))

else: # single subject
ds = self._make_evoked(decim, data_raw)
Expand Down
3 changes: 1 addition & 2 deletions eelbrain/_stats/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from itertools import izip
import logging
import os

import numpy as np
from scipy.linalg import lstsq
Expand Down Expand Up @@ -958,7 +957,7 @@ def __str__(self):

def print_log(self):
out = self._log[:]
print(os.linesep.join(out))
print('\n'.join(out))

def table(self):
"""Create an ANOVA table
Expand Down
3 changes: 1 addition & 2 deletions eelbrain/_utils/print_funcs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
"Some functions which print data in a different way"
from __future__ import print_function
import os
import numpy as np


def dicttree(dictionary):
"""readable repr for a hierarchical dictionary"""
print(os.linesep.join(_dict_repr(dictionary)))
print('\n'.join(_dict_repr(dictionary)))


def _dict_repr(dictionary, indent=0):
Expand Down
4 changes: 2 additions & 2 deletions eelbrain/_utils/subp.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def do_forward_solution(paths=dict(rawfif=None,
return fwd_file
else:
err = "fwd-file not created"
err = os.linesep.join([err, "command out:", out])
err = '\n'.join([err, "command out:", out])
raise RuntimeError(err)


Expand Down Expand Up @@ -575,7 +575,7 @@ def do_inverse_operator(fwd_file, cov_file, inv_file='{cov}inv.fif',

_, err = _run(cmd)
if not os.path.exists(inv_file):
raise RuntimeError(os.linesep.join(["inv-file not created", err]))
raise RuntimeError('\n'.join(["inv-file not created", err]))


def mne_make_morph_maps(s_to='fsaverage', s_from=None, redo=False, subjects_dir=None):
Expand Down
17 changes: 8 additions & 9 deletions eelbrain/fmtxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def make_html_doc(body, root, resource_dir=None, title=None, meta=None):
else:
meta = ''

style = os.linesep.join(('', '<style>', STYLE, '</style>'))
style = '\n'.join(('', '<style>', STYLE, '</style>'))

env = {'root': root, 'resource_dir': resource_dir}
txt_body = html(body, env)
Expand Down Expand Up @@ -963,7 +963,7 @@ def get_html(self, env={}):
items.append(_html_element('li', item, env))

items.append('</%s>' % tag)
return os.linesep.join(items)
return '\n'.join(items)

def get_str(self, env={}):
out = []
Expand All @@ -977,7 +977,7 @@ def get_str(self, env={}):
out.extend(' %s' % line for line in lines[1:])
else:
out.append('- %s' % str(item))
return os.linesep.join(out)
return '\n'.join(out)


# Table ---
Expand Down Expand Up @@ -1316,7 +1316,7 @@ def get_rtf(self, env={}):
rows.append(row.get_rtf(env))
return '\n'.join(rows)

def get_str(self, env={}, delim=' ', linesep=os.linesep):
def get_str(self, env={}, delim=' ', linesep='\n'):
"""Convert Table to str
Parameters
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def get_tex(self, env={}):
if self.rules:
tex_post = [r"\bottomrule"] + tex_post
# combine
tex_repr = os.linesep.join(tex_pre + tex_body + tex_post)
tex_repr = '\n'.join(tex_pre + tex_body + tex_post)
return tex_repr

def get_tsv(self, delimiter='\t', linesep='\r\n', fmt='%.9g'):
Expand Down Expand Up @@ -1445,7 +1445,7 @@ def save_tsv(self, path=None, delimiter='\t', linesep='\r\n', fmt='%.15g'):
"""
_save_txt(self.get_tsv(delimiter, linesep, fmt), path)

def save_txt(self, path=None, fmt='%.15g', delim=' ', linesep=os.linesep):
def save_txt(self, path=None, fmt='%.15g', delim=' ', linesep='\n'):
"""
Save the table as text file.
Expand All @@ -1458,8 +1458,7 @@ def save_txt(self, path=None, fmt='%.15g', delim=' ', linesep=os.linesep):
delim : str
Cell delimiter.
linesep : str
String that is placed in between lines (default is platform-specific
``os.linesep``).
String that is placed in between lines (default is ``'\n'``).
"""
_save_txt(self.get_str({'fmt': fmt}, delim, linesep), path)

Expand Down Expand Up @@ -2056,7 +2055,7 @@ def unindent(text, skip1=False):
if skip1:
lines[0] = ' ' * rm + lines[0].lstrip()

text = os.linesep.join(line[rm:] for line in lines)
text = '\n'.join(line[rm:] for line in lines)

return text

Expand Down
10 changes: 4 additions & 6 deletions eelbrain/mne_fixes/_label.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Fixes for defective mne functions
from collections import defaultdict
import os
import os.path as op

import numpy as np
Expand Down Expand Up @@ -127,8 +126,7 @@ def write_labels_to_annot(labels, subject=None, parc=None, overwrite=False,

# find number of vertices in surface
if subject is not None and subjects_dir is not None:
fpath = os.path.join(subjects_dir, subject, 'surf',
'%s.white' % hemi)
fpath = op.join(subjects_dir, subject, 'surf', '%s.white' % hemi)
points, _ = read_surface(fpath)
n_vertices = len(points)
else:
Expand Down Expand Up @@ -204,18 +202,18 @@ def write_labels_to_annot(labels, subject=None, parc=None, overwrite=False,
msg = ("Some labels have the same color values (all labels in one "
"hemisphere must have a unique color):")
duplicate_colors.insert(0, msg)
issues.append(os.linesep.join(duplicate_colors))
issues.append('\n'.join(duplicate_colors))
if invalid_colors:
msg = ("Some labels have invalid color values (all colors should be "
"RGBA tuples with values between 0 and 1)")
invalid_colors.insert(0, msg)
issues.append(os.linesep.join(invalid_colors))
issues.append('\n'.join(invalid_colors))
if overlap:
msg = ("Some labels occupy vertices that are also occupied by one or "
"more other labels. Each vertex can only be occupied by a "
"single label in *.annot files.")
overlap.insert(0, msg)
issues.append(os.linesep.join(overlap))
issues.append('\n'.join(overlap))

if issues:
raise ValueError('\n\n'.join(issues))
Expand Down
4 changes: 1 addition & 3 deletions eelbrain/save/_txt.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
import os

from .._utils import ui

__all__ = ['txt']


def txt(iterator, fmt='%s', delim=os.linesep, dest=None):
def txt(iterator, fmt='%s', delim='\n', dest=None):
"""
Writes any object that supports iteration to a text file.
Expand Down

0 comments on commit 92ee14c

Please sign in to comment.