diff --git a/source/ast/modulePath.ml b/source/ast/modulePath.ml index 274b2e1b8b4..c7f88bb504d 100644 --- a/source/ast/modulePath.ml +++ b/source/ast/modulePath.ml @@ -185,14 +185,27 @@ let relative { raw = { Raw.relative; _ }; _ } = relative let is_in_project { is_external; _ } = not is_external -let create_for_testing ~relative ~is_external ~priority = - let raw = Raw.{ relative; priority } in +let create_from_raw_for_testing ~is_external ({ Raw.relative; _ } as raw) = let qualifier = qualifier_from_relative_path relative in let is_stub = PyrePath.is_path_python_stub relative in let is_init = PyrePath.is_path_python_init relative in { raw; qualifier; is_stub; is_external; is_init } +let create_for_testing ~relative ~is_external ~priority = + let raw = Raw.{ relative; priority } in + create_from_raw_for_testing ~is_external raw + + +let create_for_in_memory_scratch_project ~configuration ~relative ~is_external = + let raw = + let { Configuration.Analysis.local_root; _ } = configuration in + let path_in_local_root = PyrePath.create_relative ~root:local_root ~relative in + Raw.create ~configuration (ArtifactPath.create path_in_local_root) |> Option.value_exn + in + create_from_raw_for_testing ~is_external raw + + let full_path ~configuration { raw; _ } = Raw.full_path ~configuration raw (* NOTE: This comparator is expected to operate on SourceFiles that are mapped to the same module diff --git a/source/ast/modulePath.mli b/source/ast/modulePath.mli index 0dc550fdda8..ea369e2dbdb 100644 --- a/source/ast/modulePath.mli +++ b/source/ast/modulePath.mli @@ -44,6 +44,12 @@ val relative : t -> string val is_in_project : t -> bool +val create_for_in_memory_scratch_project + : configuration:Configuration.Analysis.t -> + relative:string -> + is_external:bool -> + t + val create_for_testing : relative:string -> is_external:bool -> priority:int -> t val qualifier_from_relative_path : string -> Reference.t diff --git a/source/test/test.ml b/source/test/test.ml index d708f585551..4847615c806 100644 --- a/source/test/test.ml +++ b/source/test/test.ml @@ -3065,7 +3065,9 @@ module ScratchProject = struct let in_memory_sources = let to_in_memory_source (relative, content) ~is_external = let code = trim_extra_indentation content in - let module_path = ModulePath.create_for_testing ~relative ~is_external ~priority:1 in + let module_path = + ModulePath.create_for_in_memory_scratch_project ~configuration ~relative ~is_external + in module_path, code in List.map sources ~f:(to_in_memory_source ~is_external:false)