| 2675 | |
| 2676 | @staticmethod |
| 2677 | def new_state( |
| 2678 | id: str | None, |
| 2679 | path: str | None, |
| 2680 | source: str | None, |
| 2681 | manager: BuildManager, |
| 2682 | caller_state: State | None = None, |
| 2683 | caller_line: int = 0, |
| 2684 | ancestor_for: State | None = None, |
| 2685 | root_source: bool = False, |
| 2686 | # If `temporary` is True, this State is being created to just |
| 2687 | # quickly parse/load the tree, without an intention to further |
| 2688 | # process it. With this flag, any changes to external state as well |
| 2689 | # as error reporting should be avoided. |
| 2690 | temporary: bool = False, |
| 2691 | ) -> State: |
| 2692 | if not temporary: |
| 2693 | assert id or path or source is not None, "Neither id, path nor source given" |
| 2694 | State.order_counter += 1 |
| 2695 | if caller_state: |
| 2696 | import_context = caller_state.import_context.copy() |
| 2697 | import_context.append((caller_state.xpath, caller_line)) |
| 2698 | else: |
| 2699 | import_context = [] |
| 2700 | id = id or "__main__" |
| 2701 | options = manager.options.clone_for_module(id) |
| 2702 | manager.import_options[id] = options.dep_import_options() |
| 2703 | |
| 2704 | ignore_all = False |
| 2705 | if not path and source is None: |
| 2706 | assert id is not None |
| 2707 | try: |
| 2708 | path, follow_imports = find_module_and_diagnose( |
| 2709 | manager, |
| 2710 | id, |
| 2711 | options, |
| 2712 | caller_state, |
| 2713 | caller_line, |
| 2714 | ancestor_for, |
| 2715 | root_source, |
| 2716 | skip_diagnose=temporary, |
| 2717 | ) |
| 2718 | except ModuleNotFound as exc: |
| 2719 | if not temporary: |
| 2720 | manager.missing_modules[id] = exc.reason |
| 2721 | raise |
| 2722 | if follow_imports == "silent": |
| 2723 | ignore_all = True |
| 2724 | elif path and is_silent_import_module(manager, path) and not root_source: |
| 2725 | ignore_all = True |
| 2726 | |
| 2727 | meta = None |
| 2728 | meta_ex = None |
| 2729 | interface_hash = b"" |
| 2730 | meta_source_hash = None |
| 2731 | if path and source is None and manager.cache_enabled: |
| 2732 | meta_pair = find_cache_meta(id, path, manager) |
| 2733 | # TODO: Get mtime if not cached. |
| 2734 | if meta_pair is not None: |