tools: Create more consistent checks for venv.

This helps make the Zulip development environment somewhat more robust
to new contributors, since it will give them a nice warning if they
try running any of our development tools outside the Zulip virtualenv.

Fixes #3468.
This commit is contained in:
sinwar 2017-02-06 01:54:28 +05:30 committed by Tim Abbott
parent b6986d48c7
commit eab355b0cd
24 changed files with 116 additions and 82 deletions

View File

@ -5,15 +5,6 @@ import subprocess
import sys
import os
import glob
try:
# We don't actually need typing, but it's a good guard for being
# outside a Zulip virtualenv.
from typing import Iterable
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip tests inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
#
# In order to use remote casperjs debugging, pass the --remote-debug flag
@ -49,9 +40,15 @@ parser.add_option('--remote-debug',
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(TOOLS_DIR))
# check for the venv
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
from tools.lib.test_script import get_provisioning_status
from tools.lib.test_server import test_server_running
from typing import Iterable
if not options.force:
ok, msg = get_provisioning_status()
if not ok:

View File

@ -6,14 +6,9 @@ import os
import sys
import glob
try:
import lister
from typing import cast, Callable, Dict, Iterable, List
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
def validate(fn):
# type: (str) -> None

View File

@ -8,14 +8,13 @@ import sys
import logging
from six.moves import filter
try:
import lister
from typing import cast, Callable, Dict, Iterable, List
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import lister
from typing import cast, Callable, Dict, Iterable, List
EXCLUDED_FILES = [
## Test data Files for testing modules in tests

View File

@ -8,6 +8,10 @@ import subprocess
import sys
import time
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings

View File

@ -1,5 +1,10 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from collections import defaultdict
from typing import Any, Dict, Iterable, Set

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import os
import platform
import sys

View File

@ -7,15 +7,9 @@ import glob
import argparse
import sys
from six.moves import filter
try:
import lister
from typing import cast, Callable, Dict, Iterable, List
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
def process_files():
# type: () -> None

View File

@ -1,9 +1,14 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import sys
import re
import json
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from typing import Any, Dict, List
def debug(obj):

View File

@ -6,13 +6,12 @@ import optparse
import sys
from six.moves import filter
try:
import lister
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import lister
USAGE = '''
This file greps HTML files for keywords in a context-sensitive manner.

13
tools/lib/sanity_check.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
def check_venv(filename):
# type: (str) -> None
try:
import ujson
except ImportError:
print("You need to run %s inside a Zulip dev environment." % (filename,))
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)

View File

@ -10,14 +10,12 @@ import optparse
import subprocess
import traceback
try:
import lister
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import lister
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple
# Exclude some directories and files from lint checking
EXCLUDED_FILES = [

View File

@ -10,6 +10,7 @@ import re
from collections import defaultdict
import argparse
from six.moves import filter
from typing import Union, List, Dict
def get_ftype(fpath, use_shebang):

View File

@ -5,12 +5,16 @@
# separate script so that the import from zerver.worker.queue_processors (which
# is slow) can be done in parallel with the rest of the work in bringing up the
# dev server.
from __future__ import absolute_import
import sys
import os
import django
import subprocess
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import django
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
django.setup()

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import optparse
import os
@ -12,6 +13,10 @@ import traceback
from six.moves.urllib.parse import urlunparse
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from tornado import httpclient
from tornado import httputil
from tornado import gen

View File

@ -5,11 +5,11 @@ from __future__ import print_function
import os
import sys
import lister
import argparse
import subprocess
import six
import lister
from typing import cast, Dict, List
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))

View File

@ -1,17 +1,14 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import os
import sys
try:
import django
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip tests inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import django
TOOLS_DIR = os.path.dirname(__file__)
ROOT_DIR = os.path.dirname(TOOLS_DIR)
sys.path.insert(0, ROOT_DIR)

View File

@ -1,23 +1,19 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import optparse
import os
import sys
import subprocess
try:
import django
from django.conf import settings
from django.test.utils import get_runner
# We don't actually need typing, but it's a good guard for being
# outside a Zulip virtualenv.
import typing
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip tests inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import django
from django.conf import settings
from django.test.utils import get_runner
if __name__ == "__main__":
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
import optparse
import os
import sys
@ -7,16 +8,12 @@ import subprocess
import time
try:
# We don't actually need typing, but it's a good guard for being
# outside a Zulip virtualenv.
from typing import Iterable
import requests
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip tests inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import requests
parser = optparse.OptionParser()
parser.add_option('--force', default=False,

View File

@ -11,6 +11,10 @@ import subprocess
import re
from six.moves import range
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from typing import IO, Text
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))

View File

@ -10,6 +10,9 @@ import signal
import subprocess
from six.moves import range
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from typing import IO

View File

@ -8,6 +8,10 @@ import os
import sys
import unittest
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--coverage', dest='coverage',

View File

@ -5,6 +5,11 @@ JSON data for the /authors page.
"""
from __future__ import absolute_import, print_function
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from typing import Any, Dict, List, Optional, Union, Text
import os

View File

@ -9,6 +9,10 @@ import subprocess
import argparse
import sys
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
# We need settings so we can figure out where the prod-static directory is.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import scripts.lib.setup_path_on_import

View File

@ -6,6 +6,10 @@ import os
import subprocess
import sys
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings