From 39ed51b8413e181d3708b19275cf9fa984ce4af1 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 28 Oct 2021 09:39:01 +0200 Subject: [PATCH 1/6] Add flake8 config --- .flake8 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..16087a7 --- /dev/null +++ b/.flake8 @@ -0,0 +1,12 @@ +[flake8] +# Ignore style and complexity +# E: style errors +# W: style warnings +# C: complexity +# F841: local variable assigned but never used +ignore = E, C, W, F841 +builtins = + c + load_subconfig +exclude = + build/ From a64f242b61b564e1f597e1b468e3fff32ca01301 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 28 Oct 2021 09:37:50 +0200 Subject: [PATCH 2/6] flake8 fixes: unused imports and f-strings without vars --- .github/integration-test.py | 2 +- integration-tests/test_admin_installer.py | 1 - integration-tests/test_extensions.py | 1 - integration-tests/test_hub.py | 1 - integration-tests/test_proxy.py | 1 - integration-tests/test_simplest_plugin.py | 2 +- tests/test_configurer.py | 1 - tests/test_traefik.py | 1 - tljh/config.py | 1 - tljh/installer.py | 2 -- tljh/jupyterhub_config.py | 1 - 11 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/integration-test.py b/.github/integration-test.py index 67b8a9d..cf027fc 100755 --- a/.github/integration-test.py +++ b/.github/integration-test.py @@ -104,7 +104,7 @@ def run_test(image_name, test_name, bootstrap_pip_spec, test_files, upgrade, ins if upgrade: run_container_command( test_name, - f'curl -L https://tljh.jupyter.org/bootstrap.py | python3 -' + 'curl -L https://tljh.jupyter.org/bootstrap.py | python3 -' ) run_container_command( diff --git a/integration-tests/test_admin_installer.py b/integration-tests/test_admin_installer.py index 1f6f38a..1bda5d4 100644 --- a/integration-tests/test_admin_installer.py +++ b/integration-tests/test_admin_installer.py @@ -2,7 +2,6 @@ from hubtraf.user import User from hubtraf.auth.dummy import login_dummy import pytest from functools import partial -import asyncio @pytest.mark.asyncio diff --git a/integration-tests/test_extensions.py b/integration-tests/test_extensions.py index 9e08a8e..973f784 100644 --- a/integration-tests/test_extensions.py +++ b/integration-tests/test_extensions.py @@ -1,4 +1,3 @@ -import os import subprocess diff --git a/integration-tests/test_hub.py b/integration-tests/test_hub.py index 687d4a9..5e98d1a 100644 --- a/integration-tests/test_hub.py +++ b/integration-tests/test_hub.py @@ -8,7 +8,6 @@ from functools import partial import asyncio import pwd import grp -import sys import subprocess from os import system from tljh.normalize import generate_system_username diff --git a/integration-tests/test_proxy.py b/integration-tests/test_proxy.py index be91d78..63e4841 100644 --- a/integration-tests/test_proxy.py +++ b/integration-tests/test_proxy.py @@ -12,7 +12,6 @@ import pytest from tljh.config import ( reload_component, set_config_value, - unset_config_value, CONFIG_FILE, CONFIG_DIR, STATE_DIR, diff --git a/integration-tests/test_simplest_plugin.py b/integration-tests/test_simplest_plugin.py index 0b7afd3..e61bbcc 100644 --- a/integration-tests/test_simplest_plugin.py +++ b/integration-tests/test_simplest_plugin.py @@ -84,7 +84,7 @@ def test_new_user_create(): # Call ensure_user to make sure the user plugin gets called user.ensure_user(username) - with open(f"test_new_user_create") as f: + with open("test_new_user_create") as f: content = f.read() assert content == username diff --git a/tests/test_configurer.py b/tests/test_configurer.py index 98fe60d..8865687 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -2,7 +2,6 @@ Test configurer """ -from traitlets import Dict from traitlets.config import Config import os import sys diff --git a/tests/test_traefik.py b/tests/test_traefik.py index d22f68d..e858e07 100644 --- a/tests/test_traefik.py +++ b/tests/test_traefik.py @@ -1,6 +1,5 @@ """Test traefik configuration""" import os -from unittest import mock import toml import pytest diff --git a/tljh/config.py b/tljh/config.py index 24882ad..0609c4f 100644 --- a/tljh/config.py +++ b/tljh/config.py @@ -13,7 +13,6 @@ tljh-config show firstlevel.second_level """ import argparse -import asyncio from collections.abc import Sequence, Mapping from copy import deepcopy import os diff --git a/tljh/installer.py b/tljh/installer.py index 40f3fab..ad306da 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -16,7 +16,6 @@ import bcrypt import pluggy import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning -from getpass import getpass from tljh import ( apt, @@ -26,7 +25,6 @@ from tljh import ( systemd, traefik, user, - utils ) from .config import ( CONFIG_DIR, diff --git a/tljh/jupyterhub_config.py b/tljh/jupyterhub_config.py index cdda3d9..c5d679c 100644 --- a/tljh/jupyterhub_config.py +++ b/tljh/jupyterhub_config.py @@ -5,7 +5,6 @@ JupyterHub config for the littlest jupyterhub. from glob import glob import os -from systemdspawner import SystemdSpawner from tljh import configurer from tljh.config import INSTALL_PREFIX, USER_ENV_PREFIX, CONFIG_DIR from tljh.utils import get_plugin_manager From 0b817fb56377bb79348ebf2bd38096a09f6917f0 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 28 Oct 2021 09:43:51 +0200 Subject: [PATCH 3/6] end-of-file-fixer fixes --- docs/PULL_REQUEST_TEMPLATE.md | 2 +- docs/contributing/code-review.rst | 2 +- docs/contributing/packages.rst | 2 +- docs/howto/admin/enable-extensions.rst | 2 -- docs/howto/content/share-data.rst | 2 +- docs/howto/providers/azure.rst | 2 -- docs/howto/providers/digitalocean.rst | 2 +- docs/install/custom-server.rst | 1 - docs/install/digitalocean.rst | 2 +- docs/topic/jupyterhub-configurator.rst | 2 +- docs/troubleshooting/restart.rst | 2 -- 11 files changed, 7 insertions(+), 14 deletions(-) diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md index 1798476..c39c1c7 100644 --- a/docs/PULL_REQUEST_TEMPLATE.md +++ b/docs/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,4 @@ - [ ] Add / update documentation - [ ] Add tests - \ No newline at end of file + diff --git a/docs/contributing/code-review.rst b/docs/contributing/code-review.rst index 28feed9..76a2e8b 100644 --- a/docs/contributing/code-review.rst +++ b/docs/contributing/code-review.rst @@ -48,4 +48,4 @@ add more tests. If you are unsure what kind of tests to add for your pull request, other contributors to the repo will be happy to help guide you! -See :ref:`contributing/tests` for guidelines on writing tests. \ No newline at end of file +See :ref:`contributing/tests` for guidelines on writing tests. diff --git a/docs/contributing/packages.rst b/docs/contributing/packages.rst index 74613e2..72d329c 100644 --- a/docs/contributing/packages.rst +++ b/docs/contributing/packages.rst @@ -43,4 +43,4 @@ Base operating system packages, including Python itself, are installed via ``apt`` from the base Ubuntu repositories. We generally do not pin versions of packages provided by apt, instead -just using the latest versions provided by Ubuntu. \ No newline at end of file +just using the latest versions provided by Ubuntu. diff --git a/docs/howto/admin/enable-extensions.rst b/docs/howto/admin/enable-extensions.rst index 70c103a..5029193 100644 --- a/docs/howto/admin/enable-extensions.rst +++ b/docs/howto/admin/enable-extensions.rst @@ -56,5 +56,3 @@ Enabling extensions via the command line .. image:: ../../images/admin/enable-spellcheck.png :alt: spellcheck-interface-changes - - diff --git a/docs/howto/content/share-data.rst b/docs/howto/content/share-data.rst index 5e98324..16d1b55 100644 --- a/docs/howto/content/share-data.rst +++ b/docs/howto/content/share-data.rst @@ -136,4 +136,4 @@ and User C cannot edit the Notebook. Only User A can make changes. .. note:: The TLJH Plugin at https://github.com/kafonek/tljh-shared-directory installs ``voila`` and sets up the directories as specified above. - Include ``--plugin git+https://github.com/kafonek/tljh-shared-directory`` in your deployment startup script to install it. \ No newline at end of file + Include ``--plugin git+https://github.com/kafonek/tljh-shared-directory`` in your deployment startup script to install it. diff --git a/docs/howto/providers/azure.rst b/docs/howto/providers/azure.rst index 889ab60..fab16a8 100644 --- a/docs/howto/providers/azure.rst +++ b/docs/howto/providers/azure.rst @@ -34,5 +34,3 @@ If you no longer need any of your resources you can delete the entire resource g * Go to "Reosurce groups" on the left hand panel * Click on your resource group * Click on "Delete resource group" you will then be asked to confirm the operation. This operation will take between 5 and 10 minutes. - - diff --git a/docs/howto/providers/digitalocean.rst b/docs/howto/providers/digitalocean.rst index 081ad91..f3fcf30 100644 --- a/docs/howto/providers/digitalocean.rst +++ b/docs/howto/providers/digitalocean.rst @@ -40,4 +40,4 @@ disk space, or CPUs. Digital Ocean servers can be resized in the Now that you've resized your Droplet, you may want to change the resources available to your users. Further information on making more resources available to -users and verifying resource availability can be found in :ref:`howto/admin/resize`. \ No newline at end of file +users and verifying resource availability can be found in :ref:`howto/admin/resize`. diff --git a/docs/install/custom-server.rst b/docs/install/custom-server.rst index 5ab06fe..bcb616d 100644 --- a/docs/install/custom-server.rst +++ b/docs/install/custom-server.rst @@ -97,4 +97,3 @@ Step 4: Setup HTTPS Once you are ready to run your server for real, and have a domain, it's a good idea to proceed directly to :ref:`howto/admin/https`. - diff --git a/docs/install/digitalocean.rst b/docs/install/digitalocean.rst index 2b6c146..38d07a0 100644 --- a/docs/install/digitalocean.rst +++ b/docs/install/digitalocean.rst @@ -116,4 +116,4 @@ Step 2: Adding more users Step 3: Install conda / pip packages for all users ================================================== -.. include:: add_packages.txt \ No newline at end of file +.. include:: add_packages.txt diff --git a/docs/topic/jupyterhub-configurator.rst b/docs/topic/jupyterhub-configurator.rst index 642a996..6fdce76 100644 --- a/docs/topic/jupyterhub-configurator.rst +++ b/docs/topic/jupyterhub-configurator.rst @@ -25,4 +25,4 @@ Accessing the Configurator After enabling the configurator using ``tljh-config``, the service will only be available to hub admins, from within the control panel. The configurator can be accessed from under ``Services`` in the top navigation bar. It will ask to authenticate, so it knows the user is an admin. -Once done, the configurator interface will be available. \ No newline at end of file +Once done, the configurator interface will be available. diff --git a/docs/troubleshooting/restart.rst b/docs/troubleshooting/restart.rst index 18a2498..7220f9c 100644 --- a/docs/troubleshooting/restart.rst +++ b/docs/troubleshooting/restart.rst @@ -27,5 +27,3 @@ This calls systemctl and restarts Traefik. The user may call systemctl and resta .. code-block:: console $ sudo tljh-config reload hub - - From 623ab321f0d9e22f5f70409d231dedf098d200bb Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 28 Oct 2021 10:03:15 +0200 Subject: [PATCH 4/6] check-executable-have-shebangs fixes --- tljh/user_creating_spawner.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 tljh/user_creating_spawner.py diff --git a/tljh/user_creating_spawner.py b/tljh/user_creating_spawner.py old mode 100755 new mode 100644 From b0375627e3534612d819a2f636fd4a14a22cee6d Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 28 Oct 2021 11:24:31 +0200 Subject: [PATCH 5/6] prettier fixes --- .github/workflows/integration-test.yaml | 1 - docs/PULL_REQUEST_TEMPLATE.md | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index cd910a4..6babbc1 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -24,7 +24,6 @@ on: workflow_dispatch: jobs: - # This job is used as a workaround to a limitation when using a matrix of # variations that a job should be executed against. The limitation is that a # matrix once defined can't include any conditions. diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md index c39c1c7..214518a 100644 --- a/docs/PULL_REQUEST_TEMPLATE.md +++ b/docs/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,4 @@ - - [ ] Add / update documentation - - [ ] Add tests +- [ ] Add / update documentation +- [ ] Add tests From c2c4d708f52f611110aa640ea5b35a6e07f90d9a Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 31 Oct 2021 11:26:40 +0100 Subject: [PATCH 6/6] pyupgrade fixes --- bootstrap/bootstrap.py | 2 +- integration-tests/test_extensions.py | 2 +- tests/test_conda.py | 2 +- tests/test_installer.py | 2 +- tljh/conda.py | 2 +- tljh/configurer.py | 2 +- tljh/installer.py | 8 ++++---- tljh/traefik.py | 2 +- tljh/user.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py index 23739df..0315c13 100644 --- a/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap.py @@ -211,7 +211,7 @@ def ensure_host_system_can_install_tljh(): class ProgressPageRequestHandler(SimpleHTTPRequestHandler): def do_GET(self): if self.path == "/logs": - with open("/opt/tljh/installer.log", "r") as log_file: + with open("/opt/tljh/installer.log") as log_file: logs = log_file.read() self.send_response(200) diff --git a/integration-tests/test_extensions.py b/integration-tests/test_extensions.py index 973f784..13b305a 100644 --- a/integration-tests/test_extensions.py +++ b/integration-tests/test_extensions.py @@ -38,7 +38,7 @@ def test_nbextensions(): ] for e in extensions: - assert '{} \x1b[32m enabled \x1b[0m'.format(e) in proc.stdout.decode() + assert f'{e} \x1b[32m enabled \x1b[0m' in proc.stdout.decode() # Ensure we have 'OK' messages in our stdout, to make sure everything is importable assert proc.stderr.decode() == ' - Validating: \x1b[32mOK\x1b[0m\n' * len(extensions) diff --git a/tests/test_conda.py b/tests/test_conda.py index 539e646..a4db013 100644 --- a/tests/test_conda.py +++ b/tests/test_conda.py @@ -59,7 +59,7 @@ def test_ensure_pip_requirements(prefix): conda.ensure_conda_packages(prefix, ['pip']) with tempfile.NamedTemporaryFile() as f: # Sample small package to test - f.write('there'.encode()) + f.write(b'there') f.flush() conda.ensure_pip_requirements(prefix, f.name) subprocess.check_call([ diff --git a/tests/test_installer.py b/tests/test_installer.py index ca13cc5..361d394 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -31,7 +31,7 @@ def test_ensure_admins(tljh_dir, admins, expected_config): installer.ensure_admins(admins) config_path = installer.CONFIG_FILE - with open(config_path, 'r') as f: + with open(config_path) as f: config = yaml.load(f) # verify the list was flattened diff --git a/tljh/conda.py b/tljh/conda.py index 6827c47..7ef4099 100644 --- a/tljh/conda.py +++ b/tljh/conda.py @@ -72,7 +72,7 @@ def fix_permissions(prefix): Run after each install command. """ utils.run_subprocess( - ["chown", "-R", "{}:{}".format(os.getuid(), os.getgid()), prefix] + ["chown", "-R", f"{os.getuid()}:{os.getgid()}", prefix] ) utils.run_subprocess(["chmod", "-R", "o-w", prefix]) diff --git a/tljh/configurer.py b/tljh/configurer.py index 02235a9..36bb69d 100644 --- a/tljh/configurer.py +++ b/tljh/configurer.py @@ -121,7 +121,7 @@ def load_traefik_api_credentials(): proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret') if not os.path.exists(proxy_secret_path): return {} - with open(proxy_secret_path, 'r') as f: + with open(proxy_secret_path) as f: password = f.read() return { 'traefik_api': { diff --git a/tljh/installer.py b/tljh/installer.py index ad306da..3bb4e84 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -225,7 +225,7 @@ def ensure_admins(admin_password_list): logger.info("Setting up admin users") config_path = CONFIG_FILE if os.path.exists(config_path): - with open(config_path, 'r') as f: + with open(config_path) as f: config = yaml.load(f) else: config = {} @@ -261,7 +261,7 @@ def ensure_jupyterhub_running(times=20): for i in range(times): try: - logger.info('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times)) + logger.info(f'Waiting for JupyterHub to come up ({i + 1}/{times} tries)') # Because we don't care at this level that SSL is valid, we can suppress # InsecureRequestWarning for this request. with warnings.catch_warnings(): @@ -283,7 +283,7 @@ def ensure_jupyterhub_running(times=20): # Everything else should immediately abort raise - raise Exception("Installation failed: JupyterHub did not start in {}s".format(times)) + raise Exception(f"Installation failed: JupyterHub did not start in {times}s") def ensure_symlinks(prefix): @@ -388,7 +388,7 @@ def ensure_config_yaml(plugin_manager): migrator.migrate_config_files() if os.path.exists(CONFIG_FILE): - with open(CONFIG_FILE, 'r') as f: + with open(CONFIG_FILE) as f: config = yaml.load(f) else: config = {} diff --git a/tljh/traefik.py b/tljh/traefik.py index 997cf00..4c3151f 100644 --- a/tljh/traefik.py +++ b/tljh/traefik.py @@ -69,7 +69,7 @@ def ensure_traefik_binary(prefix): # verify that we got what we expected checksum = checksum_file(traefik_bin) if checksum != checksums[plat]: - raise IOError(f"Checksum failed {traefik_bin}: {checksum} != {checksums[plat]}") + raise OSError(f"Checksum failed {traefik_bin}: {checksum} != {checksums[plat]}") def compute_basic_auth(username, password): diff --git a/tljh/user.py b/tljh/user.py index d4daf1f..edd2d90 100644 --- a/tljh/user.py +++ b/tljh/user.py @@ -34,7 +34,7 @@ def ensure_user(username): subprocess.check_call([ 'chmod', 'o-rwx', - expanduser('~{username}'.format(username=username)) + expanduser(f'~{username}') ]) pm = get_plugin_manager()