mirror of https://github.com/zulip/zulip.git
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:
parent
b6986d48c7
commit
eab355b0cd
|
@ -5,15 +5,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import glob
|
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
|
# 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__))
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
sys.path.insert(0, os.path.dirname(TOOLS_DIR))
|
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_script import get_provisioning_status
|
||||||
from tools.lib.test_server import test_server_running
|
from tools.lib.test_server import test_server_running
|
||||||
|
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
if not options.force:
|
if not options.force:
|
||||||
ok, msg = get_provisioning_status()
|
ok, msg = get_provisioning_status()
|
||||||
if not ok:
|
if not ok:
|
||||||
|
|
|
@ -6,14 +6,9 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
try:
|
# check for the venv
|
||||||
import lister
|
from lib import sanity_check
|
||||||
from typing import cast, Callable, Dict, Iterable, List
|
sanity_check.check_venv(__file__)
|
||||||
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)
|
|
||||||
|
|
||||||
def validate(fn):
|
def validate(fn):
|
||||||
# type: (str) -> None
|
# type: (str) -> None
|
||||||
|
|
|
@ -8,14 +8,13 @@ import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from six.moves import filter
|
from six.moves import filter
|
||||||
try:
|
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
import lister
|
import lister
|
||||||
from typing import cast, Callable, Dict, Iterable, List
|
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)
|
|
||||||
|
|
||||||
EXCLUDED_FILES = [
|
EXCLUDED_FILES = [
|
||||||
## Test data Files for testing modules in tests
|
## Test data Files for testing modules in tests
|
||||||
|
|
|
@ -8,6 +8,10 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
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__), '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
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 collections import defaultdict
|
||||||
from typing import Any, Dict, Iterable, Set
|
from typing import Any, Dict, Iterable, Set
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -7,15 +7,9 @@ import glob
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from six.moves import filter
|
# check for the venv
|
||||||
try:
|
from lib import sanity_check
|
||||||
import lister
|
sanity_check.check_venv(__file__)
|
||||||
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)
|
|
||||||
|
|
||||||
def process_files():
|
def process_files():
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
def debug(obj):
|
def debug(obj):
|
||||||
|
|
|
@ -6,13 +6,12 @@ import optparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from six.moves import filter
|
from six.moves import filter
|
||||||
try:
|
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
import lister
|
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)
|
|
||||||
|
|
||||||
USAGE = '''
|
USAGE = '''
|
||||||
This file greps HTML files for keywords in a context-sensitive manner.
|
This file greps HTML files for keywords in a context-sensitive manner.
|
||||||
|
|
|
@ -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)
|
|
@ -10,14 +10,12 @@ import optparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
try:
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
import lister
|
import lister
|
||||||
from typing import cast, Any, Callable, Dict, Iterator, List, Optional, Tuple
|
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)
|
|
||||||
|
|
||||||
# Exclude some directories and files from lint checking
|
# Exclude some directories and files from lint checking
|
||||||
EXCLUDED_FILES = [
|
EXCLUDED_FILES = [
|
||||||
|
|
|
@ -10,6 +10,7 @@ import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import argparse
|
import argparse
|
||||||
from six.moves import filter
|
from six.moves import filter
|
||||||
|
|
||||||
from typing import Union, List, Dict
|
from typing import Union, List, Dict
|
||||||
|
|
||||||
def get_ftype(fpath, use_shebang):
|
def get_ftype(fpath, use_shebang):
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
# separate script so that the import from zerver.worker.queue_processors (which
|
# 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
|
# is slow) can be done in parallel with the rest of the work in bringing up the
|
||||||
# dev server.
|
# dev server.
|
||||||
|
from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import django
|
|
||||||
import subprocess
|
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__), '..'))
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
@ -12,6 +13,10 @@ import traceback
|
||||||
|
|
||||||
from six.moves.urllib.parse import urlunparse
|
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 httpclient
|
||||||
from tornado import httputil
|
from tornado import httputil
|
||||||
from tornado import gen
|
from tornado import gen
|
||||||
|
|
|
@ -5,11 +5,11 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import lister
|
|
||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
import lister
|
||||||
from typing import cast, Dict, List
|
from typing import cast, Dict, List
|
||||||
|
|
||||||
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
# check for the venv
|
||||||
import django
|
from lib import sanity_check
|
||||||
except ImportError as e:
|
sanity_check.check_venv(__file__)
|
||||||
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)
|
|
||||||
|
|
||||||
|
import django
|
||||||
TOOLS_DIR = os.path.dirname(__file__)
|
TOOLS_DIR = os.path.dirname(__file__)
|
||||||
ROOT_DIR = os.path.dirname(TOOLS_DIR)
|
ROOT_DIR = os.path.dirname(TOOLS_DIR)
|
||||||
sys.path.insert(0, ROOT_DIR)
|
sys.path.insert(0, ROOT_DIR)
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
try:
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
import django
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test.utils import get_runner
|
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -7,16 +8,12 @@ import subprocess
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
try:
|
|
||||||
# We don't actually need typing, but it's a good guard for being
|
# check for the venv
|
||||||
# outside a Zulip virtualenv.
|
from lib import sanity_check
|
||||||
from typing import Iterable
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
import requests
|
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)
|
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option('--force', default=False,
|
parser.add_option('--force', default=False,
|
||||||
|
|
|
@ -11,6 +11,10 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
from typing import IO, Text
|
from typing import IO, Text
|
||||||
|
|
||||||
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
|
@ -10,6 +10,9 @@ import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
from typing import IO
|
from typing import IO
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
# check for the venv
|
||||||
|
from lib import sanity_check
|
||||||
|
sanity_check.check_venv(__file__)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--coverage', dest='coverage',
|
parser.add_argument('--coverage', dest='coverage',
|
||||||
|
|
|
@ -5,6 +5,11 @@ JSON data for the /authors page.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, print_function
|
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
|
from typing import Any, Dict, List, Optional, Union, Text
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
|
@ -9,6 +9,10 @@ import subprocess
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
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.
|
# 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__), '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
import scripts.lib.setup_path_on_import
|
import scripts.lib.setup_path_on_import
|
||||||
|
|
|
@ -6,6 +6,10 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
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__), '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
Loading…
Reference in New Issue