Skip to content

Commit

Permalink
[format] Apply black formatting to all python sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jan 30, 2024
1 parent 41ab30e commit 883485f
Show file tree
Hide file tree
Showing 28 changed files with 4,470 additions and 3,812 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
max-line-length = 88
max-line-length = 99
extend-ignore = E203

per-file-ignores =
Expand Down
16 changes: 7 additions & 9 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"myst_parser",
"breathe",
"sphinx_copybutton",
]
]

source_suffix = {".rst": "restructuredtext", ".md": "markdown"}

Expand Down Expand Up @@ -89,7 +89,7 @@
"collapse_navigation": False,
"navigation_depth": 4,
"prev_next_buttons_location": None, # no navigation buttons
}
}

# -- Doxygen integration with Breathe -----------------------------------------

Expand All @@ -110,9 +110,7 @@

os.makedirs("_build/cpp", exist_ok=True)

subprocess.check_call(
["doxygen", "Doxyfile"], stdout=subprocess.PIPE, cwd=doc_dir, env=env
)
subprocess.check_call(["doxygen", "Doxyfile"], stdout=subprocess.PIPE, cwd=doc_dir, env=env)

cpp_api_index_target = doc_dir / "cpp_api/api.rst"

Expand All @@ -122,10 +120,10 @@
stdout=subprocess.PIPE,
cwd=doc_dir,
env=env,
)
)

if not cpp_api_index_target.exists():
shutil.copyfile(doc_dir / "cpp_api.rst", cpp_api_index_target)
shutil.copyfile(doc_dir / "cpp_api.rst", cpp_api_index_target)

print("Done with c++ API doc generation")

Expand All @@ -148,7 +146,7 @@
"../python",
"../*/*test_*.py", # exclude tests
"../python/podio_version.py", # exclude convenience module
]
)
]
)

print("Done with python API doc generation")
18 changes: 9 additions & 9 deletions python/podio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
# Try to load podio, this is equivalent to trying to load libpodio.so and will
# error if libpodio.so is not found but work if it's found
try:
from ROOT import podio # noqa: F401
from ROOT import podio # noqa: F401
except ImportError:
print("Unable to load podio, make sure that libpodio.so is in LD_LIBRARY_PATH")
raise
print("Unable to load podio, make sure that libpodio.so is in LD_LIBRARY_PATH")
raise

from .frame import Frame
from . import root_io, reading

try:
# We try to import the sio bindings which may fail if ROOT is not able to
# load the dictionary. In this case they have most likely not been built and
# we just move on
from . import sio_io
# We try to import the sio bindings which may fail if ROOT is not able to
# load the dictionary. In this case they have most likely not been built and
# we just move on
from . import sio_io
except ImportError:
pass
pass

__all__ = [
"__version__",
"Frame",
"root_io",
"sio_io",
"reading",
]
]
140 changes: 70 additions & 70 deletions python/podio/base_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,76 @@


class BaseReaderMixin:
"""Mixin class the defines the base interface of the readers.
"""Mixin class the defines the base interface of the readers.
The backend specific readers inherit from here and have to initialize the
following members:
- _reader: The actual reader that is able to read frames
"""

def __init__(self):
"""Initialize common members.
In inheriting classes this needs to be called **after** the _reader has been
setup.
"""
self._categories = tuple(s.data() for s in self._reader.getAvailableCategories())
if hasattr(self, '_is_legacy'):
self._is_legacy = getattr(self, '_is_legacy')
else:
self._is_legacy = False # by default assume we are not legacy

@property
def categories(self):
"""Get the available categories from this reader.
Returns:
tuple(str): The names of the available categories from this reader
"""
return self._categories

def get(self, category):
"""Get an iterator with access functionality for a given category.
Args:
category (str): The name of the desired category
Returns:
FrameCategoryIterator: The iterator granting access to all Frames of the
desired category
"""
return FrameCategoryIterator(self._reader, category)

@property
def is_legacy(self):
"""Whether this is a legacy file reader or not.
Returns:
bool: True if this is a legacy file reader
"""
return self._is_legacy

@property
def datamodel_definitions(self):
"""Get the available datamodel definitions from this reader.
Returns:
tuple(str): The names of the available datamodel definitions
The backend specific readers inherit from here and have to initialize the
following members:
- _reader: The actual reader that is able to read frames
"""
if self._is_legacy:
return ()
return tuple(n.c_str() for n in self._reader.getAvailableDatamodels())

def get_datamodel_definition(self, edm_name):
"""Get the datamodel definition as JSON string.

