Skip to main content

Ruff

Coherent Software Development System

Coherent deps (dependencies) provides insights into the dependencies used by a code base, resolving imports to the dependencies that supply those imports. The Coherent OSS community presents this library to make the functionality available for a variety of uses.

The Coherent System implements automatic dependency inference using coherent.deps, allowing Python projects to avoid the need to declare dependencies and to instead focus on the implementation.

pip-run leverages this library to enable on-demand installation of dependencies required by scripts, as implied by their imports.

See the code documentation for details. See also the usage in coherent.build for the usage by the build backend.

Design Overview

coherent.deps is implemented primarily by two modules, imports and pypi.

imports performs the function of statically analyzing code to detect imports from a codebase and separate stdlib imports from third-party packages backed by dependencies.

pypi provides the package index support, providing a mapping of imports to package names in PyPI. It leverages a world-readable MongoDB database hosted in MongoDB Atlas to implement the mapping. Each PyPI project gets an entry in the coherent builder:pypi:distributions collection.

Each entry has the following structure:

  • _id: the MongoDB generated unique ID
  • id: the normalized name of the package (e.g. typing-extensions or cherrypy)
  • name: the package's canonical name (e.g. typing_extensions or CherryPy)
  • updated: The last time this package was updated from PyPI
  • downloads: The number of downloads in the past 30 days as returned by the pypinfo query.
  • roots: A collection of root importable names presented by the package (e.g. requests or coherent.deps but not requests.errors).
  • error: Any error that occurred when attempting to process the package.

Only id and downloads are required. An entry without updated is due to be updated by the process routine. An entry without roots or name has never been processed.

Maintaining the mapping

There is a subpackage, distributions, which contains two scripts, load and process (invoked by python -m coherent.deps.distributions.{load,process}) to load the distributions from a "top downloads" summary and then process those by loading their data from PyPI.

To get the full set of "top downloaded" packages that contain at least one download, run this query:

 🐚 pipx run pypinfo --json --indent 0 --limit 800000 --days 30 "" project > ~/Downloads/top-pypi-packages-30-days.json

Note that this pypinfo script requires a Google API key and with a very high limit like 800000, will cost several dollars to run, so the maintainer only runs it about twice a year.

Then, to refresh the database with the downloaded dataset:

 🐚 pip-run coherent.deps -- -m coherent.deps.distributions.load ~/Downloads/top-pypi-packages-30-days.json

This process will ensure that all packages are up-to-date with their latest download stats.

From there, ensure that any newly-added packages are processed:

 🐚 pip-run coherent.deps -- -m coherent.deps.distributions.process

Note that only those entries without an updated field will be processed. To re-process packgaes that may have grown stale, clear the updated field on those entries. For example, to mark stale any entries older than 6 months:

max_age = datetime.timedelta(days=6*30)
filter = {'updated': {'$lt': datetime.today() - max_age}}
op = {'$unset': 'updated'}
collection.update_many(filter, op)

Thereafter, re-run the process routine, which will re-process the packages without the updated field.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coherent_deps-1.6.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coherent_deps-1.6.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file coherent_deps-1.6.1.tar.gz.

File metadata

  • Download URL: coherent_deps-1.6.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for coherent_deps-1.6.1.tar.gz
Algorithm Hash digest
SHA256 8275eeefe0afe162267cfb9a1ffb8c6aa65a42f82c21338f8526aa6db8a11347
MD5 460702a3ca0ed78d35c94fdd38b2bc8b
BLAKE2b-256 e7c7b2ea2e71ed002414aec5562ab2a5b1713663d0544412d7fbe8561553f88e

See more details on using hashes here.

File details

Details for the file coherent_deps-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: coherent_deps-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for coherent_deps-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0669175271226f03cd05753d096e9aabad1447421338f197c87a676288587f33
MD5 b03f995cd7cbb1178b13d32ada9defd5
BLAKE2b-256 f019463b369766147b73e1137551bb7295c6089b012e25f642221806a9550faf

See more details on using hashes here.

Release history Release notifications | RSS feed

1.6.2

2 files

This release

1.6.1 This release

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page