← Lesson
Virtual Envs and pip
Joeven
Run
Reset
Python loads on first run
INDEX = { "httpx": ["httpcore", "certifi", "idna"], "httpcore": ["h11", "idna"], "h11": [], "certifi": [], "idna": [], "pytest": ["pluggy", "iniconfig"], "pluggy": [], "iniconfig": [], } req_lines = [ "httpx==0.27.2", "pytest==8.3.2", "# skip comments", "", "unknown-pkg==1.0", ] def parse_line(line): line = line.strip() if not line or line.startswith("#"): return None if "==" in line: name, version = line.split("==", 1) return name.strip(), version.strip() return line.strip(), None def resolve(name): out = [] stack = [name] seen = [] while stack: pkg = stack.pop() if pkg in seen: continue seen.append(pkg) if pkg not in INDEX: print("not in index:", pkg) continue out.append(pkg) needs = INDEX[pkg] i = len(needs) - 1 while i >= 0: stack.append(needs[i]) i -= 1 return out for line in req_lines: parsed = parse_line(line) if parsed is None: continue name, version = parsed print("want", name, "pin", version) print(" pulls", resolve(name))
Run to execute this in your browser. Nothing is sent to a server.