Skip to content

Commit

Permalink
Add pre-commit Ruff and Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Feb 1, 2024
1 parent 9812f6f commit d803d48
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 212 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: code-quality

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install dependencies
run: |
pip install ".[dev]"
pre-commit install
- name: run pre-commit
run: |
pre-commit run --all-files
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: "https://github.com/pre-commit/mirrors-prettier"
rev: "v3.1.0"
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.9"
hooks:
- id: ruff
stages: [commit]
- id: ruff-format
stages: [commit]
8 changes: 2 additions & 6 deletions .releash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
filenames_python = glob.glob("*")
filenames_python.remove("js")
# filenames_python.remove('notebooks')
package_python = add_package(
".", "py", distribution_name="ipywebrtc", filenames=filenames_python
)
package_python = add_package(".", "py", distribution_name="ipywebrtc", filenames=filenames_python)

version_python = VersionSource(package_python, "{path}/ipywebrtc/_version.py")
gittag = ReleaseTargetGitTagVersion(version_source=version_python)

package_python.version_source = version_python
package_python.version_targets.append(
VersionTarget(package_python, "{path}/ipywebrtc/_version.py")
)
package_python.version_targets.append(VersionTarget(package_python, "{path}/ipywebrtc/_version.py"))

package_python.release_targets.append(gittag)
package_python.release_targets.append(ReleaseTargetSourceDist(package_python))
Expand Down
3 changes: 2 additions & 1 deletion dev_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ dependencies:
- jupyterlab=3
- notebook
- ipywidgets>=7.6
- flake8
- ruff
- nbsphinx
- sphinx
- sphinx_rtd_theme
- pygments==2.6.1
- jupyter-sphinx
- precommit
36 changes: 18 additions & 18 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: ipywebrtc_docs
channels:
- conda-forge
- defaults
- conda-forge
- defaults
dependencies:
- ipywidgets
- nbformat
- nbsphinx
- notebook>=4.2
- python=3.6
- sphinx>=1.4.6
- sphinx_rtd_theme
- tornado
- python-dateutil
- recommonmark
- traitlets
- ipywidgets
- nodejs
- pip
- pip:
- ipywebrtc
- ipywidgets
- nbformat
- nbsphinx
- notebook>=4.2
- python=3.6
- sphinx>=1.4.6
- sphinx_rtd_theme
- tornado
- python-dateutil
- recommonmark
- traitlets
- ipywidgets
- nodejs
- pip
- pip:
- ipywebrtc
90 changes: 52 additions & 38 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,50 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinx.ext.napoleon', # support for NumPy-style docstrings
'nbsphinx',
]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
"sphinx.ext.napoleon", # support for NumPy-style docstrings
"nbsphinx",
]

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

napoleon_use_rtype = False

html_extra_path = ['ipyvolume.mp4', 'Big.Buck.Bunny.mp3', 'Big.Buck.Bunny.mp4']
html_extra_path = ["ipyvolume.mp4", "Big.Buck.Bunny.mp3", "Big.Buck.Bunny.mp4"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = ['.rst']
source_suffix = [".rst"]

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

# General information about the project.
project = 'ipywebrtc'
copyright = '2017, Maarten Breddels'
author = 'Maarten Breddels'
project = "ipywebrtc"
copyright = "2017, Maarten Breddels"
author = "Maarten Breddels"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# from https://github.com/ipython/ipywidgets/blob/master/docs/source/conf.py
_release = {}
exec(compile(open('../../ipywebrtc/_version.py').read(), '../../ipywebrtc/_version.py', 'exec'), _release)
version = '.'.join(map(str, _release['version_info'][:2]))
release = _release['__version__']
exec(
compile(
open("../../ipywebrtc/_version.py").read(),
"../../ipywebrtc/_version.py",
"exec",
),
_release,
)
version = ".".join(map(str, _release["version_info"][:2]))
release = _release["__version__"]

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -81,7 +89,7 @@
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -92,13 +100,14 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"
try:
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
except:
print("rtd theme not found")
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
except Exception:
print("rtd theme not found")

# 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 @@ -109,13 +118,13 @@
# 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']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ipywebrtcdoc'
htmlhelp_basename = "ipywebrtcdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -124,15 +133,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 @@ -142,19 +148,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ipywebrtc.tex', 'ipywebrtc Documentation',
'Maarten Breddels', 'manual'),
(
master_doc,
"ipywebrtc.tex",
"ipywebrtc Documentation",
"Maarten Breddels",
"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, 'ipywebrtc', 'ipywebrtc Documentation',
[author], 1)
]
man_pages = [(master_doc, "ipywebrtc", "ipywebrtc Documentation", [author], 1)]


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

