mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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:
		@@ -10,13 +10,15 @@ import dateutil.parser
 | 
			
		||||
import pytz
 | 
			
		||||
import time
 | 
			
		||||
from datetime import datetime, timedelta
 | 
			
		||||
from typing import Dict, List
 | 
			
		||||
if False:
 | 
			
		||||
    from typing import Dict, List
 | 
			
		||||
 | 
			
		||||
logging.Formatter.converter = time.gmtime
 | 
			
		||||
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
 | 
			
		||||
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:
 | 
			
		||||
        print("Would have run: " + " ".join(map(shlex.quote, args)))
 | 
			
		||||
        return ""
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@ import subprocess
 | 
			
		||||
import logging
 | 
			
		||||
import time
 | 
			
		||||
import configparser
 | 
			
		||||
from typing import List
 | 
			
		||||
 | 
			
		||||
TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -479,6 +479,21 @@ def build_custom_checkers(by_lang):
 | 
			
		||||
         'description': 'Most scripts are intended to run on systems without sudo.',
 | 
			
		||||
         'good_lines': ['subprocess.check_call(["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',
 | 
			
		||||
         'include_only': set(['test/']),
 | 
			
		||||
         'description': 'Test strings should not be tagged for translation',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user