diff options
author | zaverden <zaverden@yandex-team.com> | 2024-10-03 20:00:44 +0300 |
---|---|---|
committer | zaverden <zaverden@yandex-team.com> | 2024-10-03 20:11:26 +0300 |
commit | a1e28b476a1218b7edb7573228513eae85e84eb9 (patch) | |
tree | 7824b898c65171ae9ae9740b4665aedfccb92b05 | |
parent | dc3750a31cc61b7bd4d7d5b6195ddfd6f3843c7d (diff) | |
download | ydb-a1e28b476a1218b7edb7573228513eae85e84eb9.tar.gz |
feat(builder): add tracing to node_modules
commit_hash:a90772ebe7455e03b8882a87230324f1f13426dc
4 files changed, 52 insertions, 11 deletions
diff --git a/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py b/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py index cdf2b5f90e..6339342594 100644 --- a/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py +++ b/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py @@ -3,11 +3,13 @@ import tempfile import logging from .utils import build_nm_path +from .timeit import timeit PEERS_DIR = ".peers" PEERS_INDEX = "index" +@timeit def bundle_node_modules(build_root, peers, node_modules_path, bundle_path): """ Creates node_modules bundle. diff --git a/build/plugins/lib/nots/package_manager/base/timeit.py b/build/plugins/lib/nots/package_manager/base/timeit.py new file mode 100644 index 0000000000..c0b25daee4 --- /dev/null +++ b/build/plugins/lib/nots/package_manager/base/timeit.py @@ -0,0 +1,29 @@ +import importlib + + +def import_optional_module(module_name): + # Initialize the cache attribute if it does not exist + if not hasattr(import_optional_module, 'cache'): + import_optional_module.cache = {} + + # Check if the module is already in the cache + if module_name in import_optional_module.cache: + return import_optional_module.cache[module_name] + + # Attempt to import the module + try: + module = importlib.import_module(module_name) + except ImportError: + module = None + + # Cache the result + import_optional_module.cache[module_name] = module + return module + + +def timeit(func): + logging = import_optional_module("devtools.frontend_build_platform.libraries.logging") + if logging: + return logging.timeit(func) + else: + return func diff --git a/build/plugins/lib/nots/package_manager/base/ya.make b/build/plugins/lib/nots/package_manager/base/ya.make index a184e1e39e..f35706c599 100644 --- a/build/plugins/lib/nots/package_manager/base/ya.make +++ b/build/plugins/lib/nots/package_manager/base/ya.make @@ -11,12 +11,14 @@ PY_SRCS( node_modules_bundler.py package_json.py package_manager.py + timeit.py utils.py ) PEERDIR( contrib/python/six library/python/archive + devtools/frontend_build_platform/libraries/logging ) END() diff --git a/build/plugins/lib/nots/package_manager/pnpm/package_manager.py b/build/plugins/lib/nots/package_manager/pnpm/package_manager.py index c6d8bbb342..43e6cbfe15 100644 --- a/build/plugins/lib/nots/package_manager/pnpm/package_manager.py +++ b/build/plugins/lib/nots/package_manager/pnpm/package_manager.py @@ -7,6 +7,7 @@ from .workspace import PnpmWorkspace from ..base import BasePackageManager, PackageManagerError from ..base.constants import NODE_MODULES_WORKSPACE_BUNDLE_FILENAME from ..base.node_modules_bundler import bundle_node_modules +from ..base.timeit import timeit from ..base.utils import b_rooted, build_nm_bundle_path, build_pj_path, home_dir, s_rooted @@ -37,6 +38,7 @@ class PnpmPackageManager(BasePackageManager): def get_local_pnpm_store(): return os.path.join(home_dir(), ".cache", "pnpm-store") + @timeit def create_node_modules(self, yatool_prebuilder_path=None, local_cli=False, bundle=True): """ Creates node_modules directory according to the lockfile. @@ -56,6 +58,20 @@ class PnpmPackageManager(BasePackageManager): # It's a default value of pnpm itself. But it should be defined explicitly for not using values from the lockfiles or from the previous installations. virtual_store_dir = self._nm_path('.pnpm') + self._run_pnpm_install(store_dir, virtual_store_dir) + self._run_apply_addons_if_need(yatool_prebuilder_path, virtual_store_dir) + self._replace_internal_lockfile_with_original(virtual_store_dir) + + if not local_cli and bundle: + bundle_node_modules( + build_root=self.build_root, + node_modules_path=self._nm_path(), + peers=ws.get_paths(base_path=self.module_path, ignore_self=True), + bundle_path=os.path.join(self.build_path, NODE_MODULES_WORKSPACE_BUNDLE_FILENAME), + ) + + @timeit + def _run_pnpm_install(self, store_dir: str, virtual_store_dir: str): install_cmd = [ "install", "--frozen-lockfile", @@ -76,17 +92,6 @@ class PnpmPackageManager(BasePackageManager): self._exec_command(install_cmd) - self._run_apply_addons_if_need(yatool_prebuilder_path, virtual_store_dir) - self._replace_internal_lockfile_with_original(virtual_store_dir) - - if not local_cli and bundle: - bundle_node_modules( - build_root=self.build_root, - node_modules_path=self._nm_path(), - peers=ws.get_paths(base_path=self.module_path, ignore_self=True), - bundle_path=os.path.join(self.build_path, NODE_MODULES_WORKSPACE_BUNDLE_FILENAME), - ) - def calc_prepare_deps_inouts_and_resources( self, store_path: str, has_deps: bool ) -> tuple[list[str], list[str], list[str]]: @@ -180,6 +185,7 @@ class PnpmPackageManager(BasePackageManager): if errors: raise PackageManagerError("Unable to process some lockfiles:\n{}".format("\n".join(errors))) + @timeit def _prepare_workspace(self): lf = self.load_lockfile(build_pre_lockfile_path(self.build_path)) lf.update_tarball_resolutions(lambda p: "file:" + os.path.join(self.build_root, p.tarball_url)) @@ -232,6 +238,7 @@ class PnpmPackageManager(BasePackageManager): ws.write() + @timeit def _run_apply_addons_if_need(self, yatool_prebuilder_path, virtual_store_dir): if not yatool_prebuilder_path: return @@ -252,6 +259,7 @@ class PnpmPackageManager(BasePackageManager): shutil.copyfile(original_lf_path, vs_lf_path) + @timeit def _copy_pnpm_patches(self): pj = self.load_package_json_from_dir(self.sources_path) patchedDependencies: dict[str, str] = pj.data.get("pnpm", {}).get("patchedDependencies", {}) |