Skip to content

Commit 150731d

Browse files
authored
Merge pull request #1118 from mathbunnyru/asalikhov/py_codestyle
Fix python codestyle
2 parents 74b0a01 + 2418c50 commit 150731d

File tree

14 files changed

+64
-46
lines changed

14 files changed

+64
-46
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = W605,W503,W504,H306,H238,H301,H202
3+
max-line-length = 120
4+
per-file-ignores =
5+
test/test_packages.py:E501

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ repos:
1515
rev: 2.0.0
1616
hooks:
1717
- id: bashate
18+
- repo: https://gitlab.com/pycqa/flake8
19+
rev: 3.8.3
20+
hooks:
21+
- id: flake8
22+
- repo: https://github.com/pre-commit/mirrors-autopep8
23+
rev: v1.5.4
24+
hooks:
25+
- id: autopep8
1826
- repo: local
1927
hooks:
2028
- id: hadolint

all-spark-notebook/test/test_spark_notebooks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def test_nbconvert(container, test_file):
2121
output_dir = "/tmp"
2222
timeout_ms = 600
2323
LOGGER.info(f"Test that {test_file} notebook can be executed ...")
24-
command = f"jupyter nbconvert --to markdown --ExecutePreprocessor.timeout={timeout_ms} --output-dir {output_dir} --execute {cont_data_dir}/{test_file}.ipynb"
24+
command = "jupyter nbconvert --to markdown " + \
25+
f"--ExecutePreprocessor.timeout={timeout_ms} " + \
26+
f"--output-dir {output_dir} " + \
27+
f"--execute {cont_data_dir}/{test_file}.ipynb"
2528
c = container.run(
2629
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
2730
tty=True,

base-notebook/jupyter_notebook_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import errno
88
import stat
99

10-
c = get_config()
10+
c = get_config() # noqa: F821
1111
c.NotebookApp.ip = '0.0.0.0'
1212
c.NotebookApp.port = 8888
1313
c.NotebookApp.open_browser = False
@@ -52,4 +52,4 @@
5252
# Change default umask for all subprocesses of the notebook server if set in
5353
# the environment
5454
if 'NB_UMASK' in os.environ:
55-
os.umask(int(os.environ['NB_UMASK'], 8))
55+
os.umask(int(os.environ['NB_UMASK'], 8))

base-notebook/test/test_container_options.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,28 @@ def test_nb_user_change(container):
7272
running_container = container.run(
7373
tty=True,
7474
user="root",
75-
environment=[f"NB_USER={nb_user}",
76-
"CHOWN_HOME=yes"],
75+
environment=[
76+
f"NB_USER={nb_user}",
77+
"CHOWN_HOME=yes"
78+
],
7779
working_dir=f"/home/{nb_user}",
7880
command=['start.sh', 'bash', '-c', 'sleep infinity']
7981
)
80-
81-
# Give the chown time to complete. Use sleep, not wait, because the
82+
83+
# Give the chown time to complete. Use sleep, not wait, because the
8284
# container sleeps forever.
8385
time.sleep(10)
8486
LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...")
8587
output = running_container.logs(stdout=True).decode("utf-8")
86-
assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}"
87-
88+
assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}"
89+
8890
LOGGER.info(f"Checking {nb_user} id ...")
8991
command = "id"
9092
expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)"
9193
cmd = running_container.exec_run(command, user=nb_user)
9294
output = cmd.output.decode("utf-8").strip("\n")
9395
assert output == expected_output, f"Bad user {output}, expected {expected_output}"
94-
96+
9597
LOGGER.info(f"Checking if {nb_user} owns his home folder ...")
9698
command = f'stat -c "%U %G" /home/{nb_user}/'
9799
expected_output = f"{nb_user} users"
@@ -105,10 +107,11 @@ def test_chown_extra(container):
105107
c = container.run(
106108
tty=True,
107109
user='root',
108-
environment=['NB_UID=1010',
109-
'NB_GID=101',
110-
'CHOWN_EXTRA=/opt/conda',
111-
'CHOWN_EXTRA_OPTS=-R',
110+
environment=[
111+
'NB_UID=1010',
112+
'NB_GID=101',
113+
'CHOWN_EXTRA=/opt/conda',
114+
'CHOWN_EXTRA_OPTS=-R'
112115
],
113116
command=['start.sh', 'bash', '-c', 'stat -c \'%n:%u:%g\' /opt/conda/LICENSE.txt']
114117
)
@@ -118,13 +121,14 @@ def test_chown_extra(container):
118121

119122

120123
def test_chown_home(container):
121-
"""Container should change the NB_USER home directory owner and
124+
"""Container should change the NB_USER home directory owner and
122125
group to the current value of NB_UID and NB_GID."""
123126
c = container.run(
124127
tty=True,
125128
user='root',
126-
environment=['CHOWN_HOME=yes',
127-
'CHOWN_HOME_OPTS=-R',
129+
environment=[
130+
'CHOWN_HOME=yes',
131+
'CHOWN_HOME_OPTS=-R'
128132
],
129133
command=['start.sh', 'bash', '-c', 'chown root:root /home/jovyan && ls -alsh /home']
130134
)

base-notebook/test/test_pandoc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import logging
55

6-
import pytest
7-
86
LOGGER = logging.getLogger(__name__)
97

108

@@ -17,4 +15,3 @@ def test_pandoc(container):
1715
logs = c.logs(stdout=True).decode("utf-8")
1816
LOGGER.debug(logs)
1917
assert "<p><strong>BOLD</strong></p>" in logs
20-

conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
LOGGER = logging.getLogger(__name__)
1515

16+
1617
@pytest.fixture(scope='session')
1718
def http_client():
1819
"""Requests session with retries and backoff."""
@@ -48,6 +49,7 @@ class TrackedContainer(object):
4849
**kwargs: dict, optional
4950
Default keyword arguments to pass to docker.DockerClient.containers.run
5051
"""
52+
5153
def __init__(self, docker_client, image_name, **kwargs):
5254
self.container = None
5355
self.docker_client = docker_client
@@ -78,7 +80,7 @@ def run(self, **kwargs):
7880
LOGGER.info(f"Running {self.image_name} with args {all_kwargs} ...")
7981
self.container = self.docker_client.containers.run(self.image_name, **all_kwargs)
8082
return self.container
81-
83+
8284
def remove(self):
8385
"""Kills and removes the tracked docker container."""
8486
if self.container:

datascience-notebook/test/test_julia.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
# Distributed under the terms of the Modified BSD License.
33
import logging
44

5-
import pytest
6-
75
LOGGER = logging.getLogger(__name__)
86

97

108
def test_julia(container):
119
"""Basic julia test"""
12-
LOGGER.info(f"Test that julia is correctly installed ...")
10+
LOGGER.info("Test that julia is correctly installed ...")
1311
running_container = container.run(
1412
tty=True, command=["start.sh", "bash", "-c", "sleep infinity"]
1513
)
16-
command = f"julia --version"
14+
command = "julia --version"
1715
cmd = running_container.exec_run(command)
1816
output = cmd.output.decode("utf-8")
1917
assert cmd.exit_code == 0, f"Command {command} failed {output}"

docs/conf.py

100644100755
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
# import sys
2222
# sys.path.insert(0, os.path.abspath('.'))
2323

24-
# For conversion from markdown to html
25-
import recommonmark.parser
26-
from recommonmark.transform import AutoStructify
27-
28-
2924
# -- General configuration ------------------------------------------------
3025

3126
# If your documentation needs a minimal Sphinx version, state it here.
@@ -199,4 +194,4 @@
199194
# -- Translation ----------------------------------------------------------
200195

201196
gettext_uuid = True
202-
locale_dirs = ['locale/']
197+
locale_dirs = ['locale/']

pyspark-notebook/test/test_spark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
import time
43
import logging
54

6-
import pytest
75

86
LOGGER = logging.getLogger(__name__)
97

8+
109
def test_spark_shell(container):
1110
"""Checking if Spark (spark-shell) is running properly"""
1211
c = container.run(
@@ -18,6 +17,7 @@ def test_spark_shell(container):
1817
LOGGER.debug(logs)
1918
assert 'res0: Int = 2' in logs
2019

20+
2121
def test_pyspark(container):
2222
"""PySpark should be in the Python path"""
2323
c = container.run(

0 commit comments

Comments
 (0)