Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Sourcery Starbot ⭐ refactored falcorocks/piprot #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
46 changes: 21 additions & 25 deletions piprot/piprot.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ def get_version_and_release_date(requirement, version=None,

response = response.json()
except requests.HTTPError:
if version:
if verbose:
if verbose:
if version:
print('{} ({}) isn\'t available on PyPI '
'anymore!'.format(requirement, version))
else:
if verbose:
else:
Comment on lines -174 to +178
Copy link
Author

Choose a reason for hiding this comment

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

Function get_version_and_release_date refactored with the following changes:

print('{} isn\'t on PyPI. Check that the project '
'still exists!'.format(requirement))
return None, None
Expand All @@ -195,25 +194,25 @@ def get_version_and_release_date(requirement, version=None,
else:
version = response['info'].get('stable_version')

if not version:
if not version:
versions = {
v: parse_version(v) for v in response['releases'].keys()
if not parse_version(v).is_prerelease()
}

# if we still don't have a version, let's pick up a prerelease one
if not versions:
versions = {
v: parse_version(v) for v in response['releases'].keys()
if not parse_version(v).is_prerelease()
}

# if we still don't have a version, let's pick up a prerelease one
if not versions:
versions = {
v: parse_version(v) for v in response['releases'].keys()
}

if versions:
version = max(versions.items(), key=operator.itemgetter(1))[0]
release_date = (
response['releases'][str(version)][0]['upload_time']
)
else:
return None, None
if versions:
version = max(versions.items(), key=operator.itemgetter(1))[0]
release_date = (
response['releases'][str(version)][0]['upload_time']
)
else:
return None, None

return version, datetime.fromtimestamp(time.mktime(
time.strptime(release_date, '%Y-%m-%dT%H:%M:%S')
Expand Down Expand Up @@ -306,7 +305,7 @@ def main(

if latest_release_date and specified_release_date:
time_delta = (latest_release_date - specified_release_date).days
total_time_delta = total_time_delta + time_delta
total_time_delta += time_delta
Comment on lines -309 to +308
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

max_outdated_time = max(time_delta, max_outdated_time)

if verbose:
Expand Down Expand Up @@ -347,7 +346,7 @@ def main(
"days out of date which is more than the allowed"
"{} days.".format(verbatim_str, max_outdated_time, delay))
sys.exit(1)
elif delay is not None and max_outdated_time <= int(delay):
elif delay is not None:
print("{}All of your dependencies are at most {} "
"days out of date.".format(verbatim_str, delay))
else:
Expand Down Expand Up @@ -433,11 +432,8 @@ def piprot():
sys.exit('--verbatim only allowed for single requirements files')

verbose = True
if cli_args.quiet:
verbose = False
elif cli_args.verbatim:
if cli_args.quiet or cli_args.verbatim:
verbose = False

Comment on lines -436 to -440
Copy link
Author

Choose a reason for hiding this comment

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

Function piprot refactored with the following changes:

# call the main function to kick off the real work
main(req_files=cli_args.file, verbose=verbose, outdated=cli_args.outdated,
latest=cli_args.latest, verbatim=cli_args.verbatim,
Expand Down
8 changes: 4 additions & 4 deletions piprot/providers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def get_default_branch(repo):
"""returns the name of the default branch of the repo"""
url = "{}/repos/{}".format(GITHUB_API_BASE, repo)
response = requests.get(url)
if response.status_code == 200:
api_response = json.loads(response.text)
return api_response['default_branch']
else:
if response.status_code != 200:
return 'master'

api_response = json.loads(response.text)
return api_response['default_branch']
Comment on lines -45 to +49
Copy link
Author

Choose a reason for hiding this comment

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

Function get_default_branch refactored with the following changes:



def get_requirements_file_from_url(url):
"""fetches the requiremets from the url"""
Expand Down