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.2.tar.gz (14.0 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.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coherent_deps-1.6.2.tar.gz
  • Upload date:
  • Size: 14.0 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.2.tar.gz
Algorithm Hash digest
SHA256 0e9b52366d690ed8b50904c9e998ac31347aea89d822eaf380184e8eb464289c
MD5 ae853e47528571cde1ae632487a75c05
BLAKE2b-256 82aad94160debb084ffea002cc0e0fdfa2fbae096c9731cc702dade35393de7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coherent_deps-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e4aed0067ebeb1bf0c0b004c55839c3edfa9e48c5b273bba435241c77f9dfdf0
MD5 776e71aa5e4a5221ca28cd15ecc8134e
BLAKE2b-256 c36dd0d7eb1cb8f270b44e4f28ac51be3ab3cc7fa8be9ea581b2c012ad918b79

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.6.2 This release

2 files

1.6.1

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