Skip to content

Commit

Permalink
Add pytest opts and use isort (#762)
Browse files Browse the repository at this point in the history
* add pytest opts and use isort

* fix spelling error
  • Loading branch information
blink1073 committed Mar 28, 2022
1 parent 4087b98 commit 7239666
Show file tree
Hide file tree
Showing 86 changed files with 329 additions and 444 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/python-tests.yml
Expand Up @@ -57,12 +57,12 @@ jobs:
- name: Run the tests
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }}
run: |
args="-vv -raXs --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --durations 10 --color=yes --cov-fail-under 70"
args="-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --cov-fail-under 70"
python -m pytest $args || python -m pytest $args --lf
- name: Run the tests on pypy and windows
if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(matrix.os, 'windows') }}
run: |
python -m pytest -vv -raXs || python -m pytest -vv -raXs --lf
python -m pytest -vv || python -m pytest -vv --lf
- name: Coverage
run: |
codecov
Expand All @@ -88,7 +88,7 @@ jobs:
pip install -r doc-requirements.txt
make html SPHINXOPTS="-W"
test_miniumum_versions:
test_minimum_versions:
name: Test Minimum Versions
timeout-minutes: 20
runs-on: ubuntu-latest
Expand All @@ -102,8 +102,7 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1
- name: Run the unit tests
run: |
args="-vv -raXs --durations 10 --color=yes"
pytest $args || pytest $args --lf
pytest -vv || pytest -vv --lf
test_prereleases:
name: Test Prereleases
Expand All @@ -123,8 +122,7 @@ jobs:
pip check
- name: Run the tests
run: |
args="-vv -raXs --durations 10 --color=yes"
pytest $args || pytest $args --lf
pytest -vv || pytest -vv --lf
make_sdist:
name: Make SDist
Expand Down Expand Up @@ -164,5 +162,4 @@ jobs:
- name: Run Test
run: |
cd sdist/test
args="-vv -raXs --durations 10 --color=yes"
pytest $args || pytest $args --lf
pytest -vv || pytest -vv --lf
40 changes: 21 additions & 19 deletions .pre-commit-config.yaml
@@ -1,15 +1,33 @@
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.7.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: reorder-python-imports
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
Expand All @@ -26,22 +44,6 @@ repos:
"flake8-implicit-str-concat==0.2.0",
]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.8.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Expand Up @@ -19,7 +19,6 @@

from pkg_resources import parse_version


HERE = osp.abspath(osp.dirname(__file__))


Expand Down
1 change: 0 additions & 1 deletion examples/simple/setup.py
Expand Up @@ -3,7 +3,6 @@
from jupyter_packaging import create_cmdclass
from setuptools import setup


VERSION = "0.0.1"


Expand Down
18 changes: 10 additions & 8 deletions examples/simple/simple_ext1/application.py
Expand Up @@ -2,14 +2,16 @@

from traitlets import Unicode

from .handlers import DefaultHandler
from .handlers import ErrorHandler
from .handlers import ParameterHandler
from .handlers import RedirectHandler
from .handlers import TemplateHandler
from .handlers import TypescriptHandler
from jupyter_server.extension.application import ExtensionApp
from jupyter_server.extension.application import ExtensionAppJinjaMixin
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin

from .handlers import (
DefaultHandler,
ErrorHandler,
ParameterHandler,
RedirectHandler,
TemplateHandler,
TypescriptHandler,
)

DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates")
Expand Down
6 changes: 4 additions & 2 deletions examples/simple/simple_ext1/handlers.py
@@ -1,6 +1,8 @@
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin
from jupyter_server.extension.handler import ExtensionHandlerMixin
from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin,
ExtensionHandlerMixin,
)
from jupyter_server.utils import url_escape


Expand Down
7 changes: 2 additions & 5 deletions examples/simple/simple_ext11/application.py
@@ -1,12 +1,9 @@
import os

from simple_ext1.application import SimpleApp1
from traitlets import Bool
from traitlets import observe
from traitlets import Unicode
from traitlets import Bool, Unicode, observe

from jupyter_server.serverapp import aliases
from jupyter_server.serverapp import flags
from jupyter_server.serverapp import aliases, flags

DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "./../simple_ext1/static")
DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "./../simple_ext1/templates")
Expand Down
9 changes: 3 additions & 6 deletions examples/simple/simple_ext2/application.py
Expand Up @@ -2,12 +2,9 @@

from traitlets import Unicode

from .handlers import ErrorHandler
from .handlers import IndexHandler
from .handlers import ParameterHandler
from .handlers import TemplateHandler
from jupyter_server.extension.application import ExtensionApp
from jupyter_server.extension.application import ExtensionAppJinjaMixin
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin

from .handlers import ErrorHandler, IndexHandler, ParameterHandler, TemplateHandler

DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates")
Expand Down
6 changes: 4 additions & 2 deletions examples/simple/simple_ext2/handlers.py
@@ -1,6 +1,8 @@
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin
from jupyter_server.extension.handler import ExtensionHandlerMixin
from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin,
ExtensionHandlerMixin,
)
from jupyter_server.utils import url_escape


Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/__init__.py
Expand Up @@ -13,7 +13,7 @@

del os

from ._version import version_info, __version__ # noqa
from ._version import __version__, version_info # noqa


def _cleanup():
Expand Down
4 changes: 1 addition & 3 deletions jupyter_server/_tz.py
Expand Up @@ -6,9 +6,7 @@
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from datetime import datetime
from datetime import timedelta
from datetime import tzinfo
from datetime import datetime, timedelta, tzinfo

# constant for zero offset
ZERO = timedelta(0)
Expand Down
7 changes: 2 additions & 5 deletions jupyter_server/auth/decorator.py
Expand Up @@ -3,15 +3,12 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from functools import wraps
from typing import Callable
from typing import Optional
from typing import Union
from typing import Callable, Optional, Union

