Reorg virtualenv env_setup

Add symlink from previous location of requirements.txt. Will remove in
a followup after recipes have been configured to point to new path.

Bug: 67
Change-Id: I0b808c99789d65ac216dbd176a684061c8b2d8a8
diff --git a/env_setup/env_setup.py b/env_setup/env_setup.py
index 350b6f1..f3a3622 100755
--- a/env_setup/env_setup.py
+++ b/env_setup/env_setup.py
@@ -38,7 +38,7 @@
 import cargo_setup  # pylint: disable=import-error
 import environment  # pylint: disable=import-error
 import host_build_setup  # pylint: disable=import-error
-import virtualenv.init  # pylint: disable=import-error
+import virtualenv_setup  # pylint: disable=import-error
 
 
 # TODO(mohrr) remove disable=useless-object-inheritance once in Python 3.
@@ -101,8 +101,8 @@
 
         venv_path = os.path.join(self._pw_root, '.python3-env')
 
-        requirements = os.path.join(self._pw_root, 'env_setup', 'virtualenv',
-                                    'requirements.txt')
+        requirements = os.path.join(self._pw_root, 'env_setup',
+                                    'virtualenv_setup', 'requirements.txt')
 
         cipd_bin = os.path.join(
             self._pw_root,
@@ -125,7 +125,7 @@
 
         python = os.path.join(cipd_bin, py_executable)
 
-        virtualenv.init.init(
+        virtualenv_setup.install(
             venv_path=venv_path,
             requirements=[requirements],
             python=python,
diff --git a/env_setup/virtualenv/requirements.txt b/env_setup/virtualenv/requirements.txt
new file mode 120000
index 0000000..3c9f4d0
--- /dev/null
+++ b/env_setup/virtualenv/requirements.txt
@@ -0,0 +1 @@
+../virtualenv_setup/requirements.txt
\ No newline at end of file
diff --git a/env_setup/virtualenv/__init__.py b/env_setup/virtualenv_setup/__init__.py
similarity index 81%
rename from env_setup/virtualenv/__init__.py
rename to env_setup/virtualenv_setup/__init__.py
index 2c8334f..9e6cb96 100644
--- a/env_setup/virtualenv/__init__.py
+++ b/env_setup/virtualenv_setup/__init__.py
@@ -11,3 +11,7 @@
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 # License for the specific language governing permissions and limitations under
 # the License.
+"""Sets up a Python 3 virtualenv for Pigweed."""
+
+# TODO(pwbug/67) move install.py contents to this file.
+from .install import *
diff --git a/env_setup/virtualenv_setup/__main__.py b/env_setup/virtualenv_setup/__main__.py
new file mode 100644
index 0000000..e5324c5
--- /dev/null
+++ b/env_setup/virtualenv_setup/__main__.py
@@ -0,0 +1,55 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""Runnable module that sets up virtualenv for Pigweed."""
+
+import argparse
+import os
+import sys
+
+# TODO(mohrr) remove import-error disabling, not sure why pylint has issues
+# with it.
+import install  # pylint: disable=import-error
+
+
+def _main():
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('--venv_path',
+                        required=True,
+                        help='Path at which to create the venv')
+    parser.add_argument('-r',
+                        '--requirements',
+                        default=[],
+                        action='append',
+                        help='requirements.txt files to install')
+    parser.add_argument('--quick-setup',
+                        dest='full_envsetup',
+                        action='store_false',
+                        default='PW_ENVSETUP_FULL' in os.environ,
+                        help=('Do full setup or only minimal checks to see if '
+                              'full setup is required.'))
+    parser.add_argument('--python',
+                        default=sys.executable,
+                        help='Python to use when creating virtualenv.')
+
+    try:
+        install.install(**vars(parser.parse_args()))
+    except install.GitRepoNotFound:
+        print('git repository not found', file=sys.stderr)
+        return -1
+
+    return 0
+
+
+if __name__ == '__main__':
+    sys.exit(_main())
diff --git a/env_setup/virtualenv/init.py b/env_setup/virtualenv_setup/install.py
similarity index 79%
rename from env_setup/virtualenv/init.py
rename to env_setup/virtualenv_setup/install.py
index 924f590..13733b7 100644
--- a/env_setup/virtualenv/init.py
+++ b/env_setup/virtualenv_setup/install.py
@@ -1,4 +1,4 @@
-# Copyright 2019 The Pigweed Authors
+# Copyright 2020 The Pigweed Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
@@ -15,7 +15,6 @@
 
 from __future__ import print_function
 
-import argparse
 import glob
 import os
 import subprocess
@@ -77,7 +76,7 @@
     ))
 
 
-def init(
+def install(
     venv_path,
     full_envsetup=True,
     requirements=(),
@@ -150,36 +149,3 @@
         env.set('VIRTUAL_ENV', venv_path)
         env.prepend('PATH', venv_bin)
         env.clear('PYTHONHOME')
-
-
-def _main():
-    parser = argparse.ArgumentParser(description=__doc__)
-    parser.add_argument('--venv_path',
-                        required=True,
-                        help='Path at which to create the venv')
-    parser.add_argument('-r',
-                        '--requirements',
-                        default=[],
-                        action='append',
-                        help='requirements.txt files to install')
-    parser.add_argument('--quick-setup',
-                        dest='full_envsetup',
-                        action='store_false',
-                        default='PW_ENVSETUP_FULL' in os.environ,
-                        help=('Do full setup or only minimal checks to see if '
-                              'full setup is required.'))
-    parser.add_argument('--python',
-                        default=sys.executable,
-                        help='Python to use when creating virtualenv.')
-
-    try:
-        init(**vars(parser.parse_args()))
-    except GitRepoNotFound:
-        print('git repository not found', file=sys.stderr)
-        return -1
-
-    return 0
-
-
-if __name__ == '__main__':
-    sys.exit(_main())
diff --git a/env_setup/virtualenv/requirements.in b/env_setup/virtualenv_setup/requirements.in
similarity index 95%
rename from env_setup/virtualenv/requirements.in
rename to env_setup/virtualenv_setup/requirements.in
index 2abcb5f..4810695 100644
--- a/env_setup/virtualenv/requirements.in
+++ b/env_setup/virtualenv_setup/requirements.in
@@ -1,4 +1,4 @@
-# Copyright 2019 The Pigweed Authors
+# Copyright 2020 The Pigweed Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
diff --git a/env_setup/virtualenv/requirements.txt b/env_setup/virtualenv_setup/requirements.txt
similarity index 100%
rename from env_setup/virtualenv/requirements.txt
rename to env_setup/virtualenv_setup/requirements.txt
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 11cd52c..5a18e39 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -68,13 +68,14 @@
 
 def init_virtualenv(ctx: PresubmitContext):
     """Set up virtualenv, assumes recent Python 3 is already installed."""
-    virtualenv_source = ctx.repository_root.joinpath('env_setup/virtualenv')
+    virtualenv_source = ctx.repository_root.joinpath('env_setup',
+                                                     'virtualenv_setup')
 
     # For speed, don't build the venv if it exists. Use --clean to recreate it.
     if not ctx.output_directory.joinpath('pyvenv.cfg').is_file():
         call(
             'python3',
-            virtualenv_source.joinpath('init.py'),
+            virtualenv_source,
             f'--venv_path={ctx.output_directory}',
             '--requirements={}'.format(
                 virtualenv_source.joinpath('requirements.txt')),