nbsphinx_allow_errors = True
2 changes: 1 addition & 1 deletion ipywebrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from IPython.display import display

from ._version import __version__, version_info # noqa
from .webrtc import * # noqa
from .webrtc import CameraStream, WebRTCRoomMqtt # noqa


def _prefix():
Expand Down
40 changes: 13 additions & 27 deletions ipywebrtc/webrtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ def from_download(cls, url, **kwargs):
ext = os.path.splitext(url)[1]
if ext:
format = ext[1:]
video = Video(
value=urlopen(url).read(), format=format, autoplay=False, controls=False
)
video = Video(value=urlopen(url).read(), format=format, autoplay=False, controls=False)
return cls(video=video, **kwargs)


Expand Down Expand Up @@ -265,9 +263,7 @@ def from_download(cls, url, **kwargs):
ext = os.path.splitext(url)[1]
if ext:
format = ext[1:]
audio = Audio(
value=urlopen(url).read(), format=format, autoplay=False, controls=False
)
audio = Audio(value=urlopen(url).read(), format=format, autoplay=False, controls=False)
return cls(audio=audio, **kwargs)


Expand Down Expand Up @@ -345,9 +341,9 @@ class Recorder(DOMWidget):
allow_none=True,
help="An instance of :class:`MediaStream` that is the source for recording.",
).tag(sync=True, **widget_serialization)
filename = Unicode(
"record", help="The filename used for downloading or auto saving."
).tag(sync=True)
filename = Unicode("record", help="The filename used for downloading or auto saving.").tag(
sync=True
)
format = Unicode("webm", help="The format of the recording.").tag(sync=True)
recording = Bool(
False,
Expand Down Expand Up @@ -453,9 +449,9 @@ class VideoRecorder(Recorder):
_view_name = Unicode("VideoRecorderView").tag(sync=True)

video = Instance(Video).tag(sync=True, **widget_serialization)
codecs = Unicode(
"", help='Optional codecs for the recording, e.g. "vp8" or "vp9, opus".'
).tag(sync=True)
codecs = Unicode("", help='Optional codecs for the recording, e.g. "vp8" or "vp9, opus".').tag(
sync=True
)

def __init__(
self,
Expand Down Expand Up @@ -526,9 +522,7 @@ class AudioRecorder(Recorder):
_view_name = Unicode("AudioRecorderView").tag(sync=True)

audio = Instance(Audio).tag(sync=True, **widget_serialization)
codecs = Unicode("", help='Optional codecs for the recording, e.g. "opus".').tag(
sync=True
)
codecs = Unicode("", help='Optional codecs for the recording, e.g. "opus".').tag(sync=True)

def __init__(
self,
Expand Down Expand Up @@ -597,12 +591,8 @@ class WebRTCPeer(DOMWidget):
_view_module_version = Unicode(semver_range_frontend).tag(sync=True)
_model_module_version = Unicode(semver_range_frontend).tag(sync=True)

stream_local = Instance(MediaStream, allow_none=True).tag(
sync=True, **widget_serialization
)
stream_remote = Instance(MediaStream, allow_none=True).tag(
sync=True, **widget_serialization
)
stream_local = Instance(MediaStream, allow_none=True).tag(sync=True, **widget_serialization)
stream_remote = Instance(MediaStream, allow_none=True).tag(sync=True, **widget_serialization)
id_local = Unicode("").tag(sync=True)
id_remote = Unicode("").tag(sync=True)
connected = Bool(False, read_only=True).tag(sync=True)
Expand All @@ -623,14 +613,10 @@ class WebRTCRoom(DOMWidget):
_model_module_version = Unicode(semver_range_frontend).tag(sync=True)

room = Unicode("room").tag(sync=True)
stream = Instance(MediaStream, allow_none=True).tag(
sync=True, **widget_serialization
)
stream = Instance(MediaStream, allow_none=True).tag(sync=True, **widget_serialization)
room_id = Unicode(read_only=True).tag(sync=True)
nickname = Unicode("anonymous").tag(sync=True)
peers = List(Instance(WebRTCPeer), [], allow_none=False).tag(
sync=True, **widget_serialization
)
peers = List(Instance(WebRTCPeer), [], allow_none=False).tag(sync=True, **widget_serialization)
streams = List(Instance(MediaStream), [], allow_none=False).tag(
sync=True, **widget_serialization
)
Expand Down
4 changes: 2 additions & 2 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
WebRTC for Jupyter notebook/lab

Package Install
---------------
## Package Install

**Prerequisites**

- [node](http://nodejs.org/)

```bash
Expand Down
Loading

0 comments on commit d803d48

Please sign in to comment.