Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes for flake8 and other smaller pre-commit tools #747

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion .github/integration-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_os_release_variable(key):
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)
Expand Down
6 changes: 3 additions & 3 deletions docs/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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 -->
<!-- Read more about our code-review guidelines at https://the-littlest-jupyterhub.readthedocs.io/en/latest/contributing/code-review.html -->
2 changes: 1 addition & 1 deletion docs/contributing/code-review.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
See :ref:`contributing/tests` for guidelines on writing tests.
2 changes: 1 addition & 1 deletion docs/contributing/packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
just using the latest versions provided by Ubuntu.
2 changes: 0 additions & 2 deletions docs/howto/admin/enable-extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ Enabling extensions via the command line

.. image:: ../../images/admin/enable-spellcheck.png
:alt: spellcheck-interface-changes


2 changes: 1 addition & 1 deletion docs/howto/content/share-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Include ``--plugin git+https://github.com/kafonek/tljh-shared-directory`` in your deployment startup script to install it.
2 changes: 0 additions & 2 deletions docs/howto/providers/azure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


2 changes: 1 addition & 1 deletion docs/howto/providers/digitalocean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
users and verifying resource availability can be found in :ref:`howto/admin/resize`.
1 change: 0 additions & 1 deletion docs/install/custom-server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

2 changes: 1 addition & 1 deletion docs/install/digitalocean.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ Step 2: Adding more users
Step 3: Install conda / pip packages for all users
==================================================

.. include:: add_packages.txt
.. include:: add_packages.txt
2 changes: 1 addition & 1 deletion docs/topic/jupyterhub-configurator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Once done, the configurator interface will be available.
2 changes: 0 additions & 2 deletions docs/troubleshooting/restart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


1 change: 0 additions & 1 deletion integration-tests/test_admin_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from hubtraf.auth.dummy import login_dummy
import pytest
from functools import partial
import asyncio


@pytest.mark.asyncio
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/test_extensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import subprocess


Expand Down Expand Up @@ -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)
1 change: 0 additions & 1 deletion integration-tests/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import asyncio
import pwd
import grp
import sys
import subprocess
from os import system
from tljh.normalize import generate_system_username
Expand Down
1 change: 0 additions & 1 deletion integration-tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from tljh.config import (
reload_component,
set_config_value,
unset_config_value,
CONFIG_FILE,
CONFIG_DIR,
STATE_DIR,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/test_simplest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/test_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
1 change: 0 additions & 1 deletion tests/test_configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test configurer
"""

from traitlets import Dict
from traitlets.config import Config
import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion tests/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/test_traefik.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test traefik configuration"""
import os
from unittest import mock

import toml
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tljh/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
1 change: 0 additions & 1 deletion tljh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

import argparse
import asyncio
from collections.abc import Sequence, Mapping
from copy import deepcopy
import os
Expand Down
2 changes: 1 addition & 1 deletion tljh/configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
10 changes: 4 additions & 6 deletions tljh/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import pluggy
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from getpass import getpass

from tljh import (
apt,
Expand All @@ -26,7 +25,6 @@
systemd,
traefik,
user,
utils
)
from .config import (
CONFIG_DIR,
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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():
Expand All @@ -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):
Expand Down Expand Up @@ -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 = {}
Expand Down
1 change: 0 additions & 1 deletion tljh/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tljh/traefik.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tljh/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Empty file modified tljh/user_creating_spawner.py
100755 → 100644
Empty file.