from tornado.log import app_log
from tornado.web import HTTPError

from .utils import HTTP_METHOD_TO_AUTH_ACTION
from .utils import warn_disabled_authorization
from .utils import HTTP_METHOD_TO_AUTH_ACTION, warn_disabled_authorization


def authorized(
Expand Down
3 changes: 1 addition & 2 deletions jupyter_server/auth/login.py
Expand Up @@ -9,8 +9,7 @@
from tornado.escape import url_escape

from ..base.handlers import JupyterHandler
from .security import passwd_check
from .security import set_password
from .security import passwd_check, set_password


class LoginHandler(JupyterHandler):
Expand Down
4 changes: 1 addition & 3 deletions jupyter_server/auth/security.py
Expand Up @@ -12,9 +12,7 @@
from contextlib import contextmanager

from jupyter_core.paths import jupyter_config_dir
from traitlets.config import Config
from traitlets.config import ConfigFileNotFound
from traitlets.config import JSONFileConfigLoader
from traitlets.config import Config, ConfigFileNotFound, JSONFileConfigLoader

# Length of the salt in nr of hex chars, which implies salt_len * 4
# bits of randomness.
Expand Down
18 changes: 9 additions & 9 deletions jupyter_server/base/handlers.py
Expand Up @@ -18,9 +18,7 @@
import prometheus_client
from jinja2 import TemplateNotFound
from jupyter_core.paths import is_hidden
from tornado import escape
from tornado import httputil
from tornado import web
from tornado import escape, httputil, web
from tornado.log import app_log
from traitlets.config import Application

Expand All @@ -29,12 +27,14 @@
from jupyter_server._tz import utcnow
from jupyter_server.i18n import combine_translations
from jupyter_server.services.security import csp_report_uri
from jupyter_server.utils import ensure_async
from jupyter_server.utils import filefind
from jupyter_server.utils import url_escape
from jupyter_server.utils import url_is_absolute
from jupyter_server.utils import url_path_join
from jupyter_server.utils import urldecode_unix_socket_path
from jupyter_server.utils import (
ensure_async,
filefind,
url_escape,
url_is_absolute,
url_path_join,
urldecode_unix_socket_path,
)

# -----------------------------------------------------------------------------
# Top-level handlers
Expand Down
7 changes: 4 additions & 3 deletions jupyter_server/base/zmqhandlers.py
Expand Up @@ -14,15 +14,16 @@
from jupyter_client.jsonutil import json_default
except ImportError:
from jupyter_client.jsonutil import date_default as json_default

from jupyter_client.jsonutil import extract_dates
from jupyter_client.session import Session
from tornado import ioloop
from tornado import web
from tornado import ioloop, web
from tornado.websocket import WebSocketHandler

from .handlers import JupyterHandler
from jupyter_server.auth.utils import warn_disabled_authorization

from .handlers import JupyterHandler


def serialize_binary_message(msg):
"""serialize a message as a binary blob
Expand Down
3 changes: 1 addition & 2 deletions jupyter_server/config_manager.py
Expand Up @@ -11,8 +11,7 @@

from six import PY3
from traitlets.config import LoggingConfigurable
from traitlets.traitlets import Bool
from traitlets.traitlets import Unicode
from traitlets.traitlets import Bool, Unicode


def recursive_update(target, new):
Expand Down
20 changes: 6 additions & 14 deletions jupyter_server/extension/application.py
Expand Up @@ -2,26 +2,18 @@
import re
import sys

from jinja2 import Environment
from jinja2 import FileSystemLoader
from jupyter_core.application import JupyterApp
from jupyter_core.application import NoStart
from jinja2 import Environment, FileSystemLoader
from jupyter_core.application import JupyterApp, NoStart
from tornado.log import LogFormatter
from tornado.web import RedirectHandler
from traitlets import Any
from traitlets import Bool
from traitlets import default
from traitlets import Dict
from traitlets import HasTraits
from traitlets import List
from traitlets import Unicode
from traitlets import Any, Bool, Dict, HasTraits, List, Unicode, default
from traitlets.config import Config

from .handler import ExtensionHandlerMixin
from jupyter_server.serverapp import ServerApp
from jupyter_server.transutils import _i18n
from jupyter_server.utils import is_namespace_package
from jupyter_server.utils import url_path_join
from jupyter_server.utils import is_namespace_package, url_path_join

from .handler import ExtensionHandlerMixin

# -----------------------------------------------------------------------------
# Util functions and classes.
Expand Down
1 change: 0 additions & 1 deletion jupyter_server/extension/config.py
@@ -1,6 +1,5 @@
from jupyter_server.services.config.manager import ConfigManager


DEFAULT_SECTION_NAME = "jupyter_server_config"


Expand Down
19 changes: 7 additions & 12 deletions jupyter_server/extension/manager.py
Expand Up @@ -3,22 +3,17 @@
import traceback

from tornado.gen import multi
from traitlets import Any
from traitlets import Bool
from traitlets import default
from traitlets import Dict
from traitlets import HasTraits
from traitlets import Instance
from traitlets import observe
from traitlets import Unicode
from traitlets import Any, Bool, Dict, HasTraits, Instance, Unicode, default, observe
from traitlets import validate as validate_trait
from traitlets.config import LoggingConfigurable

from .config import ExtensionConfigManager
from .utils import ExtensionMetadataError
from .utils import ExtensionModuleNotFound
from .utils import get_loader
from .utils import get_metadata
from .utils import (
ExtensionMetadataError,
ExtensionModuleNotFound,
get_loader,
get_metadata,
)


class ExtensionPoint(HasTraits):
Expand Down

0 comments on commit 7239666

Please sign in to comment.