Skip to content

Commit

Permalink
pyupgrade fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Oct 31, 2021
1 parent b037562 commit c817b5f
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_os_release_variable(key):
"""
return subprocess.check_output([
'/bin/bash', '-c',
"source /etc/os-release && echo ${{{key}}}".format(key=key)
f"source /etc/os-release && echo ${{{key}}}"
]).decode().strip()

# Require Ubuntu 18.04+
Expand Down 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 Expand Up @@ -329,7 +329,7 @@ def serve_forever(server):
run_subprocess(['apt-get', 'update'])
run_subprocess(['apt-get', 'install', '--yes', 'python3', 'python3-venv', 'python3-pip', 'git'], env=apt_get_adjusted_env)

logger.info('Setting up virtual environment at {}'.format(hub_prefix))
logger.info(f'Setting up virtual environment at {hub_prefix}')
os.makedirs(hub_prefix, exist_ok=True)
run_subprocess(['python3', '-m', 'venv', hub_prefix])

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
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
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
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
8 changes: 4 additions & 4 deletions tljh/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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():
Expand All @@ -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):
Expand Down Expand Up @@ -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 = {}
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

0 comments on commit c817b5f

Please sign in to comment.