mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-08 18:44:06 +00:00
Fix python codestyle
This commit is contained in:
@@ -7,7 +7,7 @@ import os
|
|||||||
import errno
|
import errno
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
c = get_config()
|
c = get_config() # noqa: F821
|
||||||
c.NotebookApp.ip = '0.0.0.0'
|
c.NotebookApp.ip = '0.0.0.0'
|
||||||
c.NotebookApp.port = 8888
|
c.NotebookApp.port = 8888
|
||||||
c.NotebookApp.open_browser = False
|
c.NotebookApp.open_browser = False
|
||||||
@@ -52,4 +52,4 @@ distinguished_name = req_distinguished_name
|
|||||||
# Change default umask for all subprocesses of the notebook server if set in
|
# Change default umask for all subprocesses of the notebook server if set in
|
||||||
# the environment
|
# the environment
|
||||||
if 'NB_UMASK' in os.environ:
|
if 'NB_UMASK' in os.environ:
|
||||||
os.umask(int(os.environ['NB_UMASK'], 8))
|
os.umask(int(os.environ['NB_UMASK'], 8))
|
||||||
|
@@ -70,23 +70,25 @@ def test_nb_user_change(container):
|
|||||||
running_container = container.run(
|
running_container = container.run(
|
||||||
tty=True,
|
tty=True,
|
||||||
user="root",
|
user="root",
|
||||||
environment=[f"NB_USER={nb_user}",
|
environment=[
|
||||||
"CHOWN_HOME=yes"],
|
f"NB_USER={nb_user}",
|
||||||
|
"CHOWN_HOME=yes"
|
||||||
|
],
|
||||||
working_dir=f"/home/{nb_user}",
|
working_dir=f"/home/{nb_user}",
|
||||||
command=['start.sh', 'bash', '-c', 'sleep infinity']
|
command=['start.sh', 'bash', '-c', 'sleep infinity']
|
||||||
)
|
)
|
||||||
|
|
||||||
LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...")
|
LOGGER.info(f"Checking if the user is changed to {nb_user} by the start script ...")
|
||||||
output = running_container.logs(stdout=True).decode("utf-8")
|
output = running_container.logs(stdout=True).decode("utf-8")
|
||||||
assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}"
|
assert f"Set username to: {nb_user}" in output, f"User is not changed to {nb_user}"
|
||||||
|
|
||||||
LOGGER.info(f"Checking {nb_user} id ...")
|
LOGGER.info(f"Checking {nb_user} id ...")
|
||||||
command = "id"
|
command = "id"
|
||||||
expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)"
|
expected_output = f"uid=1000({nb_user}) gid=100(users) groups=100(users)"
|
||||||
cmd = running_container.exec_run(command, user=nb_user)
|
cmd = running_container.exec_run(command, user=nb_user)
|
||||||
output = cmd.output.decode("utf-8").strip("\n")
|
output = cmd.output.decode("utf-8").strip("\n")
|
||||||
assert output == expected_output, f"Bad user {output}, expected {expected_output}"
|
assert output == expected_output, f"Bad user {output}, expected {expected_output}"
|
||||||
|
|
||||||
LOGGER.info(f"Checking if {nb_user} owns his home folder ...")
|
LOGGER.info(f"Checking if {nb_user} owns his home folder ...")
|
||||||
command = f'stat -c "%U %G" /home/{nb_user}/'
|
command = f'stat -c "%U %G" /home/{nb_user}/'
|
||||||
expected_output = f"{nb_user} users"
|
expected_output = f"{nb_user} users"
|
||||||
@@ -100,10 +102,11 @@ def test_chown_extra(container):
|
|||||||
c = container.run(
|
c = container.run(
|
||||||
tty=True,
|
tty=True,
|
||||||
user='root',
|
user='root',
|
||||||
environment=['NB_UID=1010',
|
environment=[
|
||||||
'NB_GID=101',
|
'NB_UID=1010',
|
||||||
'CHOWN_EXTRA=/opt/conda',
|
'NB_GID=101',
|
||||||
'CHOWN_EXTRA_OPTS=-R',
|
'CHOWN_EXTRA=/opt/conda',
|
||||||
|
'CHOWN_EXTRA_OPTS=-R'
|
||||||
],
|
],
|
||||||
command=['start.sh', 'bash', '-c', 'stat -c \'%n:%u:%g\' /opt/conda/LICENSE.txt']
|
command=['start.sh', 'bash', '-c', 'stat -c \'%n:%u:%g\' /opt/conda/LICENSE.txt']
|
||||||
)
|
)
|
||||||
@@ -113,13 +116,14 @@ def test_chown_extra(container):
|
|||||||
|
|
||||||
|
|
||||||
def test_chown_home(container):
|
def test_chown_home(container):
|
||||||
"""Container should change the NB_USER home directory owner and
|
"""Container should change the NB_USER home directory owner and
|
||||||
group to the current value of NB_UID and NB_GID."""
|
group to the current value of NB_UID and NB_GID."""
|
||||||
c = container.run(
|
c = container.run(
|
||||||
tty=True,
|
tty=True,
|
||||||
user='root',
|
user='root',
|
||||||
environment=['CHOWN_HOME=yes',
|
environment=[
|
||||||
'CHOWN_HOME_OPTS=-R',
|
'CHOWN_HOME=yes',
|
||||||
|
'CHOWN_HOME_OPTS=-R'
|
||||||
],
|
],
|
||||||
command=['start.sh', 'bash', '-c', 'chown root:root /home/jovyan && ls -alsh /home']
|
command=['start.sh', 'bash', '-c', 'chown root:root /home/jovyan && ls -alsh /home']
|
||||||
)
|
)
|
||||||
|
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -17,4 +15,3 @@ def test_pandoc(container):
|
|||||||
logs = c.logs(stdout=True).decode("utf-8")
|
logs = c.logs(stdout=True).decode("utf-8")
|
||||||
LOGGER.debug(logs)
|
LOGGER.debug(logs)
|
||||||
assert "<p><strong>BOLD</strong></p>" in logs
|
assert "<p><strong>BOLD</strong></p>" in logs
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ from requests.adapters import HTTPAdapter
|
|||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def http_client():
|
def http_client():
|
||||||
"""Requests session with retries and backoff."""
|
"""Requests session with retries and backoff."""
|
||||||
@@ -78,7 +79,7 @@ class TrackedContainer(object):
|
|||||||
LOGGER.info(f"Running {self.image_name} with args {all_kwargs} ...")
|
LOGGER.info(f"Running {self.image_name} with args {all_kwargs} ...")
|
||||||
self.container = self.docker_client.containers.run(self.image_name, **all_kwargs)
|
self.container = self.docker_client.containers.run(self.image_name, **all_kwargs)
|
||||||
return self.container
|
return self.container
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Kills and removes the tracked docker container."""
|
"""Kills and removes the tracked docker container."""
|
||||||
if self.container:
|
if self.container:
|
||||||
|
@@ -2,18 +2,16 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def test_julia(container):
|
def test_julia(container):
|
||||||
"""Basic julia test"""
|
"""Basic julia test"""
|
||||||
LOGGER.info(f"Test that julia is correctly installed ...")
|
LOGGER.info("Test that julia is correctly installed ...")
|
||||||
running_container = container.run(
|
running_container = container.run(
|
||||||
tty=True, command=["start.sh", "bash", "-c", "sleep infinity"]
|
tty=True, command=["start.sh", "bash", "-c", "sleep infinity"]
|
||||||
)
|
)
|
||||||
command = f"julia --version"
|
command = "julia --version"
|
||||||
cmd = running_container.exec_run(command)
|
cmd = running_container.exec_run(command)
|
||||||
output = cmd.output.decode("utf-8")
|
output = cmd.output.decode("utf-8")
|
||||||
assert cmd.exit_code == 0, f"Command {command} failed {output}"
|
assert cmd.exit_code == 0, f"Command {command} failed {output}"
|
||||||
|
7
docs/conf.py
Normal file → Executable file
7
docs/conf.py
Normal file → Executable file
@@ -21,11 +21,6 @@
|
|||||||
# import sys
|
# import sys
|
||||||
# sys.path.insert(0, os.path.abspath('.'))
|
# sys.path.insert(0, os.path.abspath('.'))
|
||||||
|
|
||||||
# For conversion from markdown to html
|
|
||||||
import recommonmark.parser
|
|
||||||
from recommonmark.transform import AutoStructify
|
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ------------------------------------------------
|
# -- General configuration ------------------------------------------------
|
||||||
|
|
||||||
# If your documentation needs a minimal Sphinx version, state it here.
|
# If your documentation needs a minimal Sphinx version, state it here.
|
||||||
@@ -199,4 +194,4 @@ linkcheck_anchors = False
|
|||||||
# -- Translation ----------------------------------------------------------
|
# -- Translation ----------------------------------------------------------
|
||||||
|
|
||||||
gettext_uuid = True
|
gettext_uuid = True
|
||||||
locale_dirs = ['locale/']
|
locale_dirs = ['locale/']
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
# Copyright (c) Jupyter Development Team.
|
# Copyright (c) Jupyter Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def test_spark_shell(container):
|
def test_spark_shell(container):
|
||||||
"""Checking if Spark (spark-shell) is running properly"""
|
"""Checking if Spark (spark-shell) is running properly"""
|
||||||
c = container.run(
|
c = container.run(
|
||||||
@@ -18,6 +17,7 @@ def test_spark_shell(container):
|
|||||||
LOGGER.debug(logs)
|
LOGGER.debug(logs)
|
||||||
assert 'res0: Int = 2' in logs
|
assert 'res0: Int = 2' in logs
|
||||||
|
|
||||||
|
|
||||||
def test_pyspark(container):
|
def test_pyspark(container):
|
||||||
"""PySpark should be in the Python path"""
|
"""PySpark should be in the Python path"""
|
||||||
c = container.run(
|
c = container.run(
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
# Optional test with [Matplotlib Jupyter Integration](https://github.com/matplotlib/ipympl)
|
# Optional test with [Matplotlib Jupyter Integration](https://github.com/matplotlib/ipympl)
|
||||||
# %matplotlib widget
|
# %matplotlib widget
|
||||||
import matplotlib
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
@@ -21,4 +20,4 @@ ax.grid()
|
|||||||
# Note that the test can be run headless by checking if an image is produced
|
# Note that the test can be run headless by checking if an image is produced
|
||||||
file_path = os.path.join("/tmp", "test.png")
|
file_path = os.path.join("/tmp", "test.png")
|
||||||
fig.savefig(file_path)
|
fig.savefig(file_path)
|
||||||
print(f"File {file_path} saved")
|
print(f"File {file_path} saved")
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
@@ -15,7 +14,7 @@ def test_matplotlib(container):
|
|||||||
cont_data_dir = "/home/jovyan/data"
|
cont_data_dir = "/home/jovyan/data"
|
||||||
test_file = "matplotlib_1.py"
|
test_file = "matplotlib_1.py"
|
||||||
output_dir = "/tmp"
|
output_dir = "/tmp"
|
||||||
LOGGER.info(f"Test that matplotlib is able to plot a graph and write it as an image ...")
|
LOGGER.info("Test that matplotlib is able to plot a graph and write it as an image ...")
|
||||||
command = "sleep infinity"
|
command = "sleep infinity"
|
||||||
running_container = container.run(
|
running_container = container.run(
|
||||||
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
|
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
|
||||||
|
@@ -64,7 +64,7 @@ class CondaPackageHelper:
|
|||||||
def installed_packages(self):
|
def installed_packages(self):
|
||||||
"""Return the installed packages"""
|
"""Return the installed packages"""
|
||||||
if self.installed is None:
|
if self.installed is None:
|
||||||
LOGGER.info(f"Grabing the list of installed packages ...")
|
LOGGER.info("Grabing the list of installed packages ...")
|
||||||
self.installed = CondaPackageHelper._packages_from_json(
|
self.installed = CondaPackageHelper._packages_from_json(
|
||||||
self._execute_command(CondaPackageHelper._conda_export_command())
|
self._execute_command(CondaPackageHelper._conda_export_command())
|
||||||
)
|
)
|
||||||
@@ -73,7 +73,7 @@ class CondaPackageHelper:
|
|||||||
def specified_packages(self):
|
def specified_packages(self):
|
||||||
"""Return the specifications (i.e. packages installation requested)"""
|
"""Return the specifications (i.e. packages installation requested)"""
|
||||||
if self.specs is None:
|
if self.specs is None:
|
||||||
LOGGER.info(f"Grabing the list of specifications ...")
|
LOGGER.info("Grabing the list of specifications ...")
|
||||||
self.specs = CondaPackageHelper._packages_from_json(
|
self.specs = CondaPackageHelper._packages_from_json(
|
||||||
self._execute_command(CondaPackageHelper._conda_export_command(True))
|
self._execute_command(CondaPackageHelper._conda_export_command(True))
|
||||||
)
|
)
|
||||||
@@ -87,11 +87,11 @@ class CondaPackageHelper:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _packages_from_json(env_export):
|
def _packages_from_json(env_export):
|
||||||
"""Extract packages and versions from the lines returned by the list of specifications"""
|
"""Extract packages and versions from the lines returned by the list of specifications"""
|
||||||
#dependencies = filter(lambda x: isinstance(x, str), json.loads(env_export).get("dependencies"))
|
# dependencies = filter(lambda x: isinstance(x, str), json.loads(env_export).get("dependencies"))
|
||||||
dependencies = json.loads(env_export).get("dependencies")
|
dependencies = json.loads(env_export).get("dependencies")
|
||||||
# Filtering packages installed through pip in this case it's a dict {'pip': ['toree==0.3.0']}
|
# Filtering packages installed through pip in this case it's a dict {'pip': ['toree==0.3.0']}
|
||||||
# Since we only manage packages installed through conda here
|
# Since we only manage packages installed through conda here
|
||||||
dependencies = filter(lambda x: isinstance(x, str), dependencies)
|
dependencies = filter(lambda x: isinstance(x, str), dependencies)
|
||||||
packages_dict = dict()
|
packages_dict = dict()
|
||||||
for split in map(lambda x: x.split("=", 1), dependencies):
|
for split in map(lambda x: x.split("=", 1), dependencies):
|
||||||
# default values
|
# default values
|
||||||
@@ -112,7 +112,7 @@ class CondaPackageHelper:
|
|||||||
"""Return the available packages"""
|
"""Return the available packages"""
|
||||||
if self.available is None:
|
if self.available is None:
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
f"Grabing the list of available packages (can take a while) ..."
|
"Grabing the list of available packages (can take a while) ..."
|
||||||
)
|
)
|
||||||
# Keeping command line output since `conda search --outdated --json` is way too long ...
|
# Keeping command line output since `conda search --outdated --json` is way too long ...
|
||||||
self.available = CondaPackageHelper._extract_available(
|
self.available = CondaPackageHelper._extract_available(
|
||||||
@@ -135,7 +135,7 @@ class CondaPackageHelper:
|
|||||||
installed = self.installed_packages()
|
installed = self.installed_packages()
|
||||||
available = self.available_packages()
|
available = self.available_packages()
|
||||||
self.comparison = list()
|
self.comparison = list()
|
||||||
for pkg, inst_vs in self.installed.items():
|
for pkg, inst_vs in installed.items():
|
||||||
if not specifications_only or pkg in specs:
|
if not specifications_only or pkg in specs:
|
||||||
avail_vs = sorted(
|
avail_vs = sorted(
|
||||||
list(available[pkg]), key=CondaPackageHelper.semantic_cmp
|
list(available[pkg]), key=CondaPackageHelper.semantic_cmp
|
||||||
@@ -158,7 +158,8 @@ class CondaPackageHelper:
|
|||||||
"""Manage semantic versioning for comparison"""
|
"""Manage semantic versioning for comparison"""
|
||||||
|
|
||||||
def mysplit(string):
|
def mysplit(string):
|
||||||
version_substrs = lambda x: re.findall(r"([A-z]+|\d+)", x)
|
def version_substrs(x):
|
||||||
|
return re.findall(r"([A-z]+|\d+)", x)
|
||||||
return list(chain(map(version_substrs, string.split("."))))
|
return list(chain(map(version_substrs, string.split("."))))
|
||||||
|
|
||||||
def str_ord(string):
|
def str_ord(string):
|
||||||
|
@@ -131,7 +131,7 @@ def _import_packages(package_helper, filtered_packages, check_function, max_fail
|
|||||||
Note: using a list of packages instead of a fixture for the list of packages since pytest prevents use of multiple yields
|
Note: using a list of packages instead of a fixture for the list of packages since pytest prevents use of multiple yields
|
||||||
"""
|
"""
|
||||||
failures = {}
|
failures = {}
|
||||||
LOGGER.info(f"Testing the import of packages ...")
|
LOGGER.info("Testing the import of packages ...")
|
||||||
for package in filtered_packages:
|
for package in filtered_packages:
|
||||||
LOGGER.info(f"Trying to import {package}")
|
LOGGER.info(f"Trying to import {package}")
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user