Args:
str: The name of the datamodel
Returns:
str: The complete model definition in JSON format. Use, e.g. json.loads
to convert it into a python dictionary.
"""
if self._is_legacy:
return ""
return self._reader.getDatamodelDefinition(edm_name).data()
def __init__(self):
"""Initialize common members.
In inheriting classes this needs to be called **after** the _reader has been
setup.
"""
self._categories = tuple(s.data() for s in self._reader.getAvailableCategories())
if hasattr(self, "_is_legacy"):
self._is_legacy = getattr(self, "_is_legacy")
else:
self._is_legacy = False # by default assume we are not legacy

@property
def categories(self):
"""Get the available categories from this reader.
Returns:
tuple(str): The names of the available categories from this reader
"""
return self._categories

def get(self, category):
"""Get an iterator with access functionality for a given category.
Args:
category (str): The name of the desired category
Returns:
FrameCategoryIterator: The iterator granting access to all Frames of the
desired category
"""
return FrameCategoryIterator(self._reader, category)

@property
def is_legacy(self):
"""Whether this is a legacy file reader or not.
Returns:
bool: True if this is a legacy file reader
"""
return self._is_legacy

@property
def datamodel_definitions(self):
"""Get the available datamodel definitions from this reader.
Returns:
tuple(str): The names of the available datamodel definitions
"""
if self._is_legacy:
return ()
return tuple(n.c_str() for n in self._reader.getAvailableDatamodels())

def get_datamodel_definition(self, edm_name):
"""Get the datamodel definition as JSON string.
Args:
str: The name of the datamodel
Returns:
str: The complete model definition in JSON format. Use, e.g. json.loads
to convert it into a python dictionary.
"""
if self._is_legacy:
return ""
return self._reader.getDatamodelDefinition(edm_name).data()
73 changes: 38 additions & 35 deletions python/podio/base_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,53 @@


class AllWriters:
"""Class to manage all writers in the program
so that they can be properly finished at the end of the program
"""
writers = []
"""Class to manage all writers in the program
so that they can be properly finished at the end of the program
"""

writers = []

def add(self, writer):
"""Add a writer to the list of managed writers"""
self.writers.append(writer)
def add(self, writer):
"""Add a writer to the list of managed writers"""
self.writers.append(writer)

def finish(self):
"""Finish all managed writers"""
for writer in self.writers:
try:
writer._writer.finish() # pylint: disable=protected-access
except AttributeError:
pass
def finish(self):
"""Finish all managed writers"""
for writer in self.writers:
try:
writer._writer.finish() # pylint: disable=protected-access
except AttributeError:
pass


_all_writers = AllWriters()
atexit.register(_all_writers.finish)


class BaseWriterMixin:
"""Mixin class that defines the base interface of the writers.
The backend specific writers inherit from here and have to initialize the
following members:
"""Mixin class that defines the base interface of the writers.
- _writer: The actual writer that is able to write frames
"""
The backend specific writers inherit from here and have to initialize the
following members:
def __init__(self):
"""Initialize the writer"""
_all_writers.add(self)

def write_frame(self, frame, category, collections=None):
"""Write the given frame under the passed category, optionally limiting the
collections that are written.
Args:
frame (podio.frame.Frame): The Frame to write
category (str): The category name
collections (optional, default=None): The subset of collections to
write. If None, all collections are written
- _writer: The actual writer that is able to write frames
"""
# pylint: disable-next=protected-access
self._writer.writeFrame(frame._frame, category, collections or frame.getAvailableCollections())

def __init__(self):
"""Initialize the writer"""
_all_writers.add(self)

def write_frame(self, frame, category, collections=None):
"""Write the given frame under the passed category, optionally limiting the
collections that are written.
Args:
frame (podio.frame.Frame): The Frame to write
category (str): The category name
collections (optional, default=None): The subset of collections to
write. If None, all collections are written
"""
# pylint: disable=protected-access
self._writer.writeFrame(
frame._frame, category, collections or frame.getAvailableCollections()
)
Loading

0 comments on commit 883485f

Please sign in to comment.