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

Consider support for file like objects instead of filenames #51

Closed
jayfk opened this issue Jan 23, 2017 · 1 comment
Closed

Consider support for file like objects instead of filenames #51

jayfk opened this issue Jan 23, 2017 · 1 comment

Comments

@jayfk
Copy link

jayfk commented Jan 23, 2017

The API is currently designed in a way that it tightly coupled with the file system. The parse function for example expects the Pipfile to be a filename: https://github.com/pypa/pipfile/blob/master/pipfile/api.py#L70

It'd great if we could find a way to decouple the API from the filesystem, at least in parts. This won't work for functions like walk_up, but when I look at parse it'd relatively easy to just pass in a file like object:

def parse(self, file_handle):
    # Open the Pipfile.
    content = f.read()
    ...

Same goes for the find function. Instead of calling os.getcwd explicitly in find, call it in walk_up:

 @staticmethod
def find(max_depth=3):
     """Returns the path of a Pipfile in parent directories."""
     i = 0
     for c, d, f in walk_up():
     ...
def walk_up(bottom):
    """mimic os.walk, but walk 'up' instead of down the directory tree.
    From: https://gist.github.com/zdavkeos/1098474
    """

    bottom = os.path.realpath(os.getcwd())
    ...

This would help external tools a lot to work with the API. There are probably still a lot of design decisions to make here, but if there's any interest in supporting external tools I'd be happy to submit a PR that addresses some of the points I mentioned earlier.

@kennethreitz
Copy link
Contributor

the codebaes is currently being re-written

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

2 participants