Repository: oppia/oppia

Issue:
Pip global config creates issue with services.start
**Describe the bug**
If global pip index configuration is configured to use a specific server URL, this causes requirements.txt regeneration to add the following line to the requirements.txt file: 

`--index-url=https://your-custom-index-server.com`

This causes the following issues:
* When running services.start, this line will break the function `_get_requirements_file_contents` in `install_backend_python_libs.py`. The function expects each line to be in the format `package==versionNumber`, so the `.split()` method returns an unexpected number of values. It would also break additional downstream functionality.
* The version controlled requirements.txt file shouldn't contain any devs local pip configuration

**To Reproduce**
Steps to reproduce the behavior:
 1. Set custom pip package index ([docs](https://mothergeo-py.readthedocs.io/en/latest/development/how-to/alternate-pypi.html))
 2. Run `python -m scripts.start` from root

**Observed behavior**
The start script fails with the following error:

`  File "/<dir>/oppia/scripts/install_backend_python_libs.py", line 153, in _get_requirements_file_contents
    library_name, version_string = line.split(' ')[0].split('==')
ValueError: not enough values to unpack (expected 2, got 1)`

**Expected behavior**
A local development server is started

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: MacOS Big Sur (11.6)

**Additional context**
I'd like to work on this bug if possible
Pip global config creates issue with services.start
**Describe the bug**
If global pip index configuration is configured to use a specific server URL, this causes requirements.txt regeneration to add the following line to the requirements.txt file: 

`--index-url=https://your-custom-index-server.com`

This causes the following issues:
* When running services.start, this line will break the function `_get_requirements_file_contents` in `install_backend_python_libs.py`. The function expects each line to be in the format `package==versionNumber`, so the `.split()` method returns an unexpected number of values. It would also break additional downstream functionality.
* The version controlled requirements.txt file shouldn't contain any devs local pip configuration

**To Reproduce**
Steps to reproduce the behavior:
 1. Set custom pip package index ([docs](https://mothergeo-py.readthedocs.io/en/latest/development/how-to/alternate-pypi.html))
 2. Run `python -m scripts.start` from root

**Observed behavior**
The start script fails with the following error:

`  File "/<dir>/oppia/scripts/install_backend_python_libs.py", line 153, in _get_requirements_file_contents
    library_name, version_string = line.split(' ')[0].split('==')
ValueError: not enough values to unpack (expected 2, got 1)`

**Expected behavior**
A local development server is started

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: MacOS Big Sur (11.6)

**Additional context**
I'd like to work on this bug if possible


Discussion:
@lheureuxe13 Hey, do you need to actually have the `--index-url=https://your-custom-index-server.com` in the requirements.txt (e.g. do you need to use the custom repo) or is it fine to remove it?
Hi @vojtechjelinek, this line is actually generated automatically anytime `services.start` is run unfortunately, at least in my case it has been (given my local pip index configuration)

I've found a solution to fix this and prevent it from happening in the future for anyone else who may have a custom pip index set - I'll be creating a PR within the next few hours
@lheureuxe13 Hey, do you need to actually have the `--index-url=https://your-custom-index-server.com` in the requirements.txt (e.g. do you need to use the custom repo) or is it fine to remove it?
Hi @vojtechjelinek, this line is actually generated automatically anytime `services.start` is run unfortunately, at least in my case it has been (given my local pip index configuration)

I've found a solution to fix this and prevent it from happening in the future for anyone else who may have a custom pip index set - I'll be creating a PR within the next few hours

Resolving patch:
diff --git a/scripts/install_backend_python_libs.py b/scripts/install_backend_python_libs.py
--- a/scripts/install_backend_python_libs.py
+++ b/scripts/install_backend_python_libs.py
@@ -670,8 +670,16 @@ def main():
     # callstack to exit.
     # Therefore, in order to allow continued execution after the requirements
     # file is generated, we must call it as a separate process.
+    # The option --no-emit-index-url is specified to prevent pip compile from
+    # generating an index configuration line(s) in requirements.txt when the
+    # local pip configuration uses one or more custom index servers.
     subprocess.check_call(
-        ['python', '-m', 'scripts.regenerate_requirements'],
+        [
+            'python',
+            '-m',
+            'scripts.regenerate_requirements',
+            '--no-emit-index-url',
+        ],
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE)
     # Adds a note to the beginning of the 'requirements.txt' file to make sure


Test patch:
diff --git a/scripts/install_backend_python_libs_test.py b/scripts/install_backend_python_libs_test.py
--- a/scripts/install_backend_python_libs_test.py
+++ b/scripts/install_backend_python_libs_test.py
@@ -271,7 +271,7 @@ def mock_validate_metadata_directories():
         self.assertEqual(
             self.cmd_token_list,
             [
-                ['scripts.regenerate_requirements'],
+                ['scripts.regenerate_requirements', '--no-emit-index-url'],
                 [
                     'pip', 'install', '--target',
                     common.THIRD_PARTY_PYTHON_LIBS_DIR,
@@ -313,7 +313,7 @@ def mock_validate_metadata_directories():
         self.assertEqual(
             self.cmd_token_list,
             [
-                ['scripts.regenerate_requirements'],
+                ['scripts.regenerate_requirements', '--no-emit-index-url'],
                 [
                     'pip', 'install',
                     '%s#egg=git-dep1' % (
@@ -380,7 +380,7 @@ def mock_validate_metadata_directories():
         self.assertEqual(
             self.cmd_token_list,
             [
-                ['scripts.regenerate_requirements'],
+                ['scripts.regenerate_requirements', '--no-emit-index-url'],
                 [
                     'pip', 'install', '--target',
                     common.THIRD_PARTY_PYTHON_LIBS_DIR,
@@ -543,7 +543,7 @@ def mock_validate_metadata_directories():
         self.assertItemsEqual(
             self.cmd_token_list,
             [
-                ['scripts.regenerate_requirements'],
+                ['scripts.regenerate_requirements', '--no-emit-index-url'],
                 [
                     'pip', 'install', '%s==%s' % ('flask', '1.1.1'),
                     '--target', common.THIRD_PARTY_PYTHON_LIBS_DIR,