Package: omnidep
A Python linter to compare a project’s declared dependencies against the import
statements in its source code.PurposeProvides warnings when a project imports packages that it doesn’t declare a
dependency on, plus some related linting of the project dependency data.Currently only poetry projects are supported (configured in pyproject.toml).
The projects that your project depends on can be packaged using any tools, but
your project (that omnidep analyses) currently must use poetry.InstallationpipinstallomnidepOptionally, you can also run the test suite. This would be a good idea if
you’re using a new (or pre-release) version of Python not included in this
repo’s CI testing.pipinstallpyOpenSSLopentelemetry-apiopentelemetry-sdkpytestpytest--pyargsomnidep.tstUsageomnideppyproject.tomlConfigurationomnidep uses your project’s poetry configuration to work out:What source files to search for imports, fromtool.poetry.packages.What dependencies your project declares, fromtool.poetry.dependencies.What dev-dependencies your project declares, fromtool.poetry.dev-dependenciesandtool.poetry.group.dev.dependencies.If you have test code that you want omnidep to search for imports, then:If you keep your test code “inside” your project, then list it inlocal-test-pathsin the[tool.omnidep]section described below,
otherwise omnidep treats it as regular code.If you keep your test code “outside” your project, then either use the--testscommand-line option to locate it, or list it inlocal-test-pathsin[tool.omnidep], otherwise omnidep ignores it. You
also need to configurelocal-test-packagesif some of your test files
import other test files, for example if you have shared helper functions.omnidep is configured using thepyproject.tomlfile, and specifically the[tool.omnidep]section. Unrecognised keys are rejected and omnidep will not
run (so, if you want to use a particular key then you should require at least
the minimum version of omnidep that recognises it). The following config keys
are recognised:ignore-importsExample:ignore-imports= ["X"]Since: 0.2.0Causes omnidep to ignore all import statements from X, for exampleimport X,from X.Y import Z. omnidep will behave as if your code does
not use package X, even if it does. X must be a top-level package. It is not
currently possible to selectively ignore a sub-package (like X.Y), nor is it
currently possible to ignore imports from some files but not others.child-packagesExample:child-packages= {boto3 =["botocore"]}Since: 0.2.0Causes omnidep to consider a dependency on boto3 to also supply botocore. This
saves you having to explictly list the child as a dependency of your project.
You should only do this when the child is inherent to the parent, not just
because by chance you pull in a package you need via an indirect dependency.
The reason is that indirect dependencies can change, and the project that you
do depend on might not require the same version of the child that your usage
requires. Only if the projects are closely related can you assume that the
version you require of one will provide the features you need from the other.ignore-dependenciesExample:ignore-dependencies= ["X"]Since: 0.2.0Causes omnidep to ignore the project X listed in your project’s dependencies.
omnidep will behave as if your project does not depend on X, even if it does.ignore-dependencies-orderExample:ignore-dependencies-order= trueSince: 0.2.0Causes omnidep to skip the check that your dependencies are alphabetically
ordered.ignore-dev-dependencies-orderExample:ignore-dev-dependencies-order= trueSince: 0.2.0Causes omnidep to skip the check that your dev-dependencies are alphabetically
ordered.local-test-pathsExample:local-test-paths=["myproject/tests/"]Since: 0.2.0Causes omnidep to treat all code inmyproject.testsas test code, meaning
that anything it imports can be provided either by your project’s dependencies
or by its dev-dependencies. Imports from code that is not test code must be
provided by non-dev dependencies.local-test-packagesExample:local-test-packages= ["tests"]Since: 0.2.0Causes omnidep to treattestsas part of the current project, but only when
considering imports that appear in test code. Use this when your test code is
not shipped as part of your project.Error codes explainedX, Y, P, Q, R, represent the names of imports or dependencies, depending on the
message.ODEP001package 'X' is imported but not listed in dependenciespackage 'X' is imported but not listed indev-dependenciesX is the name you imported, which is not necessarily the same as the name of
the project you have to install (for example the projectbeautifulsoup4installs the packagebs4). omnidep does its best to find what project your
desired package comes from, but if it fails, or if you don’t have a suitable
dependency, then this is the result.If the name you imported is found in a project that’s installed (just not
listed in your dependencies), then X is the name of the project you need,
rather than the name you imported.To fix, choose one of the following:List the project name in your dependencies. If the package is used from test
code, then the dependency can be either dev or non-dev. If the package is
used from non-test code, then the dependency needs to be non-dev.To ignore the import, add it to the list of ignored imports in your[tool.omnidep]config, likeignore-imports= ["X"].The package might come from a dependency of a dependency, and you might
prefer not to explicitly list it as a direct dependency too, so you can list
X as a child of some other dependency that you do list. You should only do
this when the indirect dependency is inherent to the direct dependency, for
exampleboto3providesbotocore. Addchild-packages= {something =["X"]}to your[tool.omnidep]config,
meaning that the project named “something” provides “X”, and so a dependency
on “something” is acceptable in place of a dependency on “X”.ODEP002module 'X' is imported but not installedNot only is there no dependency found that provides X, but X isn’t even
currently installed. omnidep relies on locally installed metadata to help it
find what dependencies correspond to what imports.To fix, choose one of the following:If your project has X as a dependency, but you haven’t installed your
project then install your project, bringing in its dependencies.Add a dependency that provides X.Ignore the import by listing it in your in your[tool.omnidep]config,
likeignore-imports= ["X"].ODEP003Namespace package found: any of ['P', 'Q', 'R'] might provide 'X'If projects P, Q, and R all provide code in the Python package X, then omnidep
doesn’t know which one you need in order to satisfy a given import. If you
declare dependencies on all of them (that is, all the ones you currently have
installed), then omnidep is satisfied. If you depend on some but not others,
then you get this message.To fix, choose one of the following:If you don’t need the ones you don’t declare dependencies on, and they are
installed accidentally, then uninstall them.If appropriate, declare dependencies on all of P, Q, and R. However, this
might not be appropriate because P and Q might be genuine direct dependencies
of your code, whereas R was pulled in indirectly via something else. You
don’t want to have to list indirect dependencies as direct dependencies.Otherwise you have to resolve for yourself whether your dependencies are
adequate, then ignore the import withignore-imports= ["X"]in your[tool.omnidep]config.ODEP004Namespace package found: any of ['P', 'Q', 'R'] might provide 'X', and there are no dependencies on any of themIf projects P, Q, and R all provide code in the Python package X, then omnidep
doesn’t know which one you need in order to satisfy a given import. If you
declare dependencies on all of them (that is, all the ones you currently have
installed), then omnidep is satisfied. If you depend on none of them,
then you get this message.To fix, choose one of the following:If appropriate, declare dependencies on all of P, Q, and R. However, this
might not be appropriate because P and Q might be genuine direct dependencies
of your code, whereas R was pulled in indirectly via something else. You
don’t want to have to list indirect dependencies as direct dependencies.Otherwise you have to resolve for yourself whether your dependencies are
adequate, then ignore the import withignore-imports= ["X"]in your[tool.omnidep]config.ODEP005unused dependencies in project file: {'X', 'Y'}omnidep expects you not to list any dependencies that you don’t import. This
might be completely legitimate, for example:the dependency is a plugin to some framework and will be used via some means
other than an explicitimportin your code;you are controlling the version of an indirect dependency, to deal with
some problem caused by unexpected breaking changes.Unused dev-dependencies are always ignored, since they tend to include linters
and suchlike.To fix, choose one of the following:Remove the dependency.List the dependency in your[tool.omnidep]config likeignore-dependencies= ["X"].ODEP006dependencies are not sorted: 'Y' before 'X'dev-dependenciesare not sorted: 'Y' before 'X'Ignoringpython, which is allowed to come first, omnidep expects you to
list dependencies in case-insensitive alphabetical order within each section
(dev and non-dev).To fix, choose one of the following:List your dependencies alphabetically.Setignore-dependencies-order= trueorignore-dev-dependencies-order= truein your[tool.omnidep]config.ODEP007dependency 'X' is not the preferred name: consider 'Y'omnidep expects you to use either of two formats to name dependencies in your
project file: the “Normalized Name” as defined inPEP 503or the name the dependency uses
for itself in its metadata. Any name that normalizes to the same value will
work, but inconsistent naming tends to lead to confusion, or to failing to find
mentions when you search for them.To fix:Use the name omnidep suggests, or the normalized name.ODEP008Module 'X' not under package management but found on python pathomnidep cannot find any project that provides X, but it is available to import.
This can happen for example if you have set up thePYTHONPATHto find the
code, instead of installing it as a dependency.To fix, choose one of the following:If this is an error, list a suitable dependency.If this occurs when your test code is importing other modules also within
your test code (for example helper utilities) then you can configurelocal-test-packages= ["X"]in your[tool.omnidep]config, and/orlocal-test-pathswith the location of the test source.If you know what you’re doing, and users of your project will know how to
supply the code that you’re importing, then ignore the import withignore-imports= ["X"]in your[tool.omnidep]config.Changelog0.3.6Add Python 3.12 to the test matrix, and to the trove classifiers.Correction to the documentation for the ODEP001 error message
(https://github.com/sjjessop/omnidep/issues/4)0.3.5No longer depend on importlib-metadata or tomli in Python versions that
have equivalent built-in libraries.0.3.4Report unused dependencies as a sorted listAllowpython-momnidep(https://github.com/sjjessop/omnidep/issues/2)0.3.3Treat local-test-paths config more like –tests option.Non-zero exit code if there are any errors reported.Documentation improvements.0.3.2Read dev dependencies from the new location used by Poetry 1.2.0+Add Python 3.11 to PyPI classifiers.0.3.1Add Python 3.11 to the test matrix, and use separate badges in the README
for what is tagged on PyPI vs. what is tested.Documentation improvements.Uncap Python dependency. If Python ever reaches version 4, you are free to
install omnidep on it and see what happens!0.3.0Breaking: When testing that dependencies are sorted, do it case-insensitive.Deal with some build issues.0.2.1Refer to online docs insted of long message in terminal.Publish to PyPI.0.2.0Minor documentation improvements.Lower bounds for dependencies importlib-metadata, isort, and tomli.CI test of the lower-bound versions.