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

Sourcery Starbot ⭐ refactored michaeljoseph/changes #282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/changes main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -41 to +46
labels = set(
[
label_name
for pull_request in pull_requests
for label_name in pull_request.label_names
]
)
labels = {
label_name
for pull_request in pull_requests
for label_name in pull_request.label_names
}

Copy link
Author

Choose a reason for hiding this comment

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

Function release_from_pull_requests refactored with the following changes:

with open('%s/__init__.py' % module_name) as input_file:
with open(f'{module_name}/__init__.py') as input_file:
Copy link
Author

Choose a reason for hiding this comment

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

Function extract_attribute refactored with the following changes:

init_file = '%s/__init__.py' % module_name
init_file = f'{module_name}/__init__.py'
Copy link
Author

Choose a reason for hiding this comment

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

Function replace_attribute refactored with the following changes:

Comment on lines -41 to +44
init_file = '%s/__init__.py' % module_name
init_file = f'{module_name}/__init__.py'
return any(
[attribute_name in init_line for init_line in open(init_file).readlines()]
attribute_name in init_line
for init_line in open(init_file).readlines()
Copy link
Author

Choose a reason for hiding this comment

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

Function has_attribute refactored with the following changes:

Comment on lines -36 to +39
# http://stackoverflow.com/a/468378/5549
sha1_re = re.match(r'^[0-9a-f]{5,40}\b', line)
if sha1_re:
if sha1_re := re.match(r'^[0-9a-f]{5,40}\b', line):
sha1 = sha1_re.group()

new_line = line.replace(sha1, '[%s](%s/commit/%s)' % (sha1, repo_url, sha1))
new_line = line.replace(sha1, f'[{sha1}]({repo_url}/commit/{sha1})')
Copy link
Author

Choose a reason for hiding this comment

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

Function replace_sha_with_commit_link refactored with the following changes:

This removes the following comments ( why? ):

# http://stackoverflow.com/a/468378/5549

Comment on lines -73 to +74
install_cmd = '%s/bin/pip install %s' % (tmp_dir, context.module_name)
install_cmd = f'{tmp_dir}/bin/pip install {context.module_name}'

package_index = 'pypi'
if context.pypi:
install_cmd += '-i %s' % context.pypi
install_cmd += f'-i {context.pypi}'
Copy link
Author

Choose a reason for hiding this comment

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

Function install_from_pypi refactored with the following changes:

log.info('%s? %s' % (probe_name, probe_result))
log.info(f'{probe_name}? {probe_result}')
Copy link
Author

Choose a reason for hiding this comment

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

Function report_and_raise refactored with the following changes:

log.info('%s does not exist' % command)
log.info(f'{command} does not exist')
Copy link
Author

Choose a reason for hiding this comment

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

Function has_binary refactored with the following changes:

return any([has_binary(tool) for tool in TOOLS])
return any(has_binary(tool) for tool in TOOLS)
Copy link
Author

Choose a reason for hiding this comment

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

Function has_tools refactored with the following changes:

return any([has_binary(runner) for runner in TEST_RUNNERS])
return any(has_binary(runner) for runner in TEST_RUNNERS)
Copy link
Author

Choose a reason for hiding this comment

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

Function has_test_runner refactored with the following changes:

any([exists('README{}'.format(ext)) for ext in README_EXTENSIONS]),
any(exists(f'README{ext}') for ext in README_EXTENSIONS),
Copy link
Author

Choose a reason for hiding this comment

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

Function has_readme refactored with the following changes:

init_path = '{}/__init__.py'.format(python_module)
init_path = f'{python_module}/__init__.py'
Copy link
Author

Choose a reason for hiding this comment

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

Function has_metadata refactored with the following changes:

Comment on lines -24 to +26
('{}'.format(i), value) for i, value in enumerate(alternatives, 1)
(f'{i}', value) for i, value in enumerate(alternatives, 1)
)

Copy link
Author

Choose a reason for hiding this comment

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

Function choose_labels refactored with the following changes:

return {'Authorization': 'token {}'.format(self.auth_token)}
return {'Authorization': f'token {self.auth_token}'}
Copy link
Author

Choose a reason for hiding this comment

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

Function GitHub.headers refactored with the following changes:

