From 6146f374dea239cc565090341b0a65e02c6d1e8a Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 14 Jan 2023 23:18:31 +0100 Subject: [PATCH 1/4] maint: add pre-commit config --- .pre-commit-config.yaml | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..dda095c2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,77 @@ +# pre-commit is a tool to perform a predefined set of tasks manually and/or +# automatically before git commits are made. +# +# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level +# +# Common tasks +# +# - Run on all files: pre-commit run --all-files +# - Register git hooks: pre-commit install --install-hooks +# +repos: + # Autoformat: Python code, syntax patterns are modernized + - repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade + args: + - --py38-plus + + # Autoformat: Python code + - repo: https://github.com/PyCQA/autoflake + rev: v2.0.0 + hooks: + - id: autoflake + # args ref: https://github.com/PyCQA/autoflake#advanced-usage + args: + - --in-place + + # Autoformat: Python code + - repo: https://github.com/pycqa/isort + rev: 5.11.4 + hooks: + - id: isort + + # Autoformat: Python code + - repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black + + # Autoformat: markdown, yaml + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0-alpha.4 + hooks: + - id: prettier + + # Misc... + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + # ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available + hooks: + # Autoformat: Makes sure files end in a newline and only a newline. + - id: end-of-file-fixer + + # Autoformat: Sorts entries in requirements.txt. + - id: requirements-txt-fixer + + # Lint: Check for files with names that would conflict on a + # case-insensitive filesystem like MacOS HFS+ or Windows FAT. + - id: check-case-conflict + + # Lint: Checks that non-binary executables have a proper shebang. + - id: check-executables-have-shebangs + + # Lint: Python code + - repo: https://github.com/PyCQA/flake8 + rev: "6.0.0" + hooks: + - id: flake8 + +# Content here is mostly copied from other locations, so lets not make +# formatting changes in it. +exclude: share + +# pre-commit.ci config reference: https://pre-commit.ci/#configuration +ci: + autoupdate_schedule: monthly From 8ad2c00bfde88e786acfb3b6915404693e669ee7 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 14 Jan 2023 23:27:21 +0100 Subject: [PATCH 2/4] Add .flake8 config --- .flake8 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..698ad83b --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +# flake8 is used for linting Python code setup to automatically run with +# pre-commit. +# +# ref: https://flake8.pycqa.org/en/latest/user/configuration.html +# + +[flake8] +# E: style errors +# W: style warnings +# C: complexity +# D: docstring warnings (unused pydocstyle extension) +# F841: local variable assigned but never used +ignore = E, C, W, D, F841 From 9e3daca12bd4e503b7f5c8bedb33b382282a5db4 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 14 Jan 2023 23:27:36 +0100 Subject: [PATCH 3/4] Add autoflake/isort/black config in pyproject.toml --- pyproject.toml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..f9f42bce --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,35 @@ +# autoflake is used for autoformatting Python code +# +# ref: https://github.com/PyCQA/autoflake#readme +# +[tool.autoflake] +ignore-init-module-imports = true +remove-all-unused-imports = true +remove-duplicate-keys = true +remove-unused-variables = true + + +# isort is used for autoformatting Python code +# +# ref: https://pycqa.github.io/isort/ +# +[tool.isort] +profile = "black" + + +# black is used for autoformatting Python code +# +# ref: https://black.readthedocs.io/en/stable/ +# +[tool.black] +skip-string-normalization = true +# target-version should be all supported versions, see +# https://github.com/psf/black/issues/751#issuecomment-473066811 +target_version = [ + "py36", + "py37", + "py38", + "py39", + "py310", + "py311", +] From 9aced4cb6026e63681b23c86d3773e9ed359f4fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Jan 2023 12:00:11 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- LICENSE | 2 +- MANIFEST.in | 2 +- README.md | 1 + jupyter_remote_desktop_proxy/__init__.py | 55 ++++++++++++++---------- setup.py | 5 +-- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/LICENSE b/LICENSE index a3ed9eef..18b740d3 100644 --- a/LICENSE +++ b/LICENSE @@ -26,4 +26,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in index f3871ec4..f6439fe4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -graft jupyter_remote_desktop_proxy/share \ No newline at end of file +graft jupyter_remote_desktop_proxy/share diff --git a/README.md b/README.md index c217390d..84ad7fae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Jupyter Remote Desktop Proxy + [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterhub/jupyter-remote-desktop-proxy/HEAD?urlpath=desktop) Run XFCE (or other desktop environments) on Jupyter. diff --git a/jupyter_remote_desktop_proxy/__init__.py b/jupyter_remote_desktop_proxy/__init__.py index 856ff151..b3f77146 100644 --- a/jupyter_remote_desktop_proxy/__init__.py +++ b/jupyter_remote_desktop_proxy/__init__.py @@ -1,11 +1,11 @@ import os import shlex -from shutil import which import tempfile - +from shutil import which HERE = os.path.dirname(os.path.abspath(__file__)) + def setup_desktop(): # make a secure temporary directory for sockets # This is only readable, writeable & searchable by our uid @@ -22,33 +22,42 @@ def setup_desktop(): # Use bundled tigervnc vnc_args = [ os.path.join(HERE, 'share/tigervnc/bin/vncserver'), - '-rfbunixpath', sockets_path, - ] - socket_args = [ - '--unix-target', sockets_path + '-rfbunixpath', + sockets_path, ] + socket_args = ['--unix-target', sockets_path] - vnc_command = ' '.join(shlex.quote(p) for p in (vnc_args + [ - '-verbose', - '-xstartup', os.path.join(HERE, 'share/xstartup'), - '-geometry', '1680x1050', - '-SecurityTypes', 'None', - '-fg', - ':1', - ])) + vnc_command = ' '.join( + shlex.quote(p) + for p in ( + vnc_args + + [ + '-verbose', + '-xstartup', + os.path.join(HERE, 'share/xstartup'), + '-geometry', + '1680x1050', + '-SecurityTypes', + 'None', + '-fg', + ':1', + ] + ) + ) return { 'command': [ - 'websockify', '-v', - '--web', os.path.join(HERE, 'share/web/noVNC-1.2.0'), - '--heartbeat', '30', + 'websockify', + '-v', + '--web', + os.path.join(HERE, 'share/web/noVNC-1.2.0'), + '--heartbeat', + '30', '5901', - ] + socket_args + [ - '--', - '/bin/sh', '-c', - f'cd {os.getcwd()} && {vnc_command}' - ], + ] + + socket_args + + ['--', '/bin/sh', '-c', f'cd {os.getcwd()} && {vnc_command}'], 'port': 5901, 'timeout': 30, 'mappath': {'/': '/vnc_lite.html'}, - 'new_browser_window': True + 'new_browser_window': True, } diff --git a/setup.py b/setup.py index 769a3bc1..d2a4a22e 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ -from setuptools import setup, find_packages - +from setuptools import find_packages, setup with open("README.md") as f: readme = f.read() @@ -40,5 +39,5 @@ }, python_requires=">=3.6", url="https://jupyter.org", - zip_safe=False + zip_safe=False, )