Skip to content

PackagePath cannot be created on your platform (Windows) #51

Closed

Description

@jaraco

In GitLab by @jaraco on Feb 24, 2019, 15:48

In the code, the PackagePath derives from PosixPath, which is not allowed to be constructed on Windows. As a result, the tests fail on Windows.

Activity

  1. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 24, 2019, 15:50

    When I selected pathlib.PosixPath, I had assumed that like the posixpath module, it was cross-platform, providing a uniform interface across platforms. I can't recall if I did this to support zipfiles or just as an arbitrary choice. Let's experiment to see if using pathlib.Path as the base class for PackagePath is sufficient to get tests to pass on Windows.

  2. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 24, 2019, 16:48

    I tried making the switch

    diff --git a/importlib_metadata/api.py b/importlib_metadata/api.py
    index cddc03f..1eed683 100644
    --- a/importlib_metadata/api.py
    +++ b/importlib_metadata/api.py
    @@ -97,7 +97,7 @@ class EntryPoint(collections.namedtuple('EntryPointBase', 'name value group')):
             return iter((self.name, self))
     
     
    -class PackagePath(pathlib.PosixPath):
    +class PackagePath(pathlib.Path):
         """A reference to a path in a package"""
     
         def read_text(self, encoding='utf-8'):
    

    But even on Unix, the tests fail.

    ======================================================================
    ERROR: test_file_hash_repr (importlib_metadata.tests.test_api.APITests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/jaraco/code/public/importlib_metadata/importlib_metadata/tests/test_api.py", line 92, in test_file_hash_repr
        p for p in importlib_metadata.files('wheel')
      File "/Users/jaraco/code/public/importlib_metadata/importlib_metadata/tests/test_api.py", line 92, in <listcomp>
        p for p in importlib_metadata.files('wheel')
      File "/Users/jaraco/code/public/importlib_metadata/importlib_metadata/api.py", line 213, in make_file
        result = PackagePath(name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 994, in __new__
        self = cls._from_parts(args, init=False)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 649, in _from_parts
        drv, root, parts = self._parse_args(args)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 642, in _parse_args
        return cls._flavour.parse_parts(parts)
    AttributeError: type object 'PackagePath' has no attribute '_flavour'
    
  3. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 24, 2019, 20:22

    It seems that even this simple Python fails similarly:

    import pathlib
    
    
    class MyPath(pathlib.Path):
    	def foo(self):
    		return 'yep'
    
    
    p = MyPath('.')
    
  4. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 24, 2019, 20:27

    Okay, it's not possible to subclass Path or PurePath.

  5. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 25, 2019, 03:19

    mentioned in commit a15b5db

  6. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 25, 2019, 03:19

    mentioned in merge request !49

  7. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 25, 2019, 03:20

    closed via commit a15b5db

  8. jaraco commented on Oct 22, 2020

    @jaraco
    MemberAuthor

    In GitLab by @jaraco on Feb 25, 2019, 03:20

    closed via merge request !49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions