Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem that transitive been reported as missing #989

Closed
wants to merge 1 commit into from

Conversation

Willa1228
Copy link

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Hello, I made a small change to fix the issue where some packages might not have the same name when import, which caused them to be incorrectly reported as missing instead of transitive, as described in in #827.

To ensure the correct package name is retrieved in module.py, I added an additional approach to check if the package is in the development environment:

`

def _get_package_name_from_metadata(self) -> str | None:
    """
    Most packages simply have a field called "Name" in their metadata. This method extracts that field.
    """
    try:
        name: str = metadata(self.name)["Name"]
    except PackageNotFoundError:
        name = self.is_package_installed(self.name)
        if name:
            return name
        return None
    else:
        return name

def is_package_installed(self, package_name: str):
    if importlib.util.find_spec(package_name):
        return package_name
    return None

`
This ensures that the package name can always be retrieved if it is in the environment, regardless of whether the package name and import name match. I also updated the test in test_module so that the package name for bs4 can now be detected.

I'm not sure if this adheres to your program framework or design logic, but I hope it helps. Thanks!

Description of changes

@Willa1228 Willa1228 closed this Dec 25, 2024
@Willa1228
Copy link
Author

I added the test dependency on the wrong place, I'll remake a pull request. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant