This function operates by traversing a DAG and grabbing dependencies of projects found from it. Generally a depth of 1 is recommended, below is a quick guide to what will be returned at each depth.
0: A depth of zero will an empty dictionary unless include_self
is True
. If so, it will include only the library name:
deps = get_installed_dependencies('pipdeptree', depth_limit=0)
assert deps == {}
deps = get_installed_dependencies('pipdeptree', depth_limit=0, include_self=True)
assert deps == {'pipdeptree':'2.2.1'}
1: A depth of one will return the project and its main dependencies (if include_self
is True
), such as those stated in the requirements.txt
as well as packages such as pip
deps = get_installed_dependencies('pipdeptree', depth_limit=1, include_self=True)
assert len(deps.keys()) == 2
assert all(package in deps.keys() for package in ('pipdeptree', 'pip'))
deps = get_installed_dependencies('pipdeptree', depth_limit=1, include_self=False)
assert len(deps.keys()) == 1
assert 'pip' in deps.keys()
2+: A depth of two or greater will return the dependencies for each of the dependencies above that layer. These allow for more fine-grained requirements
Checking for New Versions
Given these dependencies, we can also then check for a new version to see if an upgrade is available. This is what the is_latest_version
function is designed for:
using_latest_version = is_latest_version('pipdeptree', '2.0.9')
assert using_latest_version == False
Here we tested if pipdeptree
is the latest version. The version we specified is one less than that of the latest release at the time of development. We got False
, meaning a newer version is available.
assert get_github_repo_from_pypi("dependency_checker") == "muellerzr/dependency_checker"
assert get_latest_release_notes("dependency_checker") == {}
assert list(get_latest_release_notes("torch").keys()) == ["notes_url", "release_tag"]
def _in_notebook():
try:
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
return True # Jupyter notebook or qtconsole
elif shell == 'TerminalInteractiveShell':
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
With this utility we can quickly get a pretty formatted print of the new version to install, how to install it, and the latest release notes as a link:
check_for_newer_release("torch", "1.9.0")