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

Optimization in find Pipfile and Pep8 fixes #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pipfile/api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import sys
import toml

import codecs
import json
import codecs
import hashlib
import platform
import sys
import os


def format_full_version(info):
Expand All @@ -16,7 +15,6 @@ def format_full_version(info):
return version



class PipfileParser(object):
def __init__(self, filename='Pipfile'):
self.filename = filename
Expand All @@ -38,7 +36,8 @@ def parse(self):

# Load the default configuration.
default_config = {
u'source': [{u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, 'name': "pypi"}],
u'source': [{u'url': u'https://pypi.python.org/simple',
u'verify_ssl': True, 'name': "pypi"}],
u'packages': {},
u'requires': {},
u'dev-packages': {}
Expand Down Expand Up @@ -77,11 +76,13 @@ def __init__(self, filename):
def find(max_depth=3):
"""Returns the path of a Pipfile in parent directories."""
i = 0
for c, d, f in os.walk(os.getcwd(), topdown=False):
exclude_dirs = ('.', '__')
for dirpath, dirs, files in os.walk(os.getcwd(), topdown=True):
dirs[:] = [d for d in dirs if not d.startswith(exclude_dirs)]
if i > max_depth:
raise RuntimeError('No Pipfile found!')
elif 'Pipfile' in f:
return os.path.join(c, 'Pipfile')
elif 'Pipfile' in files:
return os.path.join(dirpath, 'Pipfile')
i += 1

@classmethod
Expand Down Expand Up @@ -116,7 +117,8 @@ def assert_requirements(self):

# Support for 508's implementation_version.
if hasattr(sys, 'implementation'):
implementation_version = format_full_version(sys.implementation.version)
implementation_version = format_full_version(
sys.implementation.version)
else:
implementation_version = "0"

Expand Down Expand Up @@ -147,7 +149,8 @@ def assert_requirements(self):
try:
assert lookup[marker] == specifier
except AssertionError:
raise AssertionError('Specifier {!r} does not match {!r}.'.format(marker, specifier))
raise AssertionError('Specifier {!r} does not match '
'{!r}.'.format(marker, specifier))


def load(pipfile_path=None):
Expand Down