mirror of https://github.com/zulip/zulip.git
ruff: Enable new lints DTZ, ISC, PIE, PLW, Q, S, SIM.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
17300f196c
commit
2afdb46095
|
@ -103,15 +103,22 @@ select = [
|
||||||
"ANN", # annotations
|
"ANN", # annotations
|
||||||
"B", # bugbear
|
"B", # bugbear
|
||||||
"C4", # comprehensions
|
"C4", # comprehensions
|
||||||
|
"DTZ", # naive datetime
|
||||||
"E", # style errors
|
"E", # style errors
|
||||||
"F", # flakes
|
"F", # flakes
|
||||||
"I", # import sorting
|
"I", # import sorting
|
||||||
|
"ISC", # string concatenation
|
||||||
"N", # naming
|
"N", # naming
|
||||||
"PGH", # pygrep-hooks
|
"PGH", # pygrep-hooks
|
||||||
|
"PIE", # miscellaneous
|
||||||
"PLC", # pylint convention
|
"PLC", # pylint convention
|
||||||
"PLE", # pylint error
|
"PLE", # pylint error
|
||||||
"PLR", # pylint refactor
|
"PLR", # pylint refactor
|
||||||
|
"PLW", # pylint warning
|
||||||
|
"Q", # quotes
|
||||||
"RUF", # Ruff
|
"RUF", # Ruff
|
||||||
|
"S", # security
|
||||||
|
"SIM", # simplify
|
||||||
"T10", # debugger
|
"T10", # debugger
|
||||||
"UP", # upgrade
|
"UP", # upgrade
|
||||||
"W", # style warnings
|
"W", # style warnings
|
||||||
|
@ -133,6 +140,10 @@ ignore = [
|
||||||
"N806", # Variable in function should be lowercase
|
"N806", # Variable in function should be lowercase
|
||||||
"RUF001", # String contains ambiguous unicode character
|
"RUF001", # String contains ambiguous unicode character
|
||||||
"RUF003", # Comment contains ambiguous unicode character
|
"RUF003", # Comment contains ambiguous unicode character
|
||||||
|
"S101", # Use of `assert` detected
|
||||||
|
"S105", # Possible hardcoded password
|
||||||
|
"S106", # Possible hardcoded password
|
||||||
|
"S107", # Possible hardcoded password
|
||||||
]
|
]
|
||||||
line-length = 100
|
line-length = 100
|
||||||
src = [".", "tools"]
|
src = [".", "tools"]
|
||||||
|
|
|
@ -12,7 +12,7 @@ def setup_path() -> None:
|
||||||
activate_this = os.path.join(venv, "bin", "activate_this.py")
|
activate_this = os.path.join(venv, "bin", "activate_this.py")
|
||||||
activate_locals = dict(__file__=activate_this)
|
activate_locals = dict(__file__=activate_this)
|
||||||
with open(activate_this) as f:
|
with open(activate_this) as f:
|
||||||
exec(f.read(), activate_locals)
|
exec(f.read(), activate_locals) # noqa: S102
|
||||||
# Check that the python version running this function
|
# Check that the python version running this function
|
||||||
# is same as python version that created the virtualenv.
|
# is same as python version that created the virtualenv.
|
||||||
python_version = "python{}.{}".format(*sys.version_info[:2])
|
python_version = "python{}.{}".format(*sys.version_info[:2])
|
||||||
|
|
|
@ -165,7 +165,7 @@ def su_to_zulip(save_suid: bool = False) -> None:
|
||||||
|
|
||||||
|
|
||||||
def make_deploy_path() -> str:
|
def make_deploy_path() -> str:
|
||||||
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
|
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) # noqa: DTZ005
|
||||||
return os.path.join(DEPLOYMENTS_DIR, timestamp)
|
return os.path.join(DEPLOYMENTS_DIR, timestamp)
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,7 +268,9 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:
|
||||||
# Returns a list of deployments not older than threshold days
|
# Returns a list of deployments not older than threshold days
|
||||||
# including `/root/zulip` directory if it exists.
|
# including `/root/zulip` directory if it exists.
|
||||||
recent = set()
|
recent = set()
|
||||||
threshold_date = datetime.datetime.now() - datetime.timedelta(days=threshold_days)
|
threshold_date = datetime.datetime.now() - datetime.timedelta( # noqa: DTZ005
|
||||||
|
days=threshold_days
|
||||||
|
)
|
||||||
for dir_name in os.listdir(DEPLOYMENTS_DIR):
|
for dir_name in os.listdir(DEPLOYMENTS_DIR):
|
||||||
target_dir = os.path.join(DEPLOYMENTS_DIR, dir_name)
|
target_dir = os.path.join(DEPLOYMENTS_DIR, dir_name)
|
||||||
if not os.path.isdir(target_dir):
|
if not os.path.isdir(target_dir):
|
||||||
|
@ -278,7 +280,7 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:
|
||||||
# Skip things like "lock" that aren't actually a deployment directory
|
# Skip things like "lock" that aren't actually a deployment directory
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT)
|
date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT) # noqa: DTZ007
|
||||||
if date >= threshold_date:
|
if date >= threshold_date:
|
||||||
recent.add(target_dir)
|
recent.add(target_dir)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -295,7 +297,7 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:
|
||||||
def get_threshold_timestamp(threshold_days: int) -> int:
|
def get_threshold_timestamp(threshold_days: int) -> int:
|
||||||
# Given number of days, this function returns timestamp corresponding
|
# Given number of days, this function returns timestamp corresponding
|
||||||
# to the time prior to given number of days.
|
# to the time prior to given number of days.
|
||||||
threshold = datetime.datetime.now() - datetime.timedelta(days=threshold_days)
|
threshold = datetime.datetime.now() - datetime.timedelta(days=threshold_days) # noqa: DTZ005
|
||||||
threshold_timestamp = int(time.mktime(threshold.utctimetuple()))
|
threshold_timestamp = int(time.mktime(threshold.utctimetuple()))
|
||||||
return threshold_timestamp
|
return threshold_timestamp
|
||||||
|
|
||||||
|
|
|
@ -461,7 +461,7 @@ def main(options: argparse.Namespace) -> NoReturn:
|
||||||
activate_this = "/srv/zulip-py3-venv/bin/activate_this.py"
|
activate_this = "/srv/zulip-py3-venv/bin/activate_this.py"
|
||||||
provision_inner = os.path.join(ZULIP_PATH, "tools", "lib", "provision_inner.py")
|
provision_inner = os.path.join(ZULIP_PATH, "tools", "lib", "provision_inner.py")
|
||||||
with open(activate_this) as f:
|
with open(activate_this) as f:
|
||||||
exec(f.read(), dict(__file__=activate_this))
|
exec(f.read(), dict(__file__=activate_this)) # noqa: S102
|
||||||
os.execvp(
|
os.execvp(
|
||||||
provision_inner,
|
provision_inner,
|
||||||
[
|
[
|
||||||
|
|
|
@ -376,12 +376,6 @@ python_rules = RuleList(
|
||||||
},
|
},
|
||||||
"description": "Please use access_stream_by_*() to fetch Stream objects",
|
"description": "Please use access_stream_by_*() to fetch Stream objects",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"pattern": "datetime[.](now|utcnow)",
|
|
||||||
"include_only": {"zerver/", "analytics/"},
|
|
||||||
"description": "Don't use datetime in backend code.\n"
|
|
||||||
"See https://zulip.readthedocs.io/en/latest/contributing/code-style.html#naive-datetime-objects",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"pattern": "from os.path",
|
"pattern": "from os.path",
|
||||||
"description": "Don't use from when importing from the standard library",
|
"description": "Don't use from when importing from the standard library",
|
||||||
|
|
|
@ -308,7 +308,7 @@ def parse_message(
|
||||||
events.append(parse_create_or_delete(message))
|
events.append(parse_create_or_delete(message))
|
||||||
elif message["action"].tame(check_string) == "change":
|
elif message["action"].tame(check_string) == "change":
|
||||||
if message["change"]["diff"]:
|
if message["change"]["diff"]:
|
||||||
for value in message["change"]["diff"].keys():
|
for value in message["change"]["diff"].keys(): # noqa: SIM118
|
||||||
parsed_event = parse_change_event(value, message)
|
parsed_event = parse_change_event(value, message)
|
||||||
if parsed_event:
|
if parsed_event:
|
||||||
events.append(parsed_event)
|
events.append(parsed_event)
|
||||||
|
|
Loading…
Reference in New Issue