@@ -106,18 +106,16 @@ def is_vcs_package(cls, package: Path | Package, env: Env) -> bool:
106106 return True
107107
108108 @classmethod
109- def create_package_from_distribution (
110- cls , distribution : metadata .Distribution , env : Env
109+ def _create_package_from_distribution (
110+ cls , path : Path , dist_metadata : metadata .PackageMetadata , env : Env
111111 ) -> Package :
112112 # We first check for a direct_url.json file to determine
113113 # the type of package.
114- path = Path (str (distribution ._path )) # type: ignore[attr-defined]
115-
116114 if (
117115 path .name .endswith (".dist-info" )
118116 and path .joinpath ("direct_url.json" ).exists ()
119117 ):
120- return cls .create_package_from_pep610 ( distribution )
118+ return cls ._create_package_from_pep610 ( path , dist_metadata )
121119
122120 is_standard_package = env .is_path_relative_to_lib (path )
123121
@@ -128,9 +126,7 @@ def create_package_from_distribution(
128126 source_subdirectory = None
129127 if is_standard_package :
130128 if path .name .endswith (".dist-info" ):
131- paths = cls .get_package_paths (
132- env = env , name = distribution .metadata ["name" ]
133- )
129+ paths = cls .get_package_paths (env = env , name = dist_metadata ["name" ])
134130 if paths :
135131 is_editable_package = False
136132 for src in paths :
@@ -160,32 +156,33 @@ def create_package_from_distribution(
160156 source_url ,
161157 source_reference ,
162158 ) = cls .get_package_vcs_properties_from_path (
163- env .path / "src" / canonicalize_name (distribution . metadata ["name" ])
159+ env .path / "src" / canonicalize_name (dist_metadata ["name" ])
164160 )
165161 elif is_python_project (path .parent ):
166162 source_type = "directory"
167163 source_url = str (path .parent )
168164
169165 package = Package (
170- distribution . metadata ["name" ],
171- distribution . metadata ["version" ],
166+ dist_metadata ["name" ],
167+ dist_metadata ["version" ],
172168 source_type = source_type ,
173169 source_url = source_url ,
174170 source_reference = source_reference ,
175171 source_resolved_reference = source_resolved_reference ,
176172 source_subdirectory = source_subdirectory ,
177173 )
178174
179- package .description = distribution . metadata .get ( # type: ignore[attr-defined]
175+ package .description = dist_metadata .get ( # type: ignore[attr-defined]
180176 "summary" ,
181177 "" ,
182178 )
183179
184180 return package
185181
186182 @classmethod
187- def create_package_from_pep610 (cls , distribution : metadata .Distribution ) -> Package :
188- path = Path (str (distribution ._path )) # type: ignore[attr-defined]
183+ def _create_package_from_pep610 (
184+ cls , path : Path , dist_metadata : metadata .PackageMetadata
185+ ) -> Package :
189186 source_type = None
190187 source_url = None
191188 source_reference = None
@@ -222,8 +219,8 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack
222219 source_subdirectory = url_reference .get ("subdirectory" )
223220
224221 package = Package (
225- distribution . metadata ["name" ],
226- distribution . metadata ["version" ],
222+ dist_metadata ["name" ],
223+ dist_metadata ["version" ],
227224 source_type = source_type ,
228225 source_url = source_url ,
229226 source_reference = source_reference ,
@@ -232,7 +229,7 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack
232229 develop = develop ,
233230 )
234231
235- package .description = distribution . metadata .get ( # type: ignore[attr-defined]
232+ package .description = dist_metadata .get ( # type: ignore[attr-defined]
236233 "summary" ,
237234 "" ,
238235 )
@@ -273,8 +270,13 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
273270 if path in skipped :
274271 continue
275272
276- name = distribution .metadata .get ("name" ) # type: ignore[attr-defined]
277- if name is None :
273+ dist_metadata = distribution .metadata # type: ignore[attr-defined]
274+ name = (
275+ dist_metadata .get ("name" ) # type: ignore[attr-defined]
276+ if dist_metadata
277+ else None
278+ )
279+ if not dist_metadata or name is None :
278280 logger .warning (
279281 "Project environment contains an invalid distribution"
280282 " (<c1>%s</>). Consider removing it manually or recreate"
@@ -289,21 +291,20 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
289291 if name in seen :
290292 continue
291293
292- package = cls .create_package_from_distribution (distribution , env )
294+ package = cls ._create_package_from_distribution (
295+ path , dist_metadata , env
296+ )
293297
294298 if with_dependencies :
295- for require in distribution . metadata .get_all ("requires-dist" , []):
299+ for require in dist_metadata .get_all ("requires-dist" , []):
296300 dep = Dependency .create_from_pep_508 (require )
297301 package .add_dependency (dep )
298302
299303 seen .add (package .name )
300304 repo .add_package (
301305 package ,
302306 is_system_site = bool (
303- base_env
304- and base_env .is_path_relative_to_lib (
305- Path (str (distribution ._path )) # type: ignore[attr-defined]
306- )
307+ base_env and base_env .is_path_relative_to_lib (path )
307308 ),
308309 )
309310
0 commit comments