Skip to content

Commit

Permalink
Merge pull request #25 from consideRatio/pr/add-pre-commit
Browse files Browse the repository at this point in the history
maint: add pre-commit config
  • Loading branch information
yuvipanda committed Jan 24, 2023
2 parents 90adae2 + 9aced4c commit 01a4cc5
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 28 deletions.
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
graft jupyter_remote_desktop_proxy/share
graft jupyter_remote_desktop_proxy/share
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
55 changes: 32 additions & 23 deletions jupyter_remote_desktop_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
}
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
]
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -40,5 +39,5 @@
},
python_requires=">=3.6",
url="https://jupyter.org",
zip_safe=False
zip_safe=False,
)

0 comments on commit 01a4cc5

Please sign in to comment.