py_research.reflect.deps module#

Utils for reflecting the Python dependencies.

get_all_module_dependencies(module, _ext_deps=None, _int_deps=None)[source]#

Return all (indirect) dependency modules of given module.

Parameters:
  • module (module) – Module to inspect.

  • _ext_deps (set[str] | None) –

  • _int_deps (set[module] | None) –

Returns:

Tuple of external and internal dependencies.

Return type:

tuple[set[str], set[module]]

get_dist_requirements(dist)[source]#

Get a list of declared packages via pdm.

Parameters:

dist (Distribution) –

Return type:

list[Requirement] | None

get_versions_on_pypi(package)[source]#

Get all available versions of given distribution.

Parameters:

package (Distribution | str) –

Return type:

set[Version]

version_diff(v1, v2)[source]#

Get the difference between two versions (v1 - v2).

if v1 is smaller than v2, returns None.

Parameters:
  • v1 (Version) –

  • v2 (Version) –

Return type:

Version | None

get_outdated_deps(dist, allowed_diff=<Specifier('<=1.1.1')>)[source]#

Get a list of outdated dependencies of a distribution.

Parameters:
  • dist (Distribution | module) – Distribution to inspect. Can also be supplied as a module within the distribution in question.

  • allowed_diff (Specifier) – Allowed difference between current and latest version.

Returns:

Dictionary of outdated package names with current and latest version.

Return type:

dict[str, tuple[Version, Version]]

version_to_range(version, strategy='major')[source]#

Convert exact version to version range.

Parameters:
  • version (Version) –

  • strategy (Literal['exact', 'minor', 'major']) –

Return type:

str

semver_range_to_spec(semver_range)[source]#

Convert semver range to Python version specifier.

Parameters:

semver_range (str) –

Return type:

SpecifierSet