Repository: oppia/oppia

Issue:
Rename yarn folder in oppia_tools for better consistency.
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
The folders in `oppia_tools` generally following the format of `${tool-name}-${version-number}`, except the one for `yarn`. Currently, the folder named `yarn-v1.17.3`. We should get rid of the `v` in the middle for better consistency. 

```
(venv) ➜  oppia_tools ls
browsermob-proxy-0.8.0   google-cloud-sdk-251.0.0  psutil-5.6.7       pylint-1.9.4         skulpt-0.10.0
browsermob-proxy-2.1.1   isort-4.3.20              pycodestyle-2.5.0  pylint-quotes-0.1.8  webtest-2.0.33
esprima-4.0.1            node-10.15.3              PyGithub-1.43.7    pyyaml-5.1.2         yarn-v1.17.3
google_appengine_1.9.67  Pillow-6.0.0              pygsheets-2.0.2    selenium-3.13.0      yuicompressor-2.4.8
```

Rename yarn folder in oppia_tools for better consistency.
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
The folders in `oppia_tools` generally following the format of `${tool-name}-${version-number}`, except the one for `yarn`. Currently, the folder named `yarn-v1.17.3`. We should get rid of the `v` in the middle for better consistency. 

```
(venv) ➜  oppia_tools ls
browsermob-proxy-0.8.0   google-cloud-sdk-251.0.0  psutil-5.6.7       pylint-1.9.4         skulpt-0.10.0
browsermob-proxy-2.1.1   isort-4.3.20              pycodestyle-2.5.0  pylint-quotes-0.1.8  webtest-2.0.33
esprima-4.0.1            node-10.15.3              PyGithub-1.43.7    pyyaml-5.1.2         yarn-v1.17.3
google_appengine_1.9.67  Pillow-6.0.0              pygsheets-2.0.2    selenium-3.13.0      yuicompressor-2.4.8
```



Discussion:

Resolving patch:
diff --git a/scripts/common.py b/scripts/common.py
--- a/scripts/common.py
+++ b/scripts/common.py
@@ -30,7 +30,7 @@
 NODE_VERSION = '10.18.0'
 
 # NB: Please ensure that the version is consistent with the version in .yarnrc.
-YARN_VERSION = 'v1.21.1'
+YARN_VERSION = '1.21.1'
 
 COVERAGE_VERSION = '4.5.4'
 
diff --git a/scripts/setup.py b/scripts/setup.py
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -82,9 +82,23 @@ def download_and_install_package(url_to_retrieve, filename):
     tar = tarfile.open(name=filename)
     tar.extractall(path=common.OPPIA_TOOLS_DIR)
     tar.close()
+    rename_yarn_folder(filename, common.OPPIA_TOOLS_DIR)
     os.remove(filename)
 
 
+def rename_yarn_folder(filename, path):
+    """Removes the `v` from the yarn folder name.
+
+    Args:
+        filename: string. The name of the tar file.
+        path: string. The path of the yarn file.
+    """
+    if 'yarn' in filename:
+        old_name = filename.split('.tar.gz')[0]
+        new_name = ''.join(old_name.split('v'))
+        os.rename(path + '/' + old_name, path + '/' + new_name)
+
+
 def download_and_install_node():
     """Download and install node to Oppia tools directory."""
     outfile_name = 'node-download'
@@ -175,11 +189,9 @@ def main(args=None):
             'visit https://yarnpkg.com/en/docs/usage.'])
 
         # NB: Update .yarnrc if the yarn version below is changed.
-        # TODO(#8125): Remove the `v` in the folder name, e.g., yarn-v1.17.3 ->
-        # yarn-1.17.3.
-        yarn_file_name = 'yarn-%s.tar.gz' % common.YARN_VERSION
+        yarn_file_name = 'yarn-v%s.tar.gz' % common.YARN_VERSION
         download_and_install_package(
-            'https://github.com/yarnpkg/yarn/releases/download/%s/%s'
+            'https://github.com/yarnpkg/yarn/releases/download/v%s/%s'
             % (common.YARN_VERSION, yarn_file_name), yarn_file_name)
 
     # Adjust path to support the default Chrome locations for Unix, Windows and


Test patch:
diff --git a/scripts/setup_test.py b/scripts/setup_test.py
--- a/scripts/setup_test.py
+++ b/scripts/setup_test.py
@@ -35,6 +35,8 @@
 
 RELEASE_TEST_DIR = os.path.join('core', 'tests', 'release_sources', '')
 MOCK_TMP_UNTAR_PATH = os.path.join(RELEASE_TEST_DIR, 'tmp_unzip.tar.gz')
+TEST_DATA_DIR = os.path.join('core', 'tests', 'data', '')
+MOCK_YARN_PATH = os.path.join(TEST_DATA_DIR, 'yarn-v' + common.YARN_VERSION)
 
 
 class MockCD(python_utils.OBJECT):
@@ -226,6 +228,16 @@ def mock_remove(unused_path):
                 setup.download_and_install_package('url', 'filename')
         self.assertEqual(check_function_calls, expected_check_function_calls)
 
+    def test_rename_yarn_folder(self):
+        # Creates a dummy yarn folder and then checks if `v` was removed
+        # upon function call.
+        os.mkdir(MOCK_YARN_PATH)
+        setup.rename_yarn_folder('yarn-v' + common.YARN_VERSION, TEST_DATA_DIR)
+        target = os.path.join(
+            TEST_DATA_DIR, 'yarn-' + common.YARN_VERSION)
+        self.assertTrue(os.path.exists(target))
+        os.rmdir(target)
+
     def test_invalid_dir(self):
         def mock_getcwd():
             return 'invalid'
@@ -263,7 +275,7 @@ def mock_exists(unused_path):
                 'https://nodejs.org/dist/v%s/node-v%s-darwin-x64.tar.gz' % (
                     common.NODE_VERSION, common.NODE_VERSION),
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
 
     def test_package_install_with_darwin_x86(self):
@@ -289,7 +301,7 @@ def mock_check_call(cmd_tokens):
                 'https://nodejs.org/dist/v%s/node-v%s.tar.gz' % (
                     common.NODE_VERSION, common.NODE_VERSION),
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
         self.assertEqual(all_cmd_tokens, ['./configure', 'make'])
 
@@ -313,7 +325,7 @@ def mock_exists(unused_path):
                     common.NODE_VERSION, common.NODE_VERSION) +
                 '-linux-x64.tar.gz',
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
 
     def test_package_install_with_linux_x86(self):
@@ -339,7 +351,7 @@ def mock_check_call(cmd_tokens):
                 'https://nodejs.org/dist/v%s/node-v%s.tar.gz' % (
                     common.NODE_VERSION, common.NODE_VERSION),
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
         self.assertEqual(all_cmd_tokens, ['./configure', 'make'])
 
@@ -380,7 +392,7 @@ def mock_check_call(commands):
                 'https://nodejs.org/dist/v%s/node-v%s-win-x86.zip' % (
                     common.NODE_VERSION, common.NODE_VERSION),
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
 
     def test_package_install_with_windows_x64(self):
@@ -420,7 +432,7 @@ def mock_check_call(commands):
                 'https://nodejs.org/dist/v%s/node-v%s-win-x64.zip' % (
                     common.NODE_VERSION, common.NODE_VERSION),
                 'https://github.com/yarnpkg/yarn/releases/download/'
-                '%s/yarn-%s.tar.gz' % (
+                'v%s/yarn-v%s.tar.gz' % (
                     common.YARN_VERSION, common.YARN_VERSION)])
 
     def test_chrome_bin_setup_with_travis_var_set(self):