Reland: Remove a bit of sys.path hackery.

Previously main.py would reconfigure sys.path during the execution of
the recipe code in order to make `from recipe_engine import ...` work.
This changes it so that main.py moves up a level, which will make all
known executions of main.py (namely recipes.py, the test runner and
the two bundled launcher scripts) automatically set PYTHONPATH
correctly.

Reland: Spurious quotes in generated .bat file caused invalid
PYTHONPATH entry... but the reland just moves main.py to make all
syspath manipulation unnecessary.

R=fancl, yiwzhang, mohrr

Bug: 1462728
Change-Id: If32c880caa5dc2084fb6255f0bfef392cba225c3
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/5535275
Commit-Queue: Chenlin Fan <fancl@chromium.org>
Reviewed-by: Chenlin Fan <fancl@chromium.org>
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
diff --git a/.gitattributes b/.gitattributes
index ada2a62..5b91166 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,4 +1,5 @@
 /recipes.py         recipes
+/main.py            recipes
 /recipe_engine/**   recipes
 /**/unittests/**   -recipes
 .vpython3           recipes
diff --git a/recipe_engine/main.py b/main.py
similarity index 87%
rename from recipe_engine/main.py
rename to main.py
index 93a8590..18da041 100755
--- a/recipe_engine/main.py
+++ b/main.py
@@ -55,28 +55,12 @@
 _hack_lookup_codecs()
 del _hack_lookup_codecs
 
-# Hack 4; Drop sys.path[0], which is ROOT_DIR/recipe_engine. This prevents user
-# recipe code from doing things like `import util` and getting
-# recipe_engine/util.py.
-#
-# This is needed because main.py lives inside of the recipe_engine folder; when
-# recipes.py invokes this as `python path/to/recipe_engine/main.py`, python puts
-# this directory at the front of sys.path.
-#
-# A better long-term fix would be to move main.py up one level so that the
-# automatically-prepended directory would remove the need for this and the
-# ROOT_DIR bit below.
-sys.path = sys.path[1:]
-
 try:
   import urllib3.contrib.pyopenssl
   urllib3.contrib.pyopenssl.inject_into_urllib3()
 except ImportError:
   pass
 
-ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-sys.path.insert(0, ROOT_DIR)
-
 from recipe_engine.internal import debugger
 
 debugger.engage_debugger()
diff --git a/recipe_engine/internal/commands/bundle/cmd.py b/recipe_engine/internal/commands/bundle/cmd.py
index e87fa5a..89cca94 100644
--- a/recipe_engine/internal/commands/bundle/cmd.py
+++ b/recipe_engine/internal/commands/bundle/cmd.py
@@ -153,13 +153,11 @@
 
 # pylint: disable=line-too-long
 TEMPLATE3_SH = """#!/usr/bin/env bash
-export PYTHONPATH=${BASH_SOURCE[0]%/*}/recipe_engine
-exec vpython3 -u ${BASH_SOURCE[0]%/*}/recipe_engine/recipe_engine/main.py
+exec vpython3 -u ${BASH_SOURCE[0]%/*}/recipe_engine/main.py
 """.strip()
 
 TEMPLATE3_BAT = """@echo off
-set PYTHONPATH="%~dp0\\recipe_engine"
-call vpython3.bat -u "%~dp0\\recipe_engine\\recipe_engine\\main.py"
+call vpython3.bat -u "%~dp0\\recipe_engine\\main.py"
 """.strip()
 # pylint: enable=line-too-long
 
diff --git a/recipe_engine/internal/commands/test/runner.py b/recipe_engine/internal/commands/test/runner.py
index 9db71f8..7e92d1c 100644
--- a/recipe_engine/internal/commands/test/runner.py
+++ b/recipe_engine/internal/commands/test/runner.py
@@ -600,7 +600,7 @@
         # Assuming ANY of those things are still a thing at that point :).
         sys.executable,
         '-u',
-        os.path.join(engine_path, 'recipe_engine', 'main.py'),
+        os.path.join(engine_path, 'main.py'),
         '--package',
         os.path.join(recipe_deps.main_repo.path, RECIPES_CFG_LOCATION_REL),
         '--proto-override',
diff --git a/recipes.py b/recipes.py
index c6ef83a..0c0b2e2 100755
--- a/recipes.py
+++ b/recipes.py
@@ -252,7 +252,7 @@
       '-vpython-spec',
       os.path.join(engine_path, spec),
       '-u',
-      os.path.join(engine_path, 'recipe_engine', 'main.py'),
+      os.path.join(engine_path, 'main.py'),
   ] + args)
 
   if IS_WIN: