perfetto: consolidate all Python libraries into a single folder

This CL consolidates all the Python libraries which have been written
over the past couple of years into a single top level python/ directory.
This makes it a lot easier to reason about this code, ring-fence
things like build targets and also makes dealing with imports a lot
easier.

Change-Id: Ia0d7637c0993dde51af19ce052e18e4773349596
Bug: 180499808
diff --git a/Android.bp b/Android.bp
index 333d1b1..1fad0af 100644
--- a/Android.bp
+++ b/Android.bp
@@ -10422,14 +10422,14 @@
 
 filegroup {
     name: "perfetto-trace-processor-python-srcs",
-    srcs: ["src/trace_processor/python/perfetto/**/*.py"],
-    path: "src/trace_processor/python",
+    srcs: ["python/perfetto/trace_processor/*.py"],
+    path: "python",
 }
 
 filegroup {
     name: "perfetto-trace-processor-python-data",
-    srcs: ["src/trace_processor/python/perfetto/**/*.descriptor*"],
-    path: "src/trace_processor/python",
+    srcs: ["python/perfetto/trace_processor/*.descriptor*"],
+    path: "python",
 }
 
 // Added automatically by a large-scale-change that took the approach of
diff --git a/Android.bp.extras b/Android.bp.extras
index c447a86..d6deb97 100644
--- a/Android.bp.extras
+++ b/Android.bp.extras
@@ -112,14 +112,14 @@
 
 filegroup {
     name: "perfetto-trace-processor-python-srcs",
-    srcs: ["src/trace_processor/python/perfetto/**/*.py"],
-    path: "src/trace_processor/python",
+    srcs: ["python/perfetto/trace_processor/*.py"],
+    path: "python",
 }
 
 filegroup {
     name: "perfetto-trace-processor-python-data",
-    srcs: ["src/trace_processor/python/perfetto/**/*.descriptor*"],
-    path: "src/trace_processor/python",
+    srcs: ["python/perfetto/trace_processor/*.descriptor*"],
+    path: "python",
 }
 
 // Added automatically by a large-scale-change that took the approach of
diff --git a/BUILD b/BUILD
index 21df06b..723d6a4 100644
--- a/BUILD
+++ b/BUILD
@@ -4187,77 +4187,3 @@
     main = "tools/write_version_header.py",
     python_version = "PY3",
 )
