Skip to content

Commit

Permalink
Add black formatting to the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bmerry committed Aug 2, 2023
1 parent dadf9ad commit a958c62
Show file tree
Hide file tree
Showing 33 changed files with 2,294 additions and 1,658 deletions.
54 changes: 28 additions & 26 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@
#
# import os
# import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

# Build doxygen first on readthedocs
rtd = os.environ.get('READTHEDOCS') == 'True'
rtd = os.environ.get("READTHEDOCS") == "True"
if rtd:
subprocess.check_call(['doxygen'])
subprocess.check_call(["doxygen"])
# ReadTheDocs can't build the extension (no Boost), so we have to mock it
# See http://docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
autodoc_mock_imports = ['spead2._spead2']
autodoc_mock_imports = ["spead2._spead2"]

# -- Project information -----------------------------------------------------

project = 'spead2'
copyright = '2015–2021, National Research Foundation (SARAO)'
author = 'National Research Foundation (SARAO)'
project = "spead2"
copyright = "2015–2021, National Research Foundation (SARAO)"
author = "National Research Foundation (SARAO)"


def get_version():
globals_ = {}
root = os.path.dirname(os.path.dirname(__file__))
with open(os.path.join(root, 'src', 'spead2', '_version.py')) as f:
with open(os.path.join(root, "src", "spead2", "_version.py")) as f:
code = f.read()
exec(code, globals_)
release = globals_['__version__']
match = re.match('^(\d+)\.(\d+)', release)
release = globals_["__version__"]
match = re.match("^(\d+)\.(\d+)", release)
return match.group(0), release


version, release = get_version()

# -- General configuration ---------------------------------------------------
Expand All @@ -53,40 +55,40 @@ def get_version():
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx_rtd_theme',
'breathe'
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx_rtd_theme",
"breathe",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

breathe_projects = {'spead2': './doxygen/xml'}
breathe_default_project = 'spead2'
breathe_projects = {"spead2": "./doxygen/xml"}
breathe_default_project = "spead2"

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
'numba': ('https://numba.readthedocs.io/en/latest/', None)
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"numba": ("https://numba.readthedocs.io/en/latest/", None),
}

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
25 changes: 8 additions & 17 deletions examples/recv_chunk_group_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,30 @@ def chunk_place(data_ptr, data_size):
def main():
NUM_STREAMS = 2
MAX_CHUNKS = 4
place_callback = scipy.LowLevelCallable(
chunk_place.ctypes,
signature='void (void *, size_t)'
)
place_callback = scipy.LowLevelCallable(chunk_place.ctypes, signature="void (void *, size_t)")
chunk_config = spead2.recv.ChunkStreamConfig(
items=[spead2.HEAP_CNT_ID, spead2.HEAP_LENGTH_ID],
max_chunks=MAX_CHUNKS,
place=place_callback)
place=place_callback,
)
group_config = spead2.recv.ChunkStreamGroupConfig(max_chunks=MAX_CHUNKS)
data_ring = spead2.recv.ChunkRingbuffer(MAX_CHUNKS)
free_ring = spead2.recv.ChunkRingbuffer(MAX_CHUNKS)
group = spead2.recv.ChunkStreamRingGroup(group_config, data_ring, free_ring)
for _ in range(NUM_STREAMS):
group.emplace_back(
spead2.ThreadPool(),
spead2.recv.StreamConfig(),
chunk_config
)
group.emplace_back(spead2.ThreadPool(), spead2.recv.StreamConfig(), chunk_config)
for _ in range(MAX_CHUNKS):
chunk = spead2.recv.Chunk(
present=np.empty(HEAPS_PER_CHUNK, np.uint8),
data=np.empty(CHUNK_PAYLOAD_SIZE, np.uint8)
present=np.empty(HEAPS_PER_CHUNK, np.uint8), data=np.empty(CHUNK_PAYLOAD_SIZE, np.uint8)
)
group.add_free_chunk(chunk)
for i in range(NUM_STREAMS):
group[i].add_udp_reader(8888 + i, buffer_size=1024 * 1024, bind_hostname='127.0.0.1')
group[i].add_udp_reader(8888 + i, buffer_size=1024 * 1024, bind_hostname="127.0.0.1")
for chunk in data_ring:
n_present = np.sum(chunk.present)
print(
f"Received chunk {chunk.chunk_id} with "
f"{n_present} / {HEAPS_PER_CHUNK} heaps")
print(f"Received chunk {chunk.chunk_id} with {n_present} / {HEAPS_PER_CHUNK} heaps")
group.add_free_chunk(chunk)


if __name__ == '__main__':
if __name__ == "__main__":
main()
26 changes: 9 additions & 17 deletions examples/recv_chunk_ring_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,28 @@ def chunk_place(data_ptr, data_size):

