Merge pull request #747 from consideRatio/pr/pre-adding-pre-commit-fixes

Small fixes for flake8 and other smaller pre-commit tools
This commit is contained in:
Yuvi Panda
2021-11-01 13:42:31 +05:30
committed by GitHub
32 changed files with 35 additions and 41 deletions

12
.flake8 Normal file
View File

@@ -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/

View File

@@ -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(

View File

@@ -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.

View File

@@ -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)

View File

@@ -1,4 +1,4 @@
- [ ] Add / update documentation
- [ ] Add tests
- [ ] Add / update documentation
- [ ] Add tests
<!-- Read more about our code-review guidelines at https://the-littlest-jupyterhub.readthedocs.io/en/latest/contributing/code-review.html -->

View File

@@ -56,5 +56,3 @@ Enabling extensions via the command line
.. image:: ../../images/admin/enable-spellcheck.png
:alt: spellcheck-interface-changes

View File

@@ -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.

View File

@@ -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`.

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,3 @@
import os
import subprocess
@@ -39,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)

View File

@@ -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

View File

@@ -12,7 +12,6 @@ import pytest
from tljh.config import (
reload_component,
set_config_value,
unset_config_value,
CONFIG_FILE,
CONFIG_DIR,
STATE_DIR,

View File

@@ -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

View File

@@ -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([

View File

@@ -2,7 +2,6 @@
Test configurer
"""
from traitlets import Dict
from traitlets.config import Config
import os
import sys

View File

@@ -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

View File

@@ -1,6 +1,5 @@
"""Test traefik configuration"""
import os
from unittest import mock
import toml
import pytest

View File

@@ -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])

View File

@@ -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

View File

@@ -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': {

View File

@@ -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,
@@ -227,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 = {}
@@ -263,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():
@@ -285,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):
@@ -390,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 = {}

View File

@@ -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

View File

@@ -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):

View File

@@ -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()

0
tljh/user_creating_spawner.py Executable file → Normal file
View File