mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
python: Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` on all our Python code except `zthumbor` and `zulip-ec2-configure-interfaces`, followed by manual indentation fixes. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
fff2d3958a
commit
c734bbd95d
@@ -18,7 +18,7 @@ if ENV == "travis":
|
||||
|
||||
def get_caches_in_use(threshold_days):
|
||||
# type: (int) -> Set[str]
|
||||
setups_to_check = set([ZULIP_PATH, ])
|
||||
setups_to_check = {ZULIP_PATH}
|
||||
caches_in_use = set()
|
||||
|
||||
if ENV == "prod":
|
||||
|
||||
@@ -25,7 +25,7 @@ if ENV == "travis":
|
||||
|
||||
def get_caches_in_use(threshold_days):
|
||||
# type: (int) -> Set[str]
|
||||
setups_to_check = set([ZULIP_PATH, ])
|
||||
setups_to_check = {ZULIP_PATH}
|
||||
caches_in_use = set()
|
||||
|
||||
if ENV == "prod":
|
||||
|
||||
@@ -20,7 +20,7 @@ if ENV == "travis":
|
||||
|
||||
def get_caches_in_use(threshold_days):
|
||||
# type: (int) -> Set[str]
|
||||
setups_to_check = set([ZULIP_PATH, ])
|
||||
setups_to_check = {ZULIP_PATH}
|
||||
caches_in_use = set()
|
||||
|
||||
def add_current_venv_cache(venv_name: str) -> None:
|
||||
|
||||
@@ -39,7 +39,7 @@ def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION)
|
||||
if os.path.exists(YARN_LOCK_FILE_PATH):
|
||||
# For backwards compatibility, we can't assume yarn.lock exists
|
||||
sha1sum.update(subprocess_text_output(['cat', YARN_LOCK_FILE_PATH]).encode('utf8'))
|
||||
with open(YARN_PACKAGE_JSON, "r") as f:
|
||||
with open(YARN_PACKAGE_JSON) as f:
|
||||
yarn_version = json.load(f)['version']
|
||||
sha1sum.update(yarn_version.encode("utf8"))
|
||||
sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8'))
|
||||
|
||||
@@ -171,7 +171,7 @@ def get_venv_packages(venv_path):
|
||||
package index file.
|
||||
"""
|
||||
with open(get_index_filename(venv_path)) as reader:
|
||||
return set(p.strip() for p in reader.read().split('\n') if p.strip())
|
||||
return {p.strip() for p in reader.read().split('\n') if p.strip()}
|
||||
|
||||
def try_to_copy_venv(venv_path, new_packages):
|
||||
# type: (str, Set[str]) -> bool
|
||||
@@ -281,7 +281,7 @@ def do_patch_activate_script(venv_path):
|
||||
# venv_path should be what we want to have in VIRTUAL_ENV after patching
|
||||
script_path = os.path.join(venv_path, "bin", "activate")
|
||||
|
||||
with open(script_path, 'r') as f:
|
||||
with open(script_path) as f:
|
||||
lines = f.readlines()
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith('VIRTUAL_ENV='):
|
||||
|
||||
@@ -65,7 +65,7 @@ if not args.skip_puppet:
|
||||
subprocess.check_call(["apt-get", "update"])
|
||||
subprocess.check_call(["apt-get", "-y", "upgrade"])
|
||||
|
||||
if not os.path.exists((os.path.join(deploy_path, "zproject/prod_settings.py"))):
|
||||
if not os.path.exists(os.path.join(deploy_path, "zproject/prod_settings.py")):
|
||||
# This is normally done in unpack-zulip, but for upgrading from
|
||||
# zulip<1.4.0, we need to do it. See discussion in commit 586b23637.
|
||||
os.symlink("/etc/zulip/settings.py",
|
||||
|
||||
@@ -289,7 +289,7 @@ def get_caches_to_be_purged(caches_dir, caches_in_use, threshold_days):
|
||||
|
||||
def purge_unused_caches(caches_dir, caches_in_use, cache_type, args):
|
||||
# type: (str, Set[str], str, argparse.Namespace) -> None
|
||||
all_caches = set([os.path.join(caches_dir, cache) for cache in os.listdir(caches_dir)])
|
||||
all_caches = {os.path.join(caches_dir, cache) for cache in os.listdir(caches_dir)}
|
||||
caches_to_purge = get_caches_to_be_purged(caches_dir, caches_in_use, args.threshold_days)
|
||||
caches_to_keep = all_caches - caches_to_purge
|
||||
|
||||
@@ -313,7 +313,7 @@ def generate_sha1sum_emoji(zulip_path):
|
||||
# Take into account the version of `emoji-datasource-google` package
|
||||
# while generating success stamp.
|
||||
PACKAGE_FILE_PATH = os.path.join(zulip_path, 'package.json')
|
||||
with open(PACKAGE_FILE_PATH, 'r') as fp:
|
||||
with open(PACKAGE_FILE_PATH) as fp:
|
||||
parsed_package_file = json.load(fp)
|
||||
dependency_data = parsed_package_file['dependencies']
|
||||
|
||||
@@ -366,7 +366,7 @@ def parse_os_release():
|
||||
we avoid using it, as it is not available on RHEL-based platforms.
|
||||
"""
|
||||
distro_info = {} # type: Dict[str, str]
|
||||
with open('/etc/os-release', 'r') as fp:
|
||||
with open('/etc/os-release') as fp:
|
||||
for line in fp:
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
|
||||
Reference in New Issue
Block a user