-
-perfetto_py_binary(
-    name = "trace_processor_py_example",
-    srcs = ["src/trace_processor/python/example.py"],
-    deps = [":trace_processor_py"] + PERFETTO_CONFIG.deps.pandas_py,
-    main = "src/trace_processor/python/example.py",
-    python_version = "PY3",
-)
-
-perfetto_py_library(
-    name = "trace_processor_py",
-    srcs = glob(["src/trace_processor/python/perfetto/trace_processor/*.py"]),
-    data = [
-        "src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor",
-        "src/trace_processor/python/perfetto/trace_processor/metrics.descriptor",
-        ":trace_processor_shell",
-    ] + PERFETTO_CONFIG.deps.tp_init_py,
-    deps = PERFETTO_CONFIG.deps.gfile_py + 
-        PERFETTO_CONFIG.deps.protobuf_py + 
-        PERFETTO_CONFIG.deps.protobuf_descriptor_pb2_py + 
-        PERFETTO_CONFIG.deps.pyglib_py,
-    imports = [
-        "src/trace_processor/python",
-    ],
-    visibility = PERFETTO_CONFIG.public_visibility,
-)
-
-perfetto_py_library(
-    name = "experimental_slice_breakdown_lib",
-    srcs = glob(["tools/slice_breakdown/perfetto/slice_breakdown/*.py"]),
-    deps = [
-        ":trace_processor_py",
-    ],
-    imports = [
-        "tools/slice_breakdown",
-    ],
-)
-
-perfetto_py_binary(
-    name = "experimental_slice_breakdown_bin",
-    srcs = ["tools/slice_breakdown/main.py"],
-    main = "tools/slice_breakdown/main.py",
-    deps = [
-        ":experimental_slice_breakdown_lib",
-        ":trace_processor_py",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    python_version = "PY3",
-    legacy_create_init = 0,
-)
-
-perfetto_py_library(
-    name = "batch_trace_processor",
-    srcs = glob([
-      "tools/batch_trace_processor/perfetto/batch_trace_processor/*.py"
-    ]),
-    deps = [
-        ":trace_processor_py",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    imports = [
-        "tools/batch_trace_processor",
-    ],
-)
-
-perfetto_py_binary(
-    name = "batch_trace_processor_shell",
-    srcs = ["tools/batch_trace_processor/main.py"],
-    main = "tools/batch_trace_processor/main.py",
-    deps = [
-        ":trace_processor_py",
-        ":batch_trace_processor",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    python_version = "PY3",
-    legacy_create_init = 0,
-)
diff --git a/BUILD.extras b/BUILD.extras
index 8c39316..f91b2f4 100644
--- a/BUILD.extras
+++ b/BUILD.extras
@@ -92,77 +92,3 @@
     main = "tools/write_version_header.py",
     python_version = "PY3",
 )
-
-perfetto_py_binary(
-    name = "trace_processor_py_example",
-    srcs = ["src/trace_processor/python/example.py"],
-    deps = [":trace_processor_py"] + PERFETTO_CONFIG.deps.pandas_py,
-    main = "src/trace_processor/python/example.py",
-    python_version = "PY3",
-)
-
-perfetto_py_library(
-    name = "trace_processor_py",
-    srcs = glob(["src/trace_processor/python/perfetto/trace_processor/*.py"]),
-    data = [
-        "src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor",
-        "src/trace_processor/python/perfetto/trace_processor/metrics.descriptor",
-        ":trace_processor_shell",
-    ] + PERFETTO_CONFIG.deps.tp_init_py,
-    deps = PERFETTO_CONFIG.deps.gfile_py + 
-        PERFETTO_CONFIG.deps.protobuf_py + 
-        PERFETTO_CONFIG.deps.protobuf_descriptor_pb2_py + 
-        PERFETTO_CONFIG.deps.pyglib_py,
-    imports = [
-        "src/trace_processor/python",
-    ],
-    visibility = PERFETTO_CONFIG.public_visibility,
-)
-
-perfetto_py_library(
-    name = "experimental_slice_breakdown_lib",
-    srcs = glob(["tools/slice_breakdown/perfetto/slice_breakdown/*.py"]),
-    deps = [
-        ":trace_processor_py",
-    ],
-    imports = [
-        "tools/slice_breakdown",
-    ],
-)
-
-perfetto_py_binary(
-    name = "experimental_slice_breakdown_bin",
-    srcs = ["tools/slice_breakdown/main.py"],
-    main = "tools/slice_breakdown/main.py",
-    deps = [
-        ":experimental_slice_breakdown_lib",
-        ":trace_processor_py",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    python_version = "PY3",
-    legacy_create_init = 0,
-)
-
-perfetto_py_library(
-    name = "batch_trace_processor",
-    srcs = glob([
-      "tools/batch_trace_processor/perfetto/batch_trace_processor/*.py"
-    ]),
-    deps = [
-        ":trace_processor_py",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    imports = [
-        "tools/batch_trace_processor",
-    ],
-)
-
-perfetto_py_binary(
-    name = "batch_trace_processor_shell",
-    srcs = ["tools/batch_trace_processor/main.py"],
-    main = "tools/batch_trace_processor/main.py",
-    deps = [
-        ":trace_processor_py",
-        ":batch_trace_processor",
-    ] + PERFETTO_CONFIG.deps.pandas_py,
-    python_version = "PY3",
-    legacy_create_init = 0,
-)
diff --git a/python/BUILD b/python/BUILD
new file mode 100644
index 0000000..fc81845
--- /dev/null
+++ b/python/BUILD
@@ -0,0 +1,94 @@
+# Copyright (C) 2022 The Android Open Source Project
+#
+# 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
+#
+#      http://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.
+
+load("@perfetto_cfg//:perfetto_cfg.bzl", "PERFETTO_CONFIG")
+load(
+    "@perfetto//bazel:rules.bzl",
+    "perfetto_py_binary",
+    "perfetto_py_library",
+)
+
+perfetto_py_binary(
+    name = "trace_processor_py_example",
+    srcs = ["example.py"],
+    deps = [":trace_processor_py"] + PERFETTO_CONFIG.deps.pandas_py,
+    main = "example.py",
+    python_version = "PY3",
+)
+
+perfetto_py_library(
+    name = "trace_processor_py",
+    srcs = glob(["perfetto/trace_processor/*.py"]),
+    data = [
+        "perfetto/trace_processor/trace_processor.descriptor",
+        "perfetto/trace_processor/metrics.descriptor",
+        PERFETTO_CONFIG.root + ":trace_processor_shell",
+    ] + PERFETTO_CONFIG.deps.tp_init_py,
+    deps = PERFETTO_CONFIG.deps.gfile_py +
+        PERFETTO_CONFIG.deps.protobuf_py +
+        PERFETTO_CONFIG.deps.protobuf_descriptor_pb2_py +
+        PERFETTO_CONFIG.deps.pyglib_py,
+    imports = [
+        ".",
+    ],
+    visibility = PERFETTO_CONFIG.public_visibility,
+)
+
+perfetto_py_library(
+    name = "experimental_slice_breakdown_lib",
+    srcs = glob(["perfetto/experimental/slice_breakdown/*.py"]),
+    deps = [
+        ":trace_processor_py",
+    ],
+    imports = [
+        "tools/slice_breakdown",
+    ],
+)
+
+perfetto_py_binary(
+    name = "experimental_slice_breakdown_bin",
+    srcs = ["tools/slice_breakdown.py"],
+    main = "tools/slice_breakdown.py",
+    deps = [
+        ":experimental_slice_breakdown_lib",
+        ":trace_processor_py",
+    ] + PERFETTO_CONFIG.deps.pandas_py,
+    python_version = "PY3",
+    legacy_create_init = 0,
+)
+
+perfetto_py_library(
+    name = "batch_trace_processor",
+    srcs = glob([
+      "perfetto/batch_trace_processor/*.py"
+    ]),
+    deps = [
+        ":trace_processor_py",
+    ] + PERFETTO_CONFIG.deps.pandas_py,
+    imports = [
+        ".",
+    ],
+)
+
+perfetto_py_binary(
+    name = "batch_trace_processor_shell",
+    srcs = ["tools/batch_trace_processor_shell.py"],
+    main = "tools/batch_trace_processor_shell.py",
+    deps = [
+        ":trace_processor_py",
+        ":batch_trace_processor",
+    ] + PERFETTO_CONFIG.deps.pandas_py,
+    python_version = "PY3",
+    legacy_create_init = 0,
+)
diff --git a/src/trace_processor/python/LICENSE b/python/LICENSE
similarity index 100%
rename from src/trace_processor/python/LICENSE
rename to python/LICENSE
diff --git a/src/trace_processor/python/README.md b/python/README.md
similarity index 100%
rename from src/trace_processor/python/README.md
rename to python/README.md
diff --git a/src/trace_processor/python/example.py b/python/example.py
similarity index 100%
rename from src/trace_processor/python/example.py
rename to python/example.py
diff --git a/src/trace_processor/python/perfetto/__init__.py b/python/perfetto/__init__.py
similarity index 100%
rename from src/trace_processor/python/perfetto/__init__.py
rename to python/perfetto/__init__.py
diff --git a/src/trace_processor/python/perfetto/trace_processor/__init__.py b/python/perfetto/batch_trace_processor/__init__.py
similarity index 67%
rename from src/trace_processor/python/perfetto/trace_processor/__init__.py
rename to python/perfetto/batch_trace_processor/__init__.py
index ad09ce6..9d9f785 100644
--- a/src/trace_processor/python/perfetto/trace_processor/__init__.py
+++ b/python/perfetto/batch_trace_processor/__init__.py
@@ -1,5 +1,4 @@
-#!/usr/bin/env python3
-# Copyright (C) 2020 The Android Open Source Project
+# Copyright (C) 2022 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,5 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from .api import LoadableTrace, TraceProcessor, TraceProcessorConfig, TraceProcessorException
-from .http import TraceProcessorHttp
+from perfetto.batch_trace_processor.api import BatchLoadableTrace
+from perfetto.batch_trace_processor.api import BatchTraceProcessorConfig
+from perfetto.batch_trace_processor.api import BatchTraceProcessor
diff --git a/tools/batch_trace_processor/perfetto/batch_trace_processor/api.py b/python/perfetto/batch_trace_processor/api.py
similarity index 99%
rename from tools/batch_trace_processor/perfetto/batch_trace_processor/api.py
rename to python/perfetto/batch_trace_processor/api.py
index dcd640c..caf9f74 100644
--- a/tools/batch_trace_processor/perfetto/batch_trace_processor/api.py
+++ b/python/perfetto/batch_trace_processor/api.py
@@ -12,8 +12,6 @@
 # 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.
-
-
 """Contains classes for BatchTraceProcessor API."""
 
 from concurrent.futures.thread import ThreadPoolExecutor
diff --git a/tools/slice_breakdown/perfetto/slice_breakdown/__init__.py b/python/perfetto/experimental/slice_breakdown/__init__.py
similarity index 78%
rename from tools/slice_breakdown/perfetto/slice_breakdown/__init__.py
rename to python/perfetto/experimental/slice_breakdown/__init__.py
index 6e6169f..53d1e85 100644
--- a/tools/slice_breakdown/perfetto/slice_breakdown/__init__.py
+++ b/python/perfetto/experimental/slice_breakdown/__init__.py
@@ -12,4 +12,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from .breakdown import compute_breakdown, compute_breakdown_for_startup
\ No newline at end of file
+from perfetto.experimental.slice_breakdown.breakdown import compute_breakdown
+from perfetto.experimental.slice_breakdown.breakdown import compute_breakdown_for_startup
\ No newline at end of file
diff --git a/tools/slice_breakdown/perfetto/slice_breakdown/breakdown.py b/python/perfetto/experimental/slice_breakdown/breakdown.py
similarity index 100%
rename from tools/slice_breakdown/perfetto/slice_breakdown/breakdown.py
rename to python/perfetto/experimental/slice_breakdown/breakdown.py
diff --git a/src/trace_processor/python/perfetto/trace_processor/__init__.py b/python/perfetto/trace_processor/__init__.py
similarity index 67%
copy from src/trace_processor/python/perfetto/trace_processor/__init__.py
copy to python/perfetto/trace_processor/__init__.py
index ad09ce6..e151656 100644
--- a/src/trace_processor/python/perfetto/trace_processor/__init__.py
+++ b/python/perfetto/trace_processor/__init__.py
@@ -13,5 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from .api import LoadableTrace, TraceProcessor, TraceProcessorConfig, TraceProcessorException
-from .http import TraceProcessorHttp
+from perfetto.trace_processor.api import LoadableTrace
+from perfetto.trace_processor.api import TraceProcessor
+from perfetto.trace_processor.api import TraceProcessorConfig
+from perfetto.trace_processor.api import TraceProcessorException
+from perfetto.trace_processor.http import TraceProcessorHttp
diff --git a/src/trace_processor/python/perfetto/trace_processor/api.py b/python/perfetto/trace_processor/api.py
similarity index 97%
rename from src/trace_processor/python/perfetto/trace_processor/api.py
rename to python/perfetto/trace_processor/api.py
index 0b67632..3f24a13 100644
--- a/src/trace_processor/python/perfetto/trace_processor/api.py
+++ b/python/perfetto/trace_processor/api.py
@@ -17,14 +17,15 @@
 from urllib.parse import urlparse
 from typing import BinaryIO, Callable, Generator, List, Optional, Tuple, Union
 
-from .http import TraceProcessorHttp
-from .loader import get_loader
-from .protos import ProtoFactory
-from .shell import load_shell
+from perfetto.trace_processor.http import TraceProcessorHttp
+from perfetto.trace_processor.loader import get_loader
+from perfetto.trace_processor.protos import ProtoFactory
+from perfetto.trace_processor.shell import load_shell
 
 # Union of types supported for a trace which can be loaded by shell.
 LoadableTrace = Union[None, str, BinaryIO, Generator[bytes, None, None]]
 
+
 # Custom exception raised if any trace_processor functions return a
 # response with an error defined
 class TraceProcessorException(Exception):
diff --git a/src/trace_processor/python/perfetto/trace_processor/http.py b/python/perfetto/trace_processor/http.py
similarity index 97%
rename from src/trace_processor/python/perfetto/trace_processor/http.py
rename to python/perfetto/trace_processor/http.py
index f3cbfb5..71db4ab 100644
--- a/src/trace_processor/python/perfetto/trace_processor/http.py
+++ b/python/perfetto/trace_processor/http.py
@@ -16,7 +16,7 @@
 import http.client
 from typing import List
 
-from .protos import ProtoFactory
+from perfetto.trace_processor.protos import ProtoFactory
 
 
 class TraceProcessorHttp:
diff --git a/src/trace_processor/python/perfetto/trace_processor/loader.py b/python/perfetto/trace_processor/loader.py
similarity index 100%
rename from src/trace_processor/python/perfetto/trace_processor/loader.py
rename to python/perfetto/trace_processor/loader.py
diff --git a/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor b/python/perfetto/trace_processor/metrics.descriptor
similarity index 100%
rename from src/trace_processor/python/perfetto/trace_processor/metrics.descriptor
rename to python/perfetto/trace_processor/metrics.descriptor
Binary files differ
diff --git a/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor.sha1 b/python/perfetto/trace_processor/metrics.descriptor.sha1
similarity index 74%
rename from src/trace_processor/python/perfetto/trace_processor/metrics.descriptor.sha1
rename to python/perfetto/trace_processor/metrics.descriptor.sha1
index 2291e71..17f0868 100644
--- a/src/trace_processor/python/perfetto/trace_processor/metrics.descriptor.sha1
+++ b/python/perfetto/trace_processor/metrics.descriptor.sha1
@@ -1,6 +1,6 @@
 
 // SHA1(tools/gen_binary_descriptors)
-// 9fc6d77de57ec76a80b76aa282f4c7cf5ce55eec
+// c4a38769074f8a8c2ffbf514b267919b5f2d47df
 // SHA1(protos/perfetto/metrics/metrics.proto)
 // 22722c7fde543d5abd1299f48edd49c69c5f5c3e
   
\ No newline at end of file
diff --git a/src/trace_processor/python/perfetto/trace_processor/protos.py b/python/perfetto/trace_processor/protos.py
similarity index 96%
rename from src/trace_processor/python/perfetto/trace_processor/protos.py
rename to python/perfetto/trace_processor/protos.py
index 37be4f2..0053fdb 100644
--- a/src/trace_processor/python/perfetto/trace_processor/protos.py
+++ b/python/perfetto/trace_processor/protos.py
@@ -19,8 +19,7 @@
 
 class ProtoFactory:
 
-  def __init__(self, tp_descriptor: bytes,
-               metrics_descriptor: bytes):
+  def __init__(self, tp_descriptor: bytes, metrics_descriptor: bytes):
     # Declare descriptor pool
     self.descriptor_pool = DescriptorPool()
 
diff --git a/src/trace_processor/python/perfetto/trace_processor/shell.py b/python/perfetto/trace_processor/shell.py
similarity index 96%
rename from src/trace_processor/python/perfetto/trace_processor/shell.py
rename to python/perfetto/trace_processor/shell.py
index 00749d1..8daa956 100644
--- a/src/trace_processor/python/perfetto/trace_processor/shell.py
+++ b/python/perfetto/trace_processor/shell.py
@@ -18,7 +18,7 @@
 import time
 from urllib import request, error
 
-from .loader import get_loader
+from perfetto.trace_processor.loader import get_loader
 
 
 def load_shell(bin_path, unique_port, verbose):
diff --git a/src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor b/python/perfetto/trace_processor/trace_processor.descriptor
similarity index 100%
rename from src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor
rename to python/perfetto/trace_processor/trace_processor.descriptor
Binary files differ
diff --git a/src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor.sha1 b/python/perfetto/trace_processor/trace_processor.descriptor.sha1
similarity index 76%
rename from src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor.sha1
rename to python/perfetto/trace_processor/trace_processor.descriptor.sha1
index 23712a1..92ce69e 100644
--- a/src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor.sha1
+++ b/python/perfetto/trace_processor/trace_processor.descriptor.sha1
@@ -1,6 +1,6 @@
 
 // SHA1(tools/gen_binary_descriptors)
-// 9fc6d77de57ec76a80b76aa282f4c7cf5ce55eec
+// c4a38769074f8a8c2ffbf514b267919b5f2d47df
 // SHA1(protos/perfetto/trace_processor/trace_processor.proto)
 // e303e1fc877a9fe4f8dd8413c03266ee68dfd3aa
   
\ No newline at end of file
diff --git a/tools/run_python_api_tests.py b/python/run_tests.py
similarity index 82%
rename from tools/run_python_api_tests.py
rename to python/run_tests.py
index 78a78a1..6ac0977 100755
--- a/tools/run_python_api_tests.py
+++ b/python/run_tests.py
@@ -18,6 +18,9 @@
 import sys
 import unittest
 
+from test import api_unittest
+from test import api_integrationtest
+
 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 
@@ -29,13 +32,6 @@
     print('Cannot proceed. Please `pip3 install pandas numpy`', file=sys.stderr)
     return 1
 
-  # Append test and src paths so that all imports are loaded in correctly
-  sys.path.append(os.path.join(ROOT_DIR, 'test', 'trace_processor', 'python'))
-  sys.path.append(
-      os.path.join(ROOT_DIR, 'src', 'trace_processor', 'python', 'perfetto'))
-  import api_unittest
-  import api_integrationtest
-
   # Set paths to trace_processor_shell and root directory as environment
   # variables
   parser = argparse.ArgumentParser()
@@ -43,7 +39,6 @@
   os.environ["SHELL_PATH"] = parser.parse_args().shell
   os.environ["ROOT_DIR"] = ROOT_DIR
 
-  # Initialise test suite
   loader = unittest.TestLoader()
   suite = unittest.TestSuite()
 
diff --git a/src/trace_processor/python/setup.py b/python/setup.py
similarity index 100%
rename from src/trace_processor/python/setup.py
rename to python/setup.py
diff --git a/tools/batch_trace_processor/perfetto/batch_trace_processor/__init__.py b/python/test/__init__.py
similarity index 100%
rename from tools/batch_trace_processor/perfetto/batch_trace_processor/__init__.py
rename to python/test/__init__.py
diff --git a/test/trace_processor/python/api_integrationtest.py b/python/test/api_integrationtest.py
similarity index 94%
rename from test/trace_processor/python/api_integrationtest.py
rename to python/test/api_integrationtest.py
index 03c8d9b..8d83eaf 100644
--- a/test/trace_processor/python/api_integrationtest.py
+++ b/python/test/api_integrationtest.py
@@ -18,9 +18,9 @@
 from typing import Optional
 import unittest
 
-from trace_processor.api import TraceProcessor
-from trace_processor.api import TraceProcessorConfig
-from trace_processor.api import LoadableTrace
+from perfetto.trace_processor.api import TraceProcessor
+from perfetto.trace_processor.api import TraceProcessorConfig
+from perfetto.trace_processor.api import LoadableTrace
 
 
 def create_tp(trace: LoadableTrace):
diff --git a/test/trace_processor/python/api_unittest.py b/python/test/api_unittest.py
similarity index 97%
rename from test/trace_processor/python/api_unittest.py
rename to python/test/api_unittest.py
index 2306e26..732438a 100755
--- a/test/trace_processor/python/api_unittest.py
+++ b/python/test/api_unittest.py
@@ -15,10 +15,10 @@
 
 import unittest
 
-from trace_processor.api import TraceProcessor
-from trace_processor.api import TraceProcessorException
-from trace_processor.api import TraceProcessorConfig
-from trace_processor.protos import ProtoFactory
+from perfetto.trace_processor.api import TraceProcessor
+from perfetto.trace_processor.api import TraceProcessorException
+from perfetto.trace_processor.api import TraceProcessorConfig
+from perfetto.trace_processor.protos import ProtoFactory
 
 TP_CONFIG = TraceProcessorConfig()
 PROTO_FACTORY = ProtoFactory(
diff --git a/tools/batch_trace_processor/main.py b/python/tools/batch_trace_processor_shell.py
similarity index 100%
rename from tools/batch_trace_processor/main.py
rename to python/tools/batch_trace_processor_shell.py
diff --git a/tools/slice_breakdown/main.py b/python/tools/slice_breakdown.py
similarity index 93%
rename from tools/slice_breakdown/main.py
rename to python/tools/slice_breakdown.py
index f6a4c4c..9c481ba 100644
--- a/tools/slice_breakdown/main.py
+++ b/python/tools/slice_breakdown.py
@@ -19,8 +19,8 @@
 import argparse
 import sys
 
-from perfetto.slice_breakdown import compute_breakdown
-from perfetto.slice_breakdown import compute_breakdown_for_startup
+from perfetto.experimental.slice_breakdown import compute_breakdown
+from perfetto.experimental.slice_breakdown import compute_breakdown_for_startup
 from perfetto.trace_processor import TraceProcessor
 from perfetto.trace_processor import TraceProcessorConfig
 
diff --git a/test/ci/linux_tests.sh b/test/ci/linux_tests.sh
index fd165f2..1a68291 100755
--- a/test/ci/linux_tests.sh
+++ b/test/ci/linux_tests.sh
@@ -41,7 +41,7 @@
   --perf-file=/ci/artifacts/perf/tp-perf-all.json \
   ${TP_SHELL}
 
-tools/run_python_api_tests.py ${TP_SHELL}
+python/run_tests.py ${TP_SHELL}
 
 # Don't run benchmarks under x86 (running out of address space because of 4GB)
 # limit or debug (too slow and pointless).
diff --git a/tools/gen_binary_descriptors b/tools/gen_binary_descriptors
index 5388c48..dbbf8c7 100755
--- a/tools/gen_binary_descriptors
+++ b/tools/gen_binary_descriptors
@@ -26,10 +26,10 @@
 
 SOURCE_TARGET = [
     ('protos/perfetto/trace_processor/trace_processor.proto',
-     'src/trace_processor/python/perfetto/trace_processor/trace_processor.descriptor'
+     'python/perfetto/trace_processor/trace_processor.descriptor'
     ),
     ('protos/perfetto/metrics/metrics.proto',
-     'src/trace_processor/python/perfetto/trace_processor/metrics.descriptor'),
+     'python/perfetto/trace_processor/metrics.descriptor'),
 ]
 
 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))