Put cros_venv inside the venv
BUG=chromium:708735
TEST=Run versioned venv script
TEST=Run old venv script
TEST=Run tests
Change-Id: I5bd21142b6a528e97f6e739c23085d1d37265a58
Reviewed-on: https://chromium-review.googlesource.com/470709
Commit-Ready: Allen Li <ayatane@chromium.org>
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/bin/create_venv b/bin/create_venv
index fecf7a0..6f2c976 100755
--- a/bin/create_venv
+++ b/bin/create_venv
@@ -11,5 +11,5 @@
# installed. The path to the created virtualenv is printed to stdout.
set -eu
basedir=$(readlink -f -- "$(dirname -- "${BASH_SOURCE[0]}" )")
-venvdir=$(cd "$basedir"; cd ..; pwd)
-PYTHONPATH="$venvdir" /usr/bin/python2.7 -m cros_venv.scripts.create_venv "$@"
+venvdir=$(cd "${basedir}"; cd ../venv; pwd)
+PYTHONPATH="${venvdir}" /usr/bin/python2.7 -m cros_venv.scripts.create_venv "$@"
diff --git a/bin/run_tests b/bin/run_tests
index 092fc63..851e5bc 100755
--- a/bin/run_tests
+++ b/bin/run_tests
@@ -2,10 +2,14 @@
# Copyright 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+#
+# Run unit tests.
set -eu
+
cd -- "$(readlink -e -- "$(dirname -- "$0")")"
. ./find_virtualenv.sh
-cd ..
+cd ../venv
+
find . -name "*.pyc" -print0 | xargs -0 rm -f
while getopts v name; do
case $name in
diff --git a/create_venv b/create_venv
index ede60cd..13abe9f 100755
--- a/create_venv
+++ b/create_venv
@@ -11,4 +11,4 @@
# option.
set -eu
basedir=$(readlink -f "$(dirname "${BASH_SOURCE[0]}" )")
-PYTHONPATH="$basedir" /usr/bin/python -m cros_venv "$@"
+PYTHONPATH="$basedir/venv" /usr/bin/python -m cros_venv "$@"
diff --git a/cros_venv/__init__.py b/cros_venv/__init__.py
deleted file mode 100644
index 62ef90d..0000000
--- a/cros_venv/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2017 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""This package contains modules for creating and updating virtualenvs.
-
-To run the tests, use the script bin/run_tests.
-"""
diff --git a/venv/cros_venv/__init__.py b/venv/cros_venv/__init__.py
new file mode 100644
index 0000000..5097e3a
--- /dev/null
+++ b/venv/cros_venv/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""This package contains modules for creating and updating virtualenvs.
+
+To run the tests, use the script bin/run_tests.
+
+This package is used to create virtualenvs, so it cannot depend on any
+libraries outside of the Python standard library. The unit tests are
+exempt and may depend on libraries installed through virtualenv (serving
+as a self-test that create_venv works).
+"""
diff --git a/cros_venv/__main__.py b/venv/cros_venv/__main__.py
similarity index 100%
rename from cros_venv/__main__.py
rename to venv/cros_venv/__main__.py
diff --git a/cros_venv/constants.py b/venv/cros_venv/constants.py
similarity index 90%
rename from cros_venv/constants.py
rename to venv/cros_venv/constants.py
index 3292ac0..46a36b1 100644
--- a/cros_venv/constants.py
+++ b/venv/cros_venv/constants.py
@@ -27,4 +27,4 @@
_CROS_VENV_DIR = os.path.abspath(cros_venv.__path__[0])
# Root directory of infra_virtualenv repo
-REPO_DIR = os.path.dirname(_CROS_VENV_DIR)
+REPO_DIR = os.path.abspath(os.path.join(_CROS_VENV_DIR, '..', '..'))
diff --git a/cros_venv/flock.py b/venv/cros_venv/flock.py
similarity index 100%
rename from cros_venv/flock.py
rename to venv/cros_venv/flock.py
diff --git a/cros_venv/scripts/__init__.py b/venv/cros_venv/scripts/__init__.py
similarity index 100%
rename from cros_venv/scripts/__init__.py
rename to venv/cros_venv/scripts/__init__.py
diff --git a/cros_venv/scripts/create_venv.py b/venv/cros_venv/scripts/create_venv.py
similarity index 100%
rename from cros_venv/scripts/create_venv.py
rename to venv/cros_venv/scripts/create_venv.py
diff --git a/venv/cros_venv/test_constants.py b/venv/cros_venv/test_constants.py
new file mode 100644
index 0000000..ca51ab3
--- /dev/null
+++ b/venv/cros_venv/test_constants.py
@@ -0,0 +1,21 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals
+
+import os
+import unittest
+
+from cros_venv import constants
+
+
+class ConstantsTestCase(unittest.TestCase):
+ """TestCase for constants."""
+
+ def test_REPO_DIR(self):
+ """Test that REPO_DIR is a git repo."""
+ self.assertTrue(
+ os.path.isdir(os.path.join(constants.REPO_DIR, '.git')))
diff --git a/cros_venv/test_flock.py b/venv/cros_venv/test_flock.py
similarity index 100%
rename from cros_venv/test_flock.py
rename to venv/cros_venv/test_flock.py
diff --git a/cros_venv/test_venvlib.py b/venv/cros_venv/test_venvlib.py
similarity index 100%
rename from cros_venv/test_venvlib.py
rename to venv/cros_venv/test_venvlib.py
diff --git a/cros_venv/testcases.py b/venv/cros_venv/testcases.py
similarity index 100%
rename from cros_venv/testcases.py
rename to venv/cros_venv/testcases.py
diff --git a/cros_venv/venvlib.py b/venv/cros_venv/venvlib.py
similarity index 100%
rename from cros_venv/venvlib.py
rename to venv/cros_venv/venvlib.py