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
|
||||
"B", # bugbear
|
||||
"C4", # comprehensions
|
||||
"DTZ", # naive datetime
|
||||
"E", # style errors
|
||||
"F", # flakes
|
||||
"I", # import sorting
|
||||
"ISC", # string concatenation
|
||||
"N", # naming
|
||||
"PGH", # pygrep-hooks
|
||||
"PIE", # miscellaneous
|
||||
"PLC", # pylint convention
|
||||
"PLE", # pylint error
|
||||
"PLR", # pylint refactor
|
||||
"PLW", # pylint warning
|
||||
"Q", # quotes
|
||||
"RUF", # Ruff
|
||||
"S", # security
|
||||
"SIM", # simplify
|
||||
"T10", # debugger
|
||||
"UP", # upgrade
|
||||
"W", # style warnings
|
||||
|
@ -133,6 +140,10 @@ ignore = [
|
|||
"N806", # Variable in function should be lowercase
|
||||
"RUF001", # String 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
|
||||
src = [".", "tools"]
|
||||
|
|
|
@ -12,7 +12,7 @@ def setup_path() -> None:
|
|||
activate_this = os.path.join(venv, "bin", "activate_this.py")
|
||||
activate_locals = dict(__file__=activate_this)
|
||||
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
|
||||
# is same as python version that created the virtualenv.
|
||||
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:
|
||||
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
|
||||
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) # noqa: DTZ005
|
||||
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
|
||||
# including `/root/zulip` directory if it exists.
|
||||
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):
|
||||
target_dir = os.path.join(DEPLOYMENTS_DIR, dir_name)
|
||||
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
|
||||
continue
|
||||
try:
|
||||
date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT)
|
||||
date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT) # noqa: DTZ007
|
||||
if date >= threshold_date:
|
||||
recent.add(target_dir)
|
||||
except ValueError:
|
||||
|
@ -295,7 +297,7 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:
|
|||
def get_threshold_timestamp(threshold_days: int) -> int:
|
||||
# Given number of days, this function returns timestamp corresponding
|
||||
# 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()))
|
||||
return threshold_timestamp
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ def main(options: argparse.Namespace) -> NoReturn:
|
|||
activate_this = "/srv/zulip-py3-venv/bin/activate_this.py"
|
||||
provision_inner = os.path.join(ZULIP_PATH, "tools", "lib", "provision_inner.py")
|
||||
with open(activate_this) as f:
|
||||
exec(f.read(), dict(__file__=activate_this))
|
||||
exec(f.read(), dict(__file__=activate_this)) # noqa: S102
|
||||
os.execvp(
|
||||
provision_inner,
|
||||
[
|
||||
|
|
|
@ -376,12 +376,6 @@ python_rules = RuleList(
|
|||
},
|
||||
"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",
|
||||
"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))
|
||||
elif message["action"].tame(check_string) == "change":
|
||||
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)
|
||||
if parsed_event:
|
||||
events.append(parsed_event)
|
||||
|
|
Loading…
Reference in New Issue