def main():
MAX_CHUNKS = 4
place_callback = scipy.LowLevelCallable(
chunk_place.ctypes,
signature='void (void *, size_t)'
)
place_callback = scipy.LowLevelCallable(chunk_place.ctypes, signature="void (void *, size_t)")
chunk_config = spead2.recv.ChunkStreamConfig(
items=[spead2.HEAP_CNT_ID, spead2.HEAP_LENGTH_ID],
max_chunks=MAX_CHUNKS,
place=place_callback)
place=place_callback,
)
data_ring = spead2.recv.ChunkRingbuffer(MAX_CHUNKS)
free_ring = spead2.recv.ChunkRingbuffer(MAX_CHUNKS)
stream = spead2.recv.ChunkRingStream(
spead2.ThreadPool(),
spead2.recv.StreamConfig(),
chunk_config,
data_ring,
free_ring)
spead2.ThreadPool(), spead2.recv.StreamConfig(), chunk_config, data_ring, free_ring
)
for i in range(MAX_CHUNKS):
chunk = spead2.recv.Chunk(
present=np.empty(HEAPS_PER_CHUNK, np.uint8),
data=np.empty(CHUNK_PAYLOAD_SIZE, np.uint8)
present=np.empty(HEAPS_PER_CHUNK, np.uint8), data=np.empty(CHUNK_PAYLOAD_SIZE, np.uint8)
)
stream.add_free_chunk(chunk)
stream.add_udp_reader(8888, buffer_size=1024 * 1024, bind_hostname='127.0.0.1')
stream.add_udp_reader(8888, buffer_size=1024 * 1024, bind_hostname="127.0.0.1")
for chunk in data_ring:
n_present = np.sum(chunk.present)
print(
f"Received chunk {chunk.chunk_id} with "
f"{n_present} / {HEAPS_PER_CHUNK} heaps")
print(f"Received chunk {chunk.chunk_id} with {n_present} / {HEAPS_PER_CHUNK} heaps")
stream.add_free_chunk(chunk)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions examples/test_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
thread_pool = spead2.ThreadPool()
stream = spead2.recv.Stream(
thread_pool,
spead2.recv.StreamConfig(memory_allocator=spead2.MemoryPool(16384, 26214400, 12, 8))
spead2.recv.StreamConfig(memory_allocator=spead2.MemoryPool(16384, 26214400, 12, 8)),
)
del thread_pool
if 0:
with open('junkspeadfile', 'rb') as f:
with open("junkspeadfile", "rb") as f:
text = f.read()
stream.add_buffer_reader(text)
else:
Expand Down
5 changes: 3 additions & 2 deletions examples/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

thread_pool = spead2.ThreadPool()
stream = spead2.send.UdpStream(
thread_pool, [("127.0.0.1", 8888)], spead2.send.StreamConfig(rate=1e7))
thread_pool, [("127.0.0.1", 8888)], spead2.send.StreamConfig(rate=1e7)
)
del thread_pool

shape = (40, 50)
ig = spead2.send.ItemGroup(flavour=spead2.Flavour(4, 64, 48, 0))
item = ig.add_item(0x1234, 'foo', 'a foo item', shape=shape, dtype=np.int32)
item = ig.add_item(0x1234, "foo", "a foo item", shape=shape, dtype=np.int32)
item.value = np.zeros(shape, np.int32)
stream.send_heap(ig.get_heap())
stream.send_heap(ig.get_end())
10 changes: 4 additions & 6 deletions examples/test_send_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@

thread_pool = spead2.ThreadPool()
stream = spead2.send.asyncio.UdpStream(
thread_pool, [("127.0.0.1", 8888)], spead2.send.StreamConfig(rate=1e7))
thread_pool, [("127.0.0.1", 8888)], spead2.send.StreamConfig(rate=1e7)
)
del thread_pool # Make sure this doesn't crash anything

shape = (40, 50)
ig = spead2.send.ItemGroup(flavour=spead2.Flavour(4, 64, 48, 0))
item = ig.add_item(0x1234, 'foo', 'a foo item', shape=shape, dtype=np.int32)
item = ig.add_item(0x1234, "foo", "a foo item", shape=shape, dtype=np.int32)
item.value = np.zeros(shape, np.int32)
futures = [
stream.async_send_heap(ig.get_heap()),
stream.async_send_heap(ig.get_end())
]
futures = [stream.async_send_heap(ig.get_heap()), stream.async_send_heap(ig.get_end())]
# Delete things to check that there are no refcounting bugs
del ig
del stream
Expand Down
Loading

0 comments on commit a958c62

Please sign in to comment.