Skip to content

Commit

Permalink
Support deps -r <requirements file>
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch committed Jan 22, 2024
1 parent 10f2a23 commit b8b9ea9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
14 changes: 10 additions & 4 deletions honesty/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,27 @@ def checkcache() -> None:
@click.option("--historical", help="yyyy-mm-dd of a historical date to simulate")
@click.option("--have", help="pkg==ver to assume already installed", multiple=True)
@click.option("--use-json", is_flag=True, default=True, show_default=True)
@click.argument("package_name")
@click.option("-r", "--requirement_file")
@click.argument("package_names", nargs=-1)
def deps(
include_extras: bool,
verbose: bool,
flat: bool,
pick: bool,
python_version: str,
sys_platform: str,
package_name: str,
package_names: List[str],
historical: str,
have: List[str],
use_json: bool,
requirement_file: str,
) -> None:
logging.basicConfig(level=logging.DEBUG if verbose else logging.WARNING)

if requirement_file:
# TODO handle comments and whatnot
package_names = Path(requirement_file).read_text().splitlines()

trim_newer: Optional[datetime]
if historical:
trim_newer = datetime.strptime(historical, "%Y-%m-%d").replace(
Expand All @@ -469,7 +475,7 @@ def current_versions_callback(p: str) -> Optional[str]:
seen: Set[Tuple[str, Optional[Tuple[str, ...]], Version]] = set()
assert python_version.count(".") == 2
deptree = DepWalker(
package_name,
package_names,
python_version,
sys_platform,
only_first=pick,
Expand All @@ -480,7 +486,7 @@ def current_versions_callback(p: str) -> Optional[str]:
use_json=use_json,
)
# TODO record constraints on DepEdge, or put in lib to avoid this nonsense
fake_root = DepNode("", version=Version("0"), deps=[DepEdge(target=deptree)])
fake_root = DepNode("", version=Version("0"), deps=[DepEdge(target=x) for x in deptree])
if pick:
print(f"{deptree.name}=={deptree.version}")
elif flat:
Expand Down
13 changes: 6 additions & 7 deletions honesty/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ def _all_current_versions_unknown(cn: str) -> Optional[str]:
class DepWalker:
def __init__(
self,
starting_package: str,
starting_packages: List[str],
python_version: str,
sys_platform: Optional[str] = None,
only_first: bool = False,
trim_newer: Optional[datetime] = None,
) -> None:
self.nodes: Dict[KeyType, DepNode] = {}
self.queue: List[Tuple[Optional[DepNode], str]] = [(None, starting_package)]
self.root: Optional[DepNode] = None
self.queue: List[Tuple[Optional[DepNode], str]] = [(None, pkg) for pkg in starting_packages]
self.roots: List[DepNode] = []
# TODO support unusual versions.
t = ".".join(python_version.split(".")[:2])
self.markers = EnvironmentMarkers(
Expand All @@ -116,7 +116,7 @@ def walk(
include_extras: bool,
current_versions_callback: Optional[VersionCallback] = None,
use_json: bool = True,
) -> DepNode:
) -> List[DepNode]:
if current_versions_callback is None:
current_versions_callback = _all_current_versions_unknown
already_chosen: Dict[str, Version] = {}
Expand Down Expand Up @@ -194,7 +194,7 @@ def walk(
self.nodes[key] = node

if parent is None:
self.root = node
self.roots.append(node)
else:
parent.deps.append(
DepEdge(
Expand Down Expand Up @@ -234,8 +234,7 @@ def walk(
LOG.info(f"enqueue {d!r} for {node!r}")
node.done = True

assert self.root is not None
return self.root
return self.roots

def _do_markers_match(self, marker: Marker, extras: Sequence[str] = ()) -> bool:
env = dict(**asdict(self.markers), extras=Extras(extras))
Expand Down

0 comments on commit b8b9ea9

Please sign in to comment.