Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 5, 2021
1 parent 3f0469b commit c80e5cf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 44 deletions.
15 changes: 8 additions & 7 deletions examples/fetch-urls
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from more_executors.retry import RetryPolicy, ExceptionRetryPolicy

class LoggingRetryPolicy(RetryPolicy):
"""A RetryPolicy which prints a message before each retry."""

def __init__(self):
# Inherit the behavior from the default policy
self.policy = ExceptionRetryPolicy()
Expand Down Expand Up @@ -38,14 +39,14 @@ def fetch_urls(urls):
# - run get_content on each response
# - retry up to several minutes on any errors
# - custom retry policy used to log before each retry
executor = Executors.\
thread_pool(max_workers=4).\
with_map(get_content).\
with_retry(LoggingRetryPolicy())
executor = (
Executors.thread_pool(max_workers=4)
.with_map(get_content)
.with_retry(LoggingRetryPolicy())
)

# Submit requests for each given URL
futures = [executor.submit(requests.get, url)
for url in urls]
futures = [executor.submit(requests.get, url) for url in urls]

# Iterate through completed futures.
# The status code has already been checked on each response.
Expand All @@ -57,5 +58,5 @@ def fetch_urls(urls):
print("")


if __name__ == '__main__':
if __name__ == "__main__":
fetch_urls(sys.argv[1:])
42 changes: 23 additions & 19 deletions scripts/make-pr
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import yaml

import github3

CONFIG_PATH = '~/.config/hub'
OWNER = 'rohanpm'
REPO = 'more-executors'
CONFIG_PATH = "~/.config/hub"
OWNER = "rohanpm"
REPO = "more-executors"


def github_session():
with open(os.path.expanduser(CONFIG_PATH)) as f:
hub_config = yaml.load(f)

creds = hub_config.get('github.com', [])
creds = hub_config.get("github.com", [])
if not creds:
raise RuntimeError("Login with 'hub' command first")
if len(creds) != 1:
raise RuntimeError("Unexpected content in %s" % CONFIG_PATH)

token = creds[0].get('oauth_token')
token = creds[0].get("oauth_token")
if not token:
raise RuntimeError("Missing token in %s" % CONFIG_PATH)

Expand All @@ -34,34 +34,38 @@ def github_session():

def run(raw_args):
parser = ArgumentParser()
parser.add_argument('name', help='name for branch')
parser.add_argument('--remove-branch', action='store_true',
help='remove branch if it already exists')
parser.add_argument('--skip-rebase', action='store_true',
help='do not rebase on master before push')
parser.add_argument('-m', help='pull-request message')
parser.add_argument("name", help="name for branch")
parser.add_argument(
"--remove-branch",
action="store_true",
help="remove branch if it already exists",
)
parser.add_argument(
"--skip-rebase", action="store_true", help="do not rebase on master before push"
)
parser.add_argument("-m", help="pull-request message")
args = parser.parse_args(raw_args)

if args.remove_branch:
try:
check_call(['git', 'branch', '-D', args.name])
check_call(["git", "branch", "-D", args.name])
except CalledProcessError:
pass

check_call(['git', 'checkout', '-b', args.name])
check_call(["git", "checkout", "-b", args.name])

if not args.skip_rebase:
check_call(['git', 'fetch', 'origin'])
check_call(['git', 'rebase', '-i', 'origin/master'])
check_call(["git", "fetch", "origin"])
check_call(["git", "rebase", "-i", "origin/master"])

check_call(['git', 'push', '-f', '--set-upstream', 'origin', args.name])
check_call(["git", "push", "-f", "--set-upstream", "origin", args.name])

pr_cmd = ['hub', 'pull-request']
pr_cmd = ["hub", "pull-request"]
if args.m:
pr_cmd.extend(['-m', args.m])
pr_cmd.extend(["-m", args.m])

check_call(pr_cmd)


if __name__ == '__main__':
if __name__ == "__main__":
run(sys.argv[1:])
37 changes: 20 additions & 17 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,40 @@ from subprocess import check_output, check_call


def bump(version):
components = version.split('.')
components = version.split(".")
components[1] = str(int(components[1]) + 1)
components[2] = '0'
return '.'.join(components)
components[2] = "0"
return ".".join(components)


def run():
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

current_version = check_output(
[sys.executable, 'setup.py', '--version'],
encoding='utf-8'
[sys.executable, "setup.py", "--version"], encoding="utf-8"
).strip()
new_version = bump(current_version)

check_call([
'sed',
'-r',
'-e', 's|%s|%s|g' % (re.escape(current_version), new_version),
'-i', 'setup.py',
])
check_call(
[
"sed",
"-r",
"-e",
"s|%s|%s|g" % (re.escape(current_version), new_version),
"-i",
"setup.py",
]
)

check_call(['git', 'add', 'setup.py'])
check_call(["git", "add", "setup.py"])

tag = 'v' + new_version
msg = 'Release ' + tag
check_call(['git', 'commit', '-m', msg])
check_call(['git', 'tag', '-a', '-m', msg, tag])
tag = "v" + new_version
msg = "Release " + tag
check_call(["git", "commit", "-m", msg])
check_call(["git", "tag", "-a", "-m", msg, tag])

print("Check `git log', then `git push --follow-tags'")


if __name__ == '__main__':
if __name__ == "__main__":
run()
2 changes: 1 addition & 1 deletion tests/test_executor_threadleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fn():
]


@fixture(params=["sync", "thread_pool",] + EXECUTORS_WITH_WORKER_THREAD)
@fixture(params=["sync", "thread_pool"] + EXECUTORS_WITH_WORKER_THREAD)
def executor_ctor(request):
return request.getfixturevalue("ctor_" + request.param)

Expand Down

0 comments on commit c80e5cf

Please sign in to comment.