log.info('Dry run of %s, skipping' % command)
log.info(f'Dry run of {command}, skipping')
Copy link
Author

Choose a reason for hiding this comment

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

Function dry_run refactored with the following changes:

Comment on lines -11 to +13
info('Status [{}/{}]'.format(repository.owner, repository.repo))
info(f'Status [{repository.owner}/{repository.repo}]')

info('Repository: ' + highlight('{}/{}'.format(repository.owner, repository.repo)))
info(f"Repository: {highlight(f'{repository.owner}/{repository.repo}')}")
Copy link
Author

Choose a reason for hiding this comment

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

Function status refactored with the following changes:

) + ((' ' + self.name) if self.name else '')
) + (f' {self.name}' if self.name else '')
Copy link
Author

Choose a reason for hiding this comment

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

Function Release.title refactored with the following changes:

) + (('-' + self.name) if self.name else '')
) + (f'-{self.name}' if self.name else '')
Copy link
Author

Choose a reason for hiding this comment

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

Function Release.release_note_filename refactored with the following changes:

while not version_file_path_answer == input_terminator:
while version_file_path_answer != input_terminator:
Copy link
Author

Choose a reason for hiding this comment

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

Function BumpVersion.load refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -135 to +140
'[bumpversion:file:{}]'.format(file_name)
f'[bumpversion:file:{file_name}]'
for file_name in self.version_files_to_replace
]
)


Copy link
Author

Choose a reason for hiding this comment

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

Function BumpVersion.write_to_file refactored with the following changes:

return git('config --get remote.{}.url'.format(self.REMOTE_NAME))
return git(f'config --get remote.{self.REMOTE_NAME}.url')
Copy link
Author

Choose a reason for hiding this comment

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

Function GitRepository.remote_url refactored with the following changes:

Comment on lines -94 to +96
revision_range = ' {}..HEAD'.format(version) if version else ''
revision_range = f' {version}..HEAD' if version else ''

merge_commits = git(
'log --oneline --merges --no-color{}'.format(revision_range)
).split('\n')
return merge_commits
return git(f'log --oneline --merges --no-color{revision_range}').split('\n')
Copy link
Author

Choose a reason for hiding this comment

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

Function GitRepository.merges_since refactored with the following changes:

Comment on lines -119 to +116
return git('add {}'.format(' '.join(files_to_add)))
return git(f"add {' '.join(files_to_add)}")
Copy link
Author

Choose a reason for hiding this comment

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

Function GitRepository.add refactored with the following changes:

Comment on lines -124 to +121
return git_command['commit', '--message="{}"'.format(message)]()
return git_command['commit', f'--message="{message}"']()
Copy link
Author

Choose a reason for hiding this comment

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

Function GitRepository.commit refactored with the following changes:

Comment on lines -128 to +125
return git('checkout -- {}'.format(' '.join(file_paths)))
return git(f"checkout -- {' '.join(file_paths)}")
Copy link
Author

Choose a reason for hiding this comment

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

Function GitRepository.discard refactored with the following changes:

assert result.output == 'changes {}\n'.format(changes.__version__)
assert result.output == f'changes {changes.__version__}\n'
Copy link
Author

Choose a reason for hiding this comment

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

Function test_version refactored with the following changes:

Comment on lines -74 to +76
'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat())
f'docs/releases/0.0.2-{date.today().isoformat()}-Icarus.md'
)

Copy link
Author

Choose a reason for hiding this comment

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

Function test_publish refactored with the following changes:

release_notes_path = Path(
'docs/releases/0.0.2-{}.md'.format(date.today().isoformat())
)
release_notes_path = Path(f'docs/releases/0.0.2-{date.today().isoformat()}.md')
Copy link
Author

Choose a reason for hiding this comment

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

Function test_stage_draft refactored with the following changes:

Comment on lines -101 to +102
'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat())
f'docs/releases/0.0.2-{date.today().isoformat()}-Icarus.md'
)

Copy link
Author

Choose a reason for hiding this comment

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

Function test_stage refactored with the following changes:

Comment on lines -166 to +169
'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat())
f'docs/releases/0.0.2-{date.today().isoformat()}-Icarus.md'
)

Copy link
Author

Choose a reason for hiding this comment

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

Function test_stage_discard refactored with the following changes:

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.

None yet

1 participant