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

bpo-32248: Implement importlib.abc.ResourceReader #4892

Merged
merged 8 commits into from
Dec 16, 2017

Conversation

brettcannon
Copy link
Member

@brettcannon brettcannon commented Dec 15, 2017

Copy link
Member

@warsaw warsaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to try to lift as much of the text from the standalone package's description of the ABC

.. class:: ResourceReader

An :term:`abstract base class` for :term:`loaders <loader>`
representing a :term:`package` to provide the ability to read
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit awkwardly for me. What about "An abstract base class for package loaders which provide the ability to read resources"?


From the perspective of this class, a *resource* is a binary
artifact that is shipped within the package that this loader
represents. Typically this is something like a data file that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's another awkward turn of a similar phrase. "package that this loader represents" seems weird to me ;)

representing a :term:`package` to provide the ability to read
*resources*.

From the perspective of this class, a *resource* is a binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it say "from the perspective of this ABC"?

If the resource does not concretely exist on the file system,
raise :exc:`FileNotFoundError`.

.. abstractmethod:: is_resource(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the standalone package I called this name so that it doesn't necessarily imply a path (which could include slashes).

.. abstractmethod:: contents()

Returns an :term:`iterator` of strings over the contents of
the package. Due note that it is not required that all names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Due/Do/


class ResourceReaderDefaultsTests(ABCTestHarness):

SPLIT = make_abc_subclasses(ResourceReader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is SPLIT required by ABCTestHarness? It seems an odd choice of terms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and I didn't name it.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@brettcannon
Copy link
Member Author

I didn't expect the Spanish Inquisition!

@bedevere-bot
Copy link

Nobody expects the Spanish Inquisition!

@warsaw: please review the changes made to this pull request.

@warsaw
Copy link
Member

warsaw commented Dec 15, 2017

LGTM, thanks @brettcannon !

If you close the bug, can you open a new one for the implementation? I'm also cool with keeping the original bug open for the ABC implementation branch. 'Sup to you!

@brettcannon
Copy link
Member Author

I say just keep the issue open. We can just expand on the NEWS entry as necessary.

@brettcannon brettcannon merged commit 4ac5150 into python:master Dec 16, 2017
@brettcannon brettcannon deleted the importlib_resources_abc branch December 16, 2017 00:29
versus on the file system.

For any of methods of this class, a *resource* argument is
expected to be a :term:`file-like object` which represents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So open_resource takes a file object and returns a file object? I may be misunderstanding here...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that term should say that a resource is a path-like object. I'll fix that in my follow up branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the file system path to the *resource*.

If the resource does not concretely exist on the file system,
raise :exc:`FileNotFoundError`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... is the same error returned when the given resource doesn't exist, or when the given resource exists but underlying storage is not a regular directory (e.g. a zip file)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In either case, importlib.resources will know what to do with that (e.g. extract it to a temporary file in the case where it exists in the loader's view of the world, but not on the physical file system).

.. abstractmethod:: is_resource(name)

Returns ``True`` if the named *name* is considered a resource.
:exc:`FileNotFoundError` is raised if *name* does not exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And False is returned if...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...it isn't. :) Do you think we need to clarify that?

Copy link
Contributor

@AraHaan AraHaan Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it was me I would actually have the method return False instead of an exception if name does not exist. That is how I do it in my own python code. At least I would think getters and setters and checks like this that returns bools should have an no throw garentee.

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.

6 participants