c-jo / cpython

RISC OS port of the Python programming language
https://www.python.org/
Other
7 stars 3 forks source link

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

Open laurenrad opened 10 months ago

laurenrad commented 10 months ago

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:

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 commented 10 months ago

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.