pyupgrade fixes

This commit is contained in:
Erik Sundell
2021-10-31 11:26:40 +01:00
parent b0375627e3
commit c2c4d708f5
9 changed files with 12 additions and 12 deletions

View File

@@ -211,7 +211,7 @@ def ensure_host_system_can_install_tljh():
class ProgressPageRequestHandler(SimpleHTTPRequestHandler): class ProgressPageRequestHandler(SimpleHTTPRequestHandler):
def do_GET(self): def do_GET(self):
if self.path == "/logs": 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() logs = log_file.read()
self.send_response(200) self.send_response(200)

View File

@@ -38,7 +38,7 @@ def test_nbextensions():
] ]
for e in extensions: 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 # 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) assert proc.stderr.decode() == ' - Validating: \x1b[32mOK\x1b[0m\n' * len(extensions)

View File

@@ -59,7 +59,7 @@ def test_ensure_pip_requirements(prefix):
conda.ensure_conda_packages(prefix, ['pip']) conda.ensure_conda_packages(prefix, ['pip'])
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
# Sample small package to test # Sample small package to test
f.write('there'.encode()) f.write(b'there')
f.flush() f.flush()
conda.ensure_pip_requirements(prefix, f.name) conda.ensure_pip_requirements(prefix, f.name)
subprocess.check_call([ subprocess.check_call([

View File

@@ -31,7 +31,7 @@ def test_ensure_admins(tljh_dir, admins, expected_config):
installer.ensure_admins(admins) installer.ensure_admins(admins)
config_path = installer.CONFIG_FILE config_path = installer.CONFIG_FILE
with open(config_path, 'r') as f: with open(config_path) as f:
config = yaml.load(f) config = yaml.load(f)
# verify the list was flattened # verify the list was flattened

View File

@@ -72,7 +72,7 @@ def fix_permissions(prefix):
Run after each install command. Run after each install command.
""" """
utils.run_subprocess( 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]) utils.run_subprocess(["chmod", "-R", "o-w", prefix])

View File

@@ -121,7 +121,7 @@ def load_traefik_api_credentials():
proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret') proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret')
if not os.path.exists(proxy_secret_path): if not os.path.exists(proxy_secret_path):
return {} return {}
with open(proxy_secret_path, 'r') as f: with open(proxy_secret_path) as f:
password = f.read() password = f.read()
return { return {
'traefik_api': { 'traefik_api': {

View File

@@ -225,7 +225,7 @@ def ensure_admins(admin_password_list):
logger.info("Setting up admin users") logger.info("Setting up admin users")
config_path = CONFIG_FILE config_path = CONFIG_FILE
if os.path.exists(config_path): if os.path.exists(config_path):
with open(config_path, 'r') as f: with open(config_path) as f:
config = yaml.load(f) config = yaml.load(f)
else: else:
config = {} config = {}
@@ -261,7 +261,7 @@ def ensure_jupyterhub_running(times=20):
for i in range(times): for i in range(times):
try: 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 # Because we don't care at this level that SSL is valid, we can suppress
# InsecureRequestWarning for this request. # InsecureRequestWarning for this request.
with warnings.catch_warnings(): with warnings.catch_warnings():
@@ -283,7 +283,7 @@ def ensure_jupyterhub_running(times=20):
# Everything else should immediately abort # Everything else should immediately abort
raise 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): def ensure_symlinks(prefix):
@@ -388,7 +388,7 @@ def ensure_config_yaml(plugin_manager):
migrator.migrate_config_files() migrator.migrate_config_files()
if os.path.exists(CONFIG_FILE): if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'r') as f: with open(CONFIG_FILE) as f:
config = yaml.load(f) config = yaml.load(f)
else: else:
config = {} config = {}

View File

@@ -69,7 +69,7 @@ def ensure_traefik_binary(prefix):
# verify that we got what we expected # verify that we got what we expected
checksum = checksum_file(traefik_bin) checksum = checksum_file(traefik_bin)
if checksum != checksums[plat]: 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): def compute_basic_auth(username, password):

View File

@@ -34,7 +34,7 @@ def ensure_user(username):
subprocess.check_call([ subprocess.check_call([
'chmod', 'chmod',
'o-rwx', 'o-rwx',
expanduser('~{username}'.format(username=username)) expanduser(f'~{username}')
]) ])
pm = get_plugin_manager() pm = get_plugin_manager()