diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index ff6fc08..7f6ba9d 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -8,17 +8,14 @@ jobs: - uses: actions/setup-python@v2 - run: pip install --upgrade pip wheel - run: pip install bandit black codespell flake8 flake8-bugbear - flake8-comprehensions isort mypy pytest pyupgrade safety + flake8-comprehensions isort mypy pyupgrade safety - run: bandit --recursive --skip B101,B404,B603 . - - run: black --check . || true + - run: black --diff . - run: codespell --ignore-words-list="commitish" - run: flake8 . --count --ignore=C408,E203,F841,W503 --max-complexity=10 --max-line-length=143 --show-source --statistics - - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt || pip install --editable . || true - - run: mkdir --parents --verbose .mypy_cache + - run: isort --check-only --profile black . + - run: pip install --editable . - run: mypy --ignore-missing-imports --install-types --non-interactive . - - run: pytest . || true - - run: pytest --doctest-modules . || true - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true - run: safety check diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index f393770..1233cbd 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -1,17 +1,16 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import click import collections import enum import os -import subprocess -import webbrowser import re +import subprocess import sys +import webbrowser + +import click import requests import toml - from gidgethub import sansio from . import __version__ @@ -167,7 +166,7 @@ def get_pr_url(self, base_branch, head_branch): return f"https://github.com/{self.config['team']}/{self.config['repo']}/compare/{base_branch}...{self.username}:{head_branch}?expand=1" def fetch_upstream(self): - """ git fetch """ + """git fetch """ set_state(WORKFLOW_STATES.FETCHING_UPSTREAM) cmd = ["git", "fetch", self.upstream, "--no-tags"] self.run_cmd(cmd) @@ -182,7 +181,7 @@ def run_cmd(self, cmd): return output.decode("utf-8") def checkout_branch(self, branch_name): - """ git checkout -b """ + """git checkout -b """ cmd = [ "git", "checkout", @@ -219,7 +218,7 @@ def get_commit_message(self, commit_sha): return message def checkout_default_branch(self): - """ git checkout default branch """ + """git checkout default branch""" set_state(WORKFLOW_STATES.CHECKING_OUT_DEFAULT_BRANCH) cmd = "git", "checkout", self.config["default_branch"] @@ -236,7 +235,7 @@ def status(self): return self.run_cmd(cmd) def cherry_pick(self): - """ git cherry-pick -x """ + """git cherry-pick -x """ cmd = ["git", "cherry-pick", "-x", self.commit_sha1] try: click.echo(self.run_cmd(cmd)) @@ -261,7 +260,7 @@ def get_exit_message(self, branch): """ def amend_commit_message(self, cherry_pick_branch): - """ prefix the commit message with (X.Y) """ + """prefix the commit message with (X.Y)""" commit_prefix = "" if self.prefix_commit: @@ -283,7 +282,7 @@ def amend_commit_message(self, cherry_pick_branch): return updated_commit_message def push_to_remote(self, base_branch, head_branch, commit_message=""): - """ git push """ + """git push """ set_state(WORKFLOW_STATES.PUSHING_TO_REMOTE) cmd = ["git", "push"] @@ -607,7 +606,16 @@ class state: @click.argument("branches", nargs=-1) @click.pass_context def cherry_pick_cli( - ctx, dry_run, pr_remote, abort, status, push, auto_pr, config_path, commit_sha1, branches + ctx, + dry_run, + pr_remote, + abort, + status, + push, + auto_pr, + config_path, + commit_sha1, + branches, ): """cherry-pick COMMIT_SHA1 into target BRANCHES.""" diff --git a/cherry_picker/test.py b/cherry_picker/test_cherry_picker.py similarity index 99% rename from cherry_picker/test.py rename to cherry_picker/test_cherry_picker.py index c01ba26..a2919b0 100644 --- a/cherry_picker/test.py +++ b/cherry_picker/test_cherry_picker.py @@ -4,30 +4,30 @@ from collections import ChainMap from unittest import mock -import pytest import click +import pytest from .cherry_picker import ( - get_base_branch, - get_current_branch, - get_full_sha_from_short, - get_author_info_from_short_sha, + DEFAULT_CONFIG, + WORKFLOW_STATES, CherryPicker, - InvalidRepoException, CherryPickException, - normalize_commit_message, - DEFAULT_CONFIG, - get_sha1_from, + InvalidRepoException, find_config, - load_config, - validate_sha, from_git_rev_read, - reset_state, - set_state, + get_author_info_from_short_sha, + get_base_branch, + get_current_branch, + get_full_sha_from_short, + get_sha1_from, get_state, + load_config, load_val_from_git_cfg, + normalize_commit_message, + reset_state, reset_stored_config_ref, - WORKFLOW_STATES, + set_state, + validate_sha, ) @@ -945,4 +945,4 @@ def test_abort_cherry_pick_success( def test_cli_invoked(): - subprocess.check_call('cherry_picker --help'.split()) + subprocess.check_call("cherry_picker --help".split()) diff --git a/pytest.ini b/pytest.ini index 137647b..bdb4f56 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,4 +5,3 @@ filterwarnings = error junit_duration_report = call junit_suite_name = cherry_picker_test_suite -testpaths = cherry_picker/test.py