Skip to content

Commit

Permalink
minor and allow pypy3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed May 17, 2021
1 parent a4bd4f9 commit 3582dfc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions getdist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
if sys.version_info < (3, 7):
import platform

if platform.python_implementation() != 'CPython':
raise ValueError('Only CPython is supported on Python 3.6')
if platform.python_implementation() not in ['CPython', 'PyPy']:
raise ValueError('Only CPython and PyPy is supported on Python 3.6')


def get_defaults_file(name='analysis_defaults.ini'):
Expand Down
2 changes: 1 addition & 1 deletion getdist/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def runScript(fname):
subprocess.Popen(['python', fname])


# noinspection PyUnboundLocalVariable
# noinspection PyUnboundLocalVariable,PyProtectedMember
def getdist_script(args, exit_on_error=True):
def do_error(msg):
if exit_on_error:
Expand Down
3 changes: 2 additions & 1 deletion getdist/gaussian_mixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def density2D(self, params=None, num_points=1024, xmin=None, xmax=None, ymin=Non
else:
mixture = self

# noinspection PyProtectedMember
return mixture._density2D(num_points=num_points, xmin=xmin, xmax=xmax, ymin=ymin,
ymax=ymax, sigma_max=sigma_max)

Expand All @@ -220,7 +221,7 @@ def _params_to_indices(self, params):
indices.append(p)
return indices

def marginalizedMixture(self, params, label=None, no_limit_marge=False):
def marginalizedMixture(self, params, label=None, no_limit_marge=False) -> 'MixtureND':
"""
Calculates a reduced mixture model by marginalization over unwanted parameters
Expand Down
2 changes: 2 additions & 0 deletions getdist/gui/SyntaxHighlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class PythonHighlighter(QSyntaxHighlighter):
r'\{', r'\}', r'\(', r'\)', r'\[', r'\]',
]

# noinspection PyArgumentList
def __init__(self, document):
QSyntaxHighlighter.__init__(self, document)

Expand Down Expand Up @@ -107,6 +108,7 @@ def __init__(self, document):
]

# Build a QRegExp for each pattern
# noinspection PyArgumentList
self.rules = [(QRegExp(pat), index, fmt)
for (pat, index, fmt) in rules]

Expand Down
5 changes: 3 additions & 2 deletions getdist/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def write(self, m):
pass


# noinspection PyArgumentList
class RootListWidget(QListWidget):
def __init__(self, widget, owner):
QListWidget.__init__(self, widget)
Expand Down Expand Up @@ -332,7 +333,7 @@ def _image_file(self, name):

def _icon(self, name, large=True):
if large:
name = name + '_large'
name += '_large'
pm = QPixmap(self._image_file('%s.png' % name))
if hasattr(pm, 'setDevicePixelRatio'):
pm.setDevicePixelRatio(self.devicePixelRatio())
Expand Down Expand Up @@ -2002,7 +2003,7 @@ def __init__(self, parent, PCA_text, root):

# ==============================================================================

# noinspection PyCallByClass
# noinspection PyCallByClass,PyArgumentList
class DialogParamTables(DialogTextOutput):
def __init__(self, parent, tables, root):
DialogTextOutput.__init__(self, parent)
Expand Down
19 changes: 9 additions & 10 deletions getdist/yaml_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ class InputSyntaxError(Exception):
# 1. Matches 1e2 as 100 (no need for dot, or sign after e),
# from http://stackoverflow.com/a/30462009
def yaml_load(text_stream, Loader=yaml.Loader, file_name=None):
class OrderedLoader(Loader):
class ScientificLoader(Loader):
pass

OrderedLoader.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(u'''^(?:
[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
ScientificLoader.add_implicit_resolver(
'tag:yaml.org,2002:float',
re.compile('''^(?:
[-+]?[0-9][0-9_]*\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?[0-9][0-9_]*[eE][-+]?[0-9]+
|\\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
|[-+]?\\.(?:inf|Inf|INF)
|\\.(?:nan|NaN|NAN))$''', re.X),
list(u'-+0123456789.'))
list('-+0123456789.'))

# Ignore python objects
def dummy_object_loader(loader, suffix, node):
return None

OrderedLoader.add_multi_constructor(
u'tag:yaml.org,2002:python/name:', dummy_object_loader)
ScientificLoader.add_multi_constructor('tag:yaml.org,2002:python/name:', dummy_object_loader)
try:
return yaml.load(text_stream, OrderedLoader)
return yaml.load(text_stream, ScientificLoader)
# Redefining the general exception to give more user-friendly information
except yaml.YAMLError as exception:
errstr = "Error in your input file " + ("'" + file_name + "'" if file_name else "")
Expand Down

0 comments on commit 3582dfc

Please sign in to comment.