Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

add graph model #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libcflib/harvest_pkgs.xsh
Original file line number Diff line number Diff line change
@@ -37,8 +37,11 @@ def create_graphs():

for dep in channel_graphs[channel].nodes[pkg]['req']:
if (dep, pkg) not in channel_graphs[channel].edges:
channel_graphs[channel].add_edge(dep, pkg, arch=set())
channel_graphs[channel].add_edge(dep, pkg,
arch=set(),
version=set())
channel_graphs[channel].edges[(dep, pkg)]['arch'].add(arch)
channel_graphs[channel].edges[(dep, pkg)]['version'].add(art['version'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to handle noarch

return channel_graphs


16 changes: 15 additions & 1 deletion libcflib/model.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import os
from typing import Iterator

import networkx as nx


class Model(object):
def __init__(self):
@@ -131,7 +133,6 @@ def __repr__(self):
def _load(self):
env = builtins.__xonsh_env__
filename = os.path.join(env.get("LIBCFGRAPH_DIR"), self._channel + ".json")
# TODO: use networkx to get the data so we have edges
with open(filename, "r") as f:
self._d.update(json.load(f).get(self._name, {}))
super()._load()
@@ -150,3 +151,16 @@ def _load(self):
with open(filename, "r") as f:
self._d.update(json.load(f).get(self._name, {}))
super()._load()


class Graph(Model):
def __init__(self, *, channel="conda-forge"):
self._channel = channel
super().__init__()

def _load(self):
env = builtins.__xonsh_env__
filename = os.path.join(env.get("LIBCFGRAPH_DIR"), "conda-forge.json")
with open(filename, "r") as f:
self._d["graph"] = nx.node_link_graph(json.load(f))
super()._load()
6 changes: 2 additions & 4 deletions libcflib/schemas.py
Original file line number Diff line number Diff line change
@@ -13,8 +13,7 @@
"type": "bool",
},
"PRed": {
"_description": "For each migrator which"
"track which PRs have"
"_description": "For each migrator which track which PRs have "
"been issued",
"type": "list",
"schema": {"type": "string"},
@@ -26,10 +25,9 @@
},
"commit": {"type": "string", "_description": "The latest commit"},
"new_version": {
"anyof_type": ["string", "bool"],
"anyof_type": ["string"],
"_description": "The new version",
},
"meta_yaml": {"type": "dict", "_description": "The meta_yaml"},
},
},
"artifact": {
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@
@pytest.fixture
def tmpgraphdir(tmpdir_factory):
d = tmpdir_factory.mktemp("graph", numbered=False)
d.mkdir('artifacts').mkdir('mypkg').mkdir("/somechannel").mkdir("noarch")
d.mkdir("artifacts").mkdir("mypkg").mkdir("/somechannel").mkdir("noarch")
return d
5 changes: 3 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@

def test_artifact(tmpgraphdir):
d = {"a": "hi", "world": "python"}
art_dir = os.path.join(tmpgraphdir, 'artifacts', 'mypkg', 'somechannel', 'noarch')
art_dir = os.path.join(tmpgraphdir, "artifacts", "mypkg", "somechannel", "noarch")
with open(os.path.join(art_dir, "mypkg.json"), "w") as f:
json.dump(d, f)

env = builtins.__xonsh_env__
env["LIBCFGRAPH_DIR"] = tmpgraphdir
pkg, channel, arch = art_dir.split('/')[-3:]
pkg, channel, arch = art_dir.split("/")[-3:]
n = Artifact(pkg=pkg, channel=channel, arch=arch, name="mypkg")
assert n.a == "hi"
assert n["a"] == "hi"
@@ -22,5 +22,6 @@ def test_artifact(tmpgraphdir):
# make sure we can hash artifacts
hash(n)


# TODO: test package
# TODO: test feedstock