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

Path issues prevent importlib.metadata from finding Distutils packages #27

Open
laurenrad opened this issue Jan 15, 2024 · 1 comment
Open

Comments

@laurenrad
Copy link

While trying to get flake8 to work on RISC OS, I ran across a cryptic error (not repeated here, this is due to faulty error handling on the part of flake8), and after tracking back through it, I found the following (where pyflakes is most certainly installed firmly in my path and importable in Python):

Python 3.8.8+ (riscos-1, Feb 22 2021, 21:48:54) 
[GCC 4.7.4] on riscos
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.metadata
>>> m = importlib.metadata.distribution("pyflakes")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "SDFS::RISCOSpi.$.Apps.Development.!Python3.python38.lib.importlib.metadata", line 504, in distribution
    return Distribution.from_name(distribution_name)
  File "SDFS::RISCOSpi.$.Apps.Development.!Python3.python38.lib.importlib.metadata", line 177, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: pyflakes
>>> 

Here, importlib.metadata is failing to find distutils packages through MetadataPathFinder; while most instances in this file have been fixed, there are a couple places throughout that still have hardcoded file extensions beginning with '.' which are causing paths not to resolve, which should be using os.extsep instead. These are:

  • Line 422: and base.endswith('.egg'))
  • Line 441: suffixes = '.dist-info', '.egg-info'
  • Line 453: self.versionless_egg_name = self.normalized + '.egg'

Additionally, there is a typo on line 241 where "entry_point" should be "entry_points":
self.read_text(f'entry_point{os.extsep}txt'))

After correcting these, I was able to run flake8 after some configuration.

I've attached a diff patch for this.

metadata_patch.diff.txt

@laurenrad
Copy link
Author

laurenrad commented Jan 16, 2024

I've realized that despite what I thought I might be using an outdated build. I'll double check this as soon as I have time but close if this is already corrected.

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

No branches or pull requests

1 participant