Deptry could lookup metedata only once
akeeman opened this issue · 3 comments
<continuing discussion started in #333>
deptry.dependency.Dependency::found
and deptry.dependency.Dependency::find_metadata
seem to be unused outside of the class itself. They may be internalized, so the class can be simplified by skipping creating found
all together.
try:
top_levels += self._get_top_level_module_names_from_top_level_txt()
if not top_levels:
top_levels += self._get_top_level_module_names_from_record_file()
except PackageNotFoundError:
pass # may do `top_levels.append(name.replace("-", "_").lower())` here, see #335
To add, from here:
Currently, deptry
contains some potentially confusing behavior. When python-dotenv
is in the dependencies, but not installed (so it has no metadata), with the following configuration:
[tool.deptry.package_module_name_map]
python-dotenv = [
"dotenv",
]
a warning is still shown:
Warning: Package 'python-dotenv' not found in current environment. Assuming its corresponding module name is 'python_dotenv'.
I think this is now undesired behavior? As a user I would expect that, since I manually specified which module I want the dependency to map to, I do not expect to see a warning, since I already specified how I want this package to be dealt with.
Note that the warning is actually not necessarily correct. The Assuming its corresponding module name is 'python_dotenv'
part is not a consequence of not finding the metadata. It 's a consequence of (always) adding the translation to the top level module name set.
Whether or not to add the translated package name should be discussed in #335.
Given that, I think the warning message could be improved by removing the part mentioned above.
Furthermore, as property found
is currently unused, you may decide to remove it, eliminating the metadata lookup when pre-configured top level module names are set for a package.