Skip to content

Commit

Permalink
feat: make dependency search based on metainfo attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
esynr3z committed Jan 22, 2024
1 parent 1e484c2 commit 32a48f9
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pip_hdl/metainfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import pkgutil
from importlib import metadata
from importlib import metadata, import_module
from pathlib import Path
from typing import List, NamedTuple, Optional

Expand Down Expand Up @@ -38,20 +38,19 @@ def __init__(self, py_pkg_name: str) -> None:
def dependencies(self) -> List[PackageMetaInfo]:
"""Dependencies of the current package.
Dependencies search is based on the presense of filelist.
Dependency search is based on the presense of `metainfo` attribute within top-module.
"""
if self._dependencies is None:
self._dependencies = []

required_packages = metadata.requires(self.name)
if required_packages is not None:
for spec in required_packages:
req = Requirement(spec)
req_metainfo = PackageMetaInfo(req.name)
try:
req_metainfo.filelist
self._dependencies.append(req_metainfo)
except FileNotFoundError:
module = import_module(Requirement(spec).name)
if isinstance(module.metainfo, PackageMetaInfo):
self._dependencies.append(module.metainfo)
except (ImportError, AttributeError) as _:
pass
return self._dependencies

Expand Down

0 comments on commit 32a48f9

Please sign in to comment.