Skip to content

Commit

Permalink
fixed other python 2/3 compatibility issues by hand
Browse files Browse the repository at this point in the history
  • Loading branch information
marius311 committed Aug 22, 2016
1 parent 3dbb98c commit 12a913d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CPU.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"""

from __future__ import unicode_literals, print_function

# System imports
import os
import sys
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CC = gcc
AR = ar rv

# (OPT) your python interpreter
PYTHON = python
PYTHON ?= python

# your optimization flag
OPTFLAG = -O4 -ffast-math #-march=native
Expand Down Expand Up @@ -60,7 +60,7 @@ EXTERNAL =

# Try to automatically avoid an error 'error: can't combine user with ...'
# which sometimes happens with brewed Python on OSX:
CFGFILE=$(shell $(PYTHON) -c "import sys; print sys.prefix+'/lib/'+'python'+'.'.join(['%i' % e for e in sys.version_info[0:2]])+'/distutils/distutils.cfg'")
CFGFILE=$(shell $(PYTHON) -c "from __future__ import print_function; import sys; print(sys.prefix+'/lib/'+'python'+'.'.join(['%i' % e for e in sys.version_info[0:2]])+'/distutils/distutils.cfg')")
PYTHONPREFIX=$(shell grep -s "prefix" $(CFGFILE))
ifeq ($(PYTHONPREFIX),)
PYTHONFLAGS=--user
Expand Down
1 change: 1 addition & 0 deletions external_Pk/generate_Pk_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
from __future__ import print_function
import sys
from math import exp

Expand Down
1 change: 1 addition & 0 deletions external_Pk/generate_Pk_example_w_tensors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
from __future__ import print_function
import sys
from math import exp

Expand Down
9 changes: 5 additions & 4 deletions python/classy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DEF _MAXTITLESTRINGLENGTH_ = 8000
# MontePython to handle things differently.
class CosmoError(Exception):
def __init__(self, message=""):
self.message = message
self.message = message.decode() if isinstance(message,bytes) else message

def __str__(self):
return '\n\nError in Class: ' + self.message
Expand Down Expand Up @@ -158,9 +158,10 @@ cdef class Class:
i = 0
for kk in self._pars:

dumc = kk
dumcp = kk.encode()
dumc = dumcp
sprintf(self.fc.name[i],"%s",dumc)
dumcp = str(self._pars[kk])
dumcp = str(self._pars[kk]).encode()
dumc = dumcp
sprintf(self.fc.value[i],"%s",dumc)
self.fc.read[i] = _FALSE_
Expand Down Expand Up @@ -311,7 +312,7 @@ cdef class Class:
for i in range(self.fc.size):
if self.fc.read[i] == _FALSE_:
problem_flag = True
problematic_parameters.append(self.fc.name[i])
problematic_parameters.append(self.fc.name[i].decode())
if problem_flag:
raise CosmoSevereError(
"Class did not read input parameter(s): %s\n" % ', '.join(
Expand Down
2 changes: 1 addition & 1 deletion python/extract_errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# From the dumped stdout and stderr of a nosetests test_class.py, extract all
# the failed steps.
# Usage: python extract_errors.py output

from __future__ import print_function
import sys
import os

Expand Down
6 changes: 3 additions & 3 deletions python/interface_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Automatically reads header files to generate an interface
"""

from __future__ import division, print_function
import sys
import logging
try:
Expand Down Expand Up @@ -88,7 +88,7 @@ def main():
for header in headers:
extract_headers(header, structs, output_file, logger)
logger.info("Finished extracting headers")
for struct_name, struct in list(structs.items()):
for struct_name, struct in structs.items():
create_wrapper_class(struct_name, struct, output_file, logger)

return
Expand Down Expand Up @@ -315,7 +315,7 @@ def create_wrapper_class(struct_name, struct, of, logger):
# Define the array variables for all needed
array_variables = []
variables = []
for key, value in list(struct.items()):
for key, value in struct.items():
if key != 'init':
if value[1]:
array_variables.append(key)
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
GCCPATH_STRING = sbp.Popen(
['gcc', '-print-libgcc-file-name'],
stdout=sbp.PIPE).communicate()[0]
GCCPATH = osp.normpath(osp.dirname(GCCPATH_STRING))
GCCPATH = osp.normpath(osp.dirname(GCCPATH_STRING)).decode()

# Recover the CLASS version
with open(os.path.join('..', 'include', 'common.h'), 'r') as v_file:
Expand Down
1 change: 1 addition & 0 deletions python/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
matter power spectrum. If the two are not close enough, it will generate a
PDF plot of this and save it in the 'fail' folder.
"""
from __future__ import print_function
from classy import Class
from classy import CosmoSevereError
import itertools
Expand Down

0 comments on commit 12a913d

Please sign in to comment.