Skip to content

Commit

Permalink
format with black and add gh action to check black format was applied
Browse files Browse the repository at this point in the history
  • Loading branch information
attwad committed Jul 26, 2024
1 parent e7a4361 commit 30ef81c
Show file tree
Hide file tree
Showing 30 changed files with 635 additions and 451 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Lint with Black

on: [push, pull_request]

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --exit-zero --max-complexity=10 --statistics
- name: Check with mypy
run: mypy pythonosc examples
- name: Test with pytest
Expand Down
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ Thanks for contributing to this package!

Before sending a PR, please make sure you checked the [python test workflow](.github/workflows/python-test.yml) and ran it locally, either using [act](https://nektosact.com) or by executing the workflow actions yourself.

Please only send the PR once all tests pass and mypy is happy, thanks!
TL;DR:
- Format all code with Black
- Provide type annotations with mypy
- Write and run tests with pytest

Please only send the PR once all of the above is done, thanks!
60 changes: 30 additions & 30 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys

sys.path.insert(0, os.path.abspath(".."))

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

project = 'python-osc'
copyright = '2019, attwad'
author = 'attwad'
project = "python-osc"
copyright = "2019, attwad"
author = "attwad"

# The short X.Y version
version = ''
version = ""
# The full version, including alpha/beta/rc tags
release = '1.7.1'
release = "1.7.1"


# -- General configuration ---------------------------------------------------
Expand All @@ -41,24 +42,24 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
]

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

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -70,7 +71,7 @@
# 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"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
Expand All @@ -81,7 +82,7 @@
# 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"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -92,7 +93,7 @@
# 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"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -108,7 +109,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'python-oscdoc'
htmlhelp_basename = "python-oscdoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -117,15 +118,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -135,19 +133,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'python-osc.tex', 'python-osc Documentation',
'attwad', 'manual'),
(master_doc, "python-osc.tex", "python-osc Documentation", "attwad", "manual"),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'python-osc', 'python-osc Documentation',
[author], 1)
]
man_pages = [(master_doc, "python-osc", "python-osc Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -156,9 +150,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'python-osc', 'python-osc Documentation',
author, 'python-osc', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"python-osc",
"python-osc Documentation",
author,
"python-osc",
"One line description of project.",
"Miscellaneous",
),
]


Expand All @@ -177,7 +177,7 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------
4 changes: 3 additions & 1 deletion examples/async_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ async def loop():

async def init_main():
server = AsyncIOOSCUDPServer((ip, port), dispatcher, asyncio.get_event_loop())
transport, protocol = await server.create_serve_endpoint() # Create datagram endpoint and start serving
transport, protocol = (
await server.create_serve_endpoint()
) # Create datagram endpoint and start serving

await loop() # Enter main loop of program

Expand Down
4 changes: 2 additions & 2 deletions examples/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def set_filter(address: str, *args: List[Any]) -> None:
client = SimpleUDPClient("127.0.0.1", 1337)

# Send message and receive exactly one message (blocking)
client.send_message("/filter1", [1., 2.])
client.send_message("/filter1", [1.0, 2.0])
server.handle_request()

client.send_message("/filter8", [6., -2.])
client.send_message("/filter8", [6.0, -2.0])
server.handle_request()
23 changes: 17 additions & 6 deletions examples/simple_2way.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ def print_xy_fader_handler(unused_addr, args, value1, value2):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--serverip", default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--serverport", type=int, default=5005, help="The port the OSC Server is listening on")
parser.add_argument("--clientip", default="127.0.0.1", help="The ip of the OSC server")
parser.add_argument("--clientport", type=int, default=5006, help="The port the OSC Client is listening on")
parser.add_argument(
"--serverport",
type=int,
default=5005,
help="The port the OSC Server is listening on",
)
parser.add_argument(
"--clientip", default="127.0.0.1", help="The ip of the OSC server"
)
parser.add_argument(
"--clientport",
type=int,
default=5006,
help="The port the OSC Client is listening on",
)
args = parser.parse_args()

# listen to addresses and print changes in values
Expand All @@ -41,8 +53,7 @@ def print_xy_fader_handler(unused_addr, args, value1, value2):

def start_server(ip, port):
print("Starting Server")
server = osc_server.ThreadingOSCUDPServer(
(ip, port), dispatcher)
server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
print("Serving on {}".format(server.server_address))
thread = threading.Thread(target=server.serve_forever)
thread.start()
Expand All @@ -63,7 +74,7 @@ def random_values(client):
client.send_message("/1/fader2", random.random())
client.send_message("/1/fader1", random.random())
client.send_message("/1/xy1", [random.random(), random.random()])
time.sleep(.5)
time.sleep(0.5)


start_server(args.serverip, args.serverport)
Expand Down
9 changes: 5 additions & 4 deletions examples/simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This program sends 10 random values between 0.0 and 1.0 to the /filter address,
waiting for 1 seconds between each value.
"""

import argparse
import random
import time
Expand All @@ -11,10 +12,10 @@

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=5005,
help="The port the OSC server is listening on")
parser.add_argument("--ip", default="127.0.0.1", help="The ip of the OSC server")
parser.add_argument(
"--port", type=int, default=5005, help="The port the OSC server is listening on"
)
args = parser.parse_args()

client = udp_client.SimpleUDPClient(args.ip, args.port)
Expand Down
10 changes: 4 additions & 6 deletions examples/simple_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This program listens to several addresses, and prints some information about
received packets.
"""

import argparse
import math

Expand All @@ -23,18 +24,15 @@ def print_compute_handler(unused_addr, args, volume):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=5005, help="The port to listen on")
parser.add_argument("--ip", default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port", type=int, default=5005, help="The port to listen on")
args = parser.parse_args()

dispatcher = Dispatcher()
dispatcher.map("/filter", print)
dispatcher.map("/volume", print_volume_handler, "Volume")
dispatcher.map("/logvolume", print_compute_handler, "Log volume", math.log)

server = osc_server.ThreadingOSCUDPServer(
(args.ip, args.port), dispatcher)
server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
Loading

0 comments on commit 30ef81c

Please sign in to comment.