Skip to content

Commit

Permalink
2-3-compatibilize python code
Browse files Browse the repository at this point in the history
  • Loading branch information
vvolkl committed Mar 24, 2020
1 parent 6019f0f commit 86a8559
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
3 changes: 3 additions & 0 deletions python/EventStore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

from past.builtins import xrange

from ROOT import gSystem
gSystem.Load("libpodioRootIO")
from ROOT import podio
Expand Down
47 changes: 25 additions & 22 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env python

from __future__ import print_function
from past.builtins import xrange
from six import iteritems
from six import iterkeys

from collections import OrderedDict

import os
Expand Down Expand Up @@ -50,8 +55,8 @@ def configure_clang_format(self, apply):
try:
cformat_exe = subprocess.check_output(['which', 'clang-format']).strip()
except subprocess.CalledProcessError:
print "ERROR: Cannot find clang-format executable"
print " Please make sure it is in the PATH."
print("ERROR: Cannot find clang-format executable")
print(" Please make sure it is in the PATH.")
self.clang_format = []
return
self.clang_format = [cformat_exe, "-style=file", "-fallback-style=llvm"]
Expand All @@ -68,14 +73,14 @@ def process(self):

def process_components(self, content):
self.requested_classes += content.keys()
for name, components in content.iteritems():
for name, components in iteritems(content):
self.create_component(name, components["Members"])

def process_datatypes(self, content):
for name in content.iterkeys():
for name in iterkeys(content):
self.requested_classes.append(name)
self.requested_classes.append("%sData" % name)
for name, components in content.iteritems():
for name, components in iteritems(content):
self.create_data(name, components)
self.create_class(name, components)
self.create_collection(name, components)
Expand All @@ -85,21 +90,21 @@ def process_datatypes(self, content):
def print_report(self):
if not self.verbose:
return
pkl = open(os.path.join(thisdir, "figure.txt"))
pkl = open(os.path.join(thisdir, "figure.txt"), 'rb')
figure = pickle.load(pkl)
text = _text_ % (self.yamlfile,
len(self.created_classes),
self.install_dir
)
cntr = 0
print
print()
for figline, summaryline in zip(figure, text.splitlines()):
cntr += 1
print figline + summaryline
print(figline + summaryline)
for i in xrange(cntr, len(figure)):
print figure[i]
print " 'Homage to the Square' - Josef Albers"
print
print(figure[i])
print(" 'Homage to the Square' - Josef Albers")
print()

def get_template(self, filename):
templatefile = os.path.join(self.template_dir, filename)
Expand Down Expand Up @@ -259,7 +264,7 @@ def create_class(self, classname, definition):
forward_declarations_namespace[mnamespace] += ["class Const%s;\n" %(klassname)]
includes_cc.add(self._build_include(klassname))

for nsp in forward_declarations_namespace.iterkeys():
for nsp in iterkeys(forward_declarations_namespace):
if nsp != "":
forward_declarations += "namespace %s {\n" % nsp
forward_declarations += "".join(forward_declarations_namespace[nsp])
Expand Down Expand Up @@ -472,17 +477,17 @@ def create_class(self, classname, definition):
extracode = ""
constextracode_declarations = ""
constextracode = ""
if definition.has_key("ExtraCode"):
if "ExtraCode" in definition:
extra = definition["ExtraCode"]
if( extra.has_key("declaration")):
if "declaration" in extra:
extracode_declarations = extra["declaration"].replace("{name}",rawclassname)
if( extra.has_key("implementation")):
if "implementation" in extra:
extracode = extra["implementation"].replace("{name}",rawclassname)
if( extra.has_key("const_declaration")):
if "const_declaration" in extra:
constextracode_declarations = extra["const_declaration"].replace("{name}","Const"+rawclassname)
extracode_declarations += "\n"
extracode_declarations += extra["const_declaration"]
if( extra.has_key("const_implementation")):
if "const_implementation" in extra:
constextracode = extra["const_implementation"].replace("{name}","Const"+rawclassname)
extracode += "\n"
extracode += extra["const_implementation"].replace("{name}",rawclassname)
Expand Down Expand Up @@ -582,14 +587,12 @@ def create_collection(self, classname, definition):
if t in comps.keys():
nCompMem = 0
compMemStr += ' ['
#print " found component: " , name , t , comps[ t ] , " #members: " , nCompMem
for cm in comps[t]["Members"]:
if cm != 'ExtraCode':
nCompMem += 1
compMemStr += ('%s,' % cm )
compMemStr += ']'
colW *= nCompMem
#print " found component: " , name , t , comps[ t ] , " #members: " , nCompMem
colName = name[:colW-2]
colName += compMemStr
colName +=":"
Expand Down Expand Up @@ -876,7 +879,7 @@ def create_component(self, classname, components):
else:
members += " ::%s::%s %s;\n" %(mnamespace, klassname, name)
self.component_members[classname].append(["::%s::%s" % (mnamespace, klassname), name])
if self.reader.components.has_key(klass):
if klass in self.reader.components:
includes.add(self._build_include(klassname))
if "std::array" in klass:
includes.add("#include <array>")
Expand Down Expand Up @@ -956,7 +959,7 @@ def create_obj(self, classname, definition):
set_relations += implementations["set_relations"].format(name=name, klass=klassWithQualifier)
delete_singlerelations+="\t\tif (m_%s != nullptr) delete m_%s;\n" % (name, name)

for nsp in forward_declarations_namespace.iterkeys():
for nsp in iterkeys(forward_declarations_namespace):
if nsp != "":
forward_declarations += "namespace %s {" % nsp
forward_declarations += "".join(forward_declarations_namespace[nsp])
Expand Down Expand Up @@ -1143,4 +1146,4 @@ def _join_set(aSet):
gen.process()
if gen.verbose:
for warning in gen.warnings:
print warning
print(warning)
9 changes: 5 additions & 4 deletions python/podio_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

from collections import OrderedDict
from six import iteritems

def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
class OrderedLoader(Loader):
Expand Down Expand Up @@ -132,7 +133,7 @@ def check_component(self, name, definition):
"which is not allowed in a component!")

def check_components(self, components):
for klassname, value in components.iteritems():
for klassname, value in iteritems(components):
self.check_component(klassname, value)


Expand Down Expand Up @@ -161,11 +162,11 @@ def read(self):
validator = ClassDefinitionValidator(content)
if "components" in content.keys():
validator.check_components(content["components"])
for klassname, value in content["components"].iteritems():
for klassname, value in iteritems(content["components"]):
component = {"Members": value}
self.components[klassname] = component
if "datatypes" in content:
for klassname, value in content["datatypes"].iteritems():
for klassname, value in iteritems(content["datatypes"]):
validator.check_datatype(klassname, value)
datatype = {}
datatype["Description"] = value["Description"]
Expand All @@ -191,5 +192,5 @@ def read(self):
value["ConstExtraCode"])
self.datatypes[klassname] = datatype
if "options" in content.keys():
for option, value in content["options"].iteritems():
for option, value in iteritems(content["options"]):
self.options[option] = value
4 changes: 2 additions & 2 deletions python/test_EventStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_chain(self):
numbers.append(evinfo[0].Number())
self.assertEqual(iev+1, 2*events.GetEntries())
# testing that numbers is [0, .. 1999, 0, .. 1999]
self.assertEqual(numbers, range(events.GetEntries())*2)
self.assertEqual(numbers, list(range(events.GetEntries()))*2)
# trying to go to an event beyond the last one
self.assertRaises(ValueError, self.store.__getitem__,
4001)
Expand All @@ -116,6 +116,6 @@ def test_no_file(self):
# creating example file for the tests
if not os.path.isfile('example.root'):
write = '{podio}/tests/write'.format(podio=os.environ['PODIO'])
print write
print(write)
call(write)
unittest.main()

0 comments on commit 86a8559

Please sign in to comment.