mirror of https://github.com/zulip/zulip.git
lint: Add lint rule for scripts importing typing improperly.
This is a common bug that users might be tempated to introduce. And also fix two instances of this bug that were present in our codebase, including an important one in our upgrade code path.
This commit is contained in:
parent
47c4a2d21a
commit
bce90a3340
|
@ -10,13 +10,15 @@ import dateutil.parser
|
||||||
import pytz
|
import pytz
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Dict, List
|
if False:
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
logging.Formatter.converter = time.gmtime
|
logging.Formatter.converter = time.gmtime
|
||||||
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
|
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def run(args: List[str], dry_run: bool=False) -> str:
|
def run(args, dry_run=False):
|
||||||
|
# type: (List[str], bool) -> str
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print("Would have run: " + " ".join(map(shlex.quote, args)))
|
print("Would have run: " + " ".join(map(shlex.quote, args)))
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -6,7 +6,6 @@ import subprocess
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import configparser
|
import configparser
|
||||||
from typing import List
|
|
||||||
|
|
||||||
TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
|
TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
|
||||||
os.environ["PYTHONUNBUFFERED"] = "y"
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
||||||
|
@ -17,7 +16,7 @@ from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, \
|
||||||
get_config_file, get_deploy_options
|
get_config_file, get_deploy_options
|
||||||
|
|
||||||
config_file = get_config_file() # type: configparser.RawConfigParser
|
config_file = get_config_file() # type: configparser.RawConfigParser
|
||||||
deploy_options = get_deploy_options(config_file) # type: List[str]
|
deploy_options = get_deploy_options(config_file)
|
||||||
|
|
||||||
assert_running_as_root(strip_lib_from_paths=True)
|
assert_running_as_root(strip_lib_from_paths=True)
|
||||||
|
|
||||||
|
|
|
@ -479,6 +479,21 @@ def build_custom_checkers(by_lang):
|
||||||
'description': 'Most scripts are intended to run on systems without sudo.',
|
'description': 'Most scripts are intended to run on systems without sudo.',
|
||||||
'good_lines': ['subprocess.check_call(["ls"])'],
|
'good_lines': ['subprocess.check_call(["ls"])'],
|
||||||
'bad_lines': ['subprocess.check_call(["sudo", "ls"])']},
|
'bad_lines': ['subprocess.check_call(["sudo", "ls"])']},
|
||||||
|
{'pattern': '^from typing import',
|
||||||
|
'strip': '\n',
|
||||||
|
'include_only': set([
|
||||||
|
'scripts/',
|
||||||
|
'puppet/',
|
||||||
|
]),
|
||||||
|
'exclude': set([
|
||||||
|
# Not important, but should fix
|
||||||
|
'scripts/lib/process-mobile-i18n',
|
||||||
|
# Uses setup_path_on_import before importing.
|
||||||
|
'puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_send_receive_time',
|
||||||
|
]),
|
||||||
|
'description': 'For scripts run as part of installer, cannot rely on typing existing; use `if False` workaround.',
|
||||||
|
'good_lines': ['subprocess.check_call(["ls"])'],
|
||||||
|
'bad_lines': ['subprocess.check_call(["sudo", "ls"])']},
|
||||||
{'pattern': 'django.utils.translation',
|
{'pattern': 'django.utils.translation',
|
||||||
'include_only': set(['test/']),
|
'include_only': set(['test/']),
|
||||||
'description': 'Test strings should not be tagged for translation',
|
'description': 'Test strings should not be tagged for translation',
|
||||||
|
|
Loading…
Reference in New Issue