Skip to content

Commit

Permalink
Merge pull request #41 from xhochy/pre-commit-hooks
Browse files Browse the repository at this point in the history
Add some pre-commit hooks
  • Loading branch information
xhochy authored Aug 18, 2023
2 parents ae67d42 + 937a0cd commit 445e69f
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Taken directly from https://github.com/ambv/black/blob/master/.flake8
[flake8]
ignore = E203, E266, E501, W503, C901, D104, D100
max-line-length = 88
max-complexity = 18
select = B,C,E,F,W,T4,B9
per-file-ignores =
tests/**:D101,D102,D103
docstring-convention = numpy
32 changes: 32 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push, pull_request]

# Automatically stop old builds on the same branch/PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -el {0}

jobs:
pre-commit-checks:
name: "Linux - pre-commit checks - Python 3.10"
timeout-minutes: 30
runs-on: ubuntu-latest
env:
PRE_COMMIT_USE_MICROMAMBA: 1
steps:
- name: Checkout branch
uses: actions/[email protected]
- name: Set up micromamba
uses: mamba-org/setup-micromamba@875557da4ee020f18df03b8910a42203fbf02da1
- name: Add micromamba to GITHUB_PATH
run: echo "${HOME}/micromamba-bin" >> "$GITHUB_PATH"
- name: Install Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Run pre-commit checks
uses: pre-commit/[email protected]
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: https://github.com/Quantco/pre-commit-mirrors-black
rev: 23.7.0
hooks:
- id: black-conda
args:
- --safe
- --target-version=py38
- repo: https://github.com/Quantco/pre-commit-mirrors-flake8
rev: 6.1.0
hooks:
- id: flake8-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-isort
rev: 5.12.0
hooks:
- id: isort-conda
additional_dependencies: [-c, conda-forge, toml=0.10.2]
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
rev: "1.5.1"
hooks:
- id: mypy-conda
additional_dependencies:
- -c
- conda-forge
- types-mock
- types-setuptools
- types-redis
- types-boto
- boto3-stubs
- repo: https://github.com/Quantco/pre-commit-mirrors-pyupgrade
rev: 3.10.1
hooks:
- id: pyupgrade-conda
args:
- --py38-plus
11 changes: 6 additions & 5 deletions jupyter_vscode_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Callable, List, Dict, Any

import os
import shutil
from typing import Any, Callable, Dict, List


def _get_inner_vscode_cmd() -> List[str]:
Expand Down Expand Up @@ -30,14 +29,16 @@ def _get_inner_openvscode_cmd() -> List[str]:

def _get_cmd_factory(executable: str) -> Callable:
if executable not in _CODE_EXECUTABLE_INNER_CMD_MAP:
raise KeyError(f"'{executable}' is not one of {_CODE_EXECUTABLE_INNER_CMD_MAP.keys()}.")

raise KeyError(
f"'{executable}' is not one of {_CODE_EXECUTABLE_INNER_CMD_MAP.keys()}."
)

get_inner_cmd = _CODE_EXECUTABLE_INNER_CMD_MAP[executable]

def _get_cmd(port: int) -> List[str]:
if not shutil.which(executable):
raise FileNotFoundError(f"Can not find {executable} in PATH")

# Start vscode in CODE_WORKINGDIR env variable if set
# If not, start in 'current directory', which is $REPO_DIR in mybinder
# but /home/jovyan (or equivalent) in JupyterHubs
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tool.black]
exclude = '''
/(
\.eggs
| \.git
| \.venv
| build
| dist
)/
'''

[tool.isort]
profile = "black"
line_length = 88
known_first_party = "{{ project_slug }}"
skip_glob = '\.eggs/*,\.git/*,\.venv/*,build/*,dist/*'
default_section = 'THIRDPARTY'

[tool.mypy]
python_version = '3.8'
ignore_missing_imports = true
no_implicit_optional = true
check_untyped_defs = true
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import setuptools


with open("README.md", encoding="utf8") as f:
readme = f.read()

Expand All @@ -17,11 +16,11 @@
packages=setuptools.find_packages(),
keywords=["Jupyter", "vscode", "vs code", "editor"],
classifiers=["Framework :: Jupyter"],
install_requires=[
'jupyter-server-proxy'
],
install_requires=["jupyter-server-proxy"],
entry_points={
"jupyter_serverproxy_servers": ["vscode = jupyter_vscode_proxy:setup_vscode",]
"jupyter_serverproxy_servers": [
"vscode = jupyter_vscode_proxy:setup_vscode",
]
},
package_data={"jupyter_vscode_proxy": ["icons/*"]},
project_urls={
Expand Down

0 comments on commit 445e69f

Please sign in to comment.