Repository: oppia/oppia

Issue:
Remove duplicated DIRS_TO_ADD_TO_SYS_PATH 
Currently, there are two `DIRS_TO_ADD_TO_SYS_PATH` in the code base, one in `run_backend_tests.py` and the other one is in `gae_suite.py`. I feel this is not a good pattern and might be worth to remove the duplication. 
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/scripts/run_backend_tests.py#L66
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/core/tests/gae_suite.py#L36

What we could do:
- Put this constant in `common.py`. But we may need to add some hack to make `gae_suite.py` to be able to import `common`, like this:
```
sys.path.insert(1, os.getcwd())

from scripts import common
```
- Or we put this constant in a separate manifest json file

Personally I prefer the first one, by specifying the constant in `common.py`, we can also set the version numbers to be constants and those constants can also be reused in other places. 

**Addition note**:
Noticed that we are inserting the paths to `sys.path`, can we change to insert the paths to environment variable `os.environ['PYTHONPATH']`? This environment variable can be inherited to subprocess. 
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/core/tests/gae_suite.py#L91
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/scripts/run_backend_tests.py#L347 

/cc @oppia/dev-workflow-team 
Remove duplicated DIRS_TO_ADD_TO_SYS_PATH 
Currently, there are two `DIRS_TO_ADD_TO_SYS_PATH` in the code base, one in `run_backend_tests.py` and the other one is in `gae_suite.py`. I feel this is not a good pattern and might be worth to remove the duplication. 
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/scripts/run_backend_tests.py#L66
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/core/tests/gae_suite.py#L36

What we could do:
- Put this constant in `common.py`. But we may need to add some hack to make `gae_suite.py` to be able to import `common`, like this:
```
sys.path.insert(1, os.getcwd())

from scripts import common
```
- Or we put this constant in a separate manifest json file

Personally I prefer the first one, by specifying the constant in `common.py`, we can also set the version numbers to be constants and those constants can also be reused in other places. 

**Addition note**:
Noticed that we are inserting the paths to `sys.path`, can we change to insert the paths to environment variable `os.environ['PYTHONPATH']`? This environment variable can be inherited to subprocess. 
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/core/tests/gae_suite.py#L91
https://github.com/oppia/oppia/blob/1781135095551c436033f23c34e3cd8cadf54fba/scripts/run_backend_tests.py#L347 

/cc @oppia/dev-workflow-team 


Discussion:
@cuichenli please assign this to me
@anshalshukla you got it!
Assigning this to @AdityaDubey0, as per offline discussion! 
@cuichenli please assign this to me
@anshalshukla you got it!
Assigning this to @AdityaDubey0, as per offline discussion! 

Resolving patch:
diff --git a/scripts/common.py b/scripts/common.py
--- a/scripts/common.py
+++ b/scripts/common.py
@@ -158,6 +158,25 @@
 # will be identical.
 REQUIREMENTS_FILE_PATH = os.path.join(CURR_DIR, 'requirements.in')
 
+DIRS_TO_ADD_TO_SYS_PATH = [
+    GOOGLE_APP_ENGINE_SDK_HOME,
+    PYLINT_PATH,
+
+    os.path.join(OPPIA_TOOLS_DIR, 'webtest-%s' % WEBTEST_VERSION),
+    os.path.join(OPPIA_TOOLS_DIR, 'Pillow-%s' % PILLOW_VERSION),
+    os.path.join(
+        OPPIA_TOOLS_DIR, 'protobuf-%s' % PROTOBUF_VERSION),
+    PSUTIL_DIR,
+    os.path.join(OPPIA_TOOLS_DIR, 'grpcio-%s' % GRPCIO_VERSION),
+    os.path.join(OPPIA_TOOLS_DIR, 'setuptools-%s' % '36.6.0'),
+    os.path.join(
+        OPPIA_TOOLS_DIR, 'PyGithub-%s' % PYGITHUB_VERSION),
+    os.path.join(
+        OPPIA_TOOLS_DIR, 'pip-tools-%s' % PIP_TOOLS_VERSION),
+    CURR_DIR,
+    THIRD_PARTY_PYTHON_LIBS_DIR
+]
+
 
 def is_windows_os():
     """Check if the running system is Windows."""


Test patch:
diff --git a/core/tests/gae_suite.py b/core/tests/gae_suite.py
--- a/core/tests/gae_suite.py
+++ b/core/tests/gae_suite.py
@@ -30,6 +30,10 @@
 import sys
 import unittest
 
+sys.path.insert(1, os.getcwd())
+
+from scripts import common # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
+
 CURR_DIR = os.path.abspath(os.getcwd())
 OPPIA_TOOLS_DIR = os.path.join(CURR_DIR, '..', 'oppia_tools')
 THIRD_PARTY_DIR = os.path.join(CURR_DIR, 'third_party')
@@ -39,16 +43,6 @@
     OPPIA_TOOLS_DIR, 'google-cloud-sdk-304.0.0', 'google-cloud-sdk', 'platform',
     'google_appengine')
 
-DIRS_TO_ADD_TO_SYS_PATH = [
-    GOOGLE_APP_ENGINE_SDK_HOME,
-    os.path.join(OPPIA_TOOLS_DIR, 'webtest-2.0.35'),
-    os.path.join(OPPIA_TOOLS_DIR, 'Pillow-6.2.2'),
-    os.path.join(OPPIA_TOOLS_DIR, 'psutil-5.7.3'),
-    os.path.join(OPPIA_TOOLS_DIR, 'PyGithub-1.45'),
-    CURR_DIR,
-    os.path.join(THIRD_PARTY_DIR, 'python_libs')
-]
-
 _PARSER = argparse.ArgumentParser()
 _PARSER.add_argument(
     '--test_target',
@@ -73,7 +67,7 @@ def main(args=None):
     """Runs the tests."""
     parsed_args = _PARSER.parse_args(args=args)
 
-    for directory in DIRS_TO_ADD_TO_SYS_PATH:
+    for directory in common.DIRS_TO_ADD_TO_SYS_PATH:
         if not os.path.exists(os.path.dirname(directory)):
             raise Exception('Directory %s does not exist.' % directory)
         sys.path.insert(0, directory)
diff --git a/scripts/run_backend_tests.py b/scripts/run_backend_tests.py
--- a/scripts/run_backend_tests.py
+++ b/scripts/run_backend_tests.py
@@ -65,23 +65,6 @@
 from . import common # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 from . import concurrent_task_utils # isort:skip  pylint: disable=wrong-import-position, wrong-import-order
 
-DIRS_TO_ADD_TO_SYS_PATH = [
-    os.path.join(common.OPPIA_TOOLS_DIR, 'pylint-%s' % common.PYLINT_VERSION),
-
-    os.path.join(common.OPPIA_TOOLS_DIR, 'webtest-%s' % common.WEBTEST_VERSION),
-    os.path.join(common.OPPIA_TOOLS_DIR, 'Pillow-%s' % common.PILLOW_VERSION),
-    os.path.join(
-        common.OPPIA_TOOLS_DIR, 'protobuf-%s' % common.PROTOBUF_VERSION),
-    os.path.join(common.OPPIA_TOOLS_DIR, 'psutil-%s' % common.PSUTIL_VERSION),
-    os.path.join(common.OPPIA_TOOLS_DIR, 'grpcio-%s' % common.GRPCIO_VERSION),
-    os.path.join(common.OPPIA_TOOLS_DIR, 'setuptools-%s' % '36.6.0'),
-    os.path.join(
-        common.OPPIA_TOOLS_DIR, 'PyGithub-%s' % common.PYGITHUB_VERSION),
-    os.path.join(
-        common.OPPIA_TOOLS_DIR, 'pip-tools-%s' % common.PIP_TOOLS_VERSION),
-    common.CURR_DIR
-]
-
 COVERAGE_DIR = os.path.join(
     os.getcwd(), os.pardir, 'oppia_tools',
     'coverage-%s' % common.COVERAGE_VERSION)
@@ -233,7 +216,7 @@ def main(args=None):
     """Run the tests."""
     parsed_args = _PARSER.parse_args(args=args)
 
-    for directory in DIRS_TO_ADD_TO_SYS_PATH:
+    for directory in common.DIRS_TO_ADD_TO_SYS_PATH:
         if not os.path.exists(os.path.dirname(directory)):
             raise Exception('Directory %s does not exist.' % directory)