diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py index 23739df5b..0315c1342 100644 --- a/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap.py @@ -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) diff --git a/integration-tests/test_extensions.py b/integration-tests/test_extensions.py index 973f784f4..13b305ada 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 539e6469f..a4db0134d 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 ca13cc5be..361d394c1 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 6827c4778..7ef409907 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 02235a9f0..36bb69dd7 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 ad306dac9..3bb4e8437 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 997cf00a9..4c3151f4e 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 d4daf1fc7..edd2d90a4 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()