Skip to content

Commit c4cbcee

Browse files
formatting tools code (Azure#18983)
1 parent 9fa8e38 commit c4cbcee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1517
-1555
lines changed

tools/azure-devtools/setup.py

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,55 @@
1313

1414

1515
CLASSIFIERS = [
16-
'Development Status :: 3 - Alpha',
17-
'Intended Audience :: Developers',
18-
'Programming Language :: Python',
19-
'Programming Language :: Python :: 2',
20-
'Programming Language :: Python :: 2.7',
21-
'Programming Language :: Python :: 3',
22-
'Programming Language :: Python :: 3.4',
23-
'Programming Language :: Python :: 3.5',
24-
'Programming Language :: Python :: 3.6',
25-
'License :: OSI Approved :: MIT License',
16+
"Development Status :: 3 - Alpha",
17+
"Intended Audience :: Developers",
18+
"Programming Language :: Python",
19+
"Programming Language :: Python :: 2",
20+
"Programming Language :: Python :: 2.7",
21+
"Programming Language :: Python :: 3",
22+
"Programming Language :: Python :: 3.4",
23+
"Programming Language :: Python :: 3.5",
24+
"Programming Language :: Python :: 3.6",
25+
"License :: OSI Approved :: MIT License",
2626
]
2727

2828

29-
DEPENDENCIES = [
30-
'ConfigArgParse>=0.12.0',
31-
'six>=1.10.0',
32-
'vcrpy==3.0.0'
33-
]
29+
DEPENDENCIES = ["ConfigArgParse>=0.12.0", "six>=1.10.0", "vcrpy==3.0.0"]
3430

35-
with io.open('README.rst', 'r', encoding='utf-8') as f:
31+
with io.open("README.rst", "r", encoding="utf-8") as f:
3632
README = f.read()
3733

3834
setup(
39-
name='azure-devtools',
35+
name="azure-devtools",
4036
version=VERSION,
41-
description='Microsoft Azure Development Tools for SDK',
37+
description="Microsoft Azure Development Tools for SDK",
4238
long_description=README,
43-
license='MIT',
44-
author='Microsoft Corporation',
45-
author_email='ptvshelp@microsoft.com',
46-
url='https://github.com/Azure/azure-python-devtools',
39+
license="MIT",
40+
author="Microsoft Corporation",
41+
author_email="ptvshelp@microsoft.com",
42+
url="https://github.com/Azure/azure-python-devtools",
4743
zip_safe=False,
4844
classifiers=CLASSIFIERS,
4945
packages=[
50-
'azure_devtools',
51-
'azure_devtools.scenario_tests',
52-
'azure_devtools.perfstress_tests',
53-
'azure_devtools.ci_tools',
46+
"azure_devtools",
47+
"azure_devtools.scenario_tests",
48+
"azure_devtools.perfstress_tests",
49+
"azure_devtools.ci_tools",
5450
],
5551
entry_points={
56-
'console_scripts': [
57-
'perfstress = azure_devtools.perfstress_tests:run_perfstress_cmd',
58-
'systemperf = azure_devtools.perfstress_tests:run_system_perfstress_tests_cmd',
52+
"console_scripts": [
53+
"perfstress = azure_devtools.perfstress_tests:run_perfstress_cmd",
54+
"systemperf = azure_devtools.perfstress_tests:run_system_perfstress_tests_cmd",
5955
],
6056
},
6157
extras_require={
62-
'ci_tools':[
63-
"PyGithub>=1.40", # Can Merge PR after 1.36, "requests" and tests after 1.40
58+
"ci_tools": [
59+
"PyGithub>=1.40", # Can Merge PR after 1.36, "requests" and tests after 1.40
6460
"GitPython",
65-
"requests>=2.0"
66-
],
67-
'systemperf':[
68-
"aiohttp>=3.0",
6961
"requests>=2.0",
70-
"tornado==6.0.3"
71-
"pycurl==7.43.0.5"
72-
"httpx==0.11.1"
73-
]
62+
],
63+
"systemperf": ["aiohttp>=3.0", "requests>=2.0", "tornado==6.0.3" "pycurl==7.43.0.5" "httpx==0.11.1"],
7464
},
75-
package_dir={'': 'src'},
65+
package_dir={"": "src"},
7666
install_requires=DEPENDENCIES,
7767
)

tools/azure-devtools/src/azure_devtools/ci_tools/bot_framework.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,38 @@ def order(function):
1717
function.bot_order = True
1818
return function
1919

20-
WebhookMetadata = namedtuple(
21-
'WebhookMetadata',
22-
['repo', 'issue', 'text', 'comment']
23-
)
20+
21+
WebhookMetadata = namedtuple("WebhookMetadata", ["repo", "issue", "text", "comment"])
22+
2423

2524
def build_from_issue_comment(gh_token, body):
26-
"""Create a WebhookMetadata from a comment added to an issue.
27-
"""
25+
"""Create a WebhookMetadata from a comment added to an issue."""
2826
if body["action"] in ["created", "edited"]:
2927
github_con = Github(gh_token)
30-
repo = github_con.get_repo(body['repository']['full_name'])
31-
issue = repo.get_issue(body['issue']['number'])
32-
text = body['comment']['body']
28+
repo = github_con.get_repo(body["repository"]["full_name"])
29+
issue = repo.get_issue(body["issue"]["number"])
30+
text = body["comment"]["body"]
3331
try:
34-
comment = issue.get_comment(body['comment']['id'])
32+
comment = issue.get_comment(body["comment"]["id"])
3533
except UnknownObjectException:
3634
# If the comment has already disapeared, skip the command
3735
return None
3836
return WebhookMetadata(repo, issue, text, comment)
3937
return None
4038

39+
4140
def build_from_issues(gh_token, body):
42-
"""Create a WebhookMetadata from an opening issue text.
43-
"""
41+
"""Create a WebhookMetadata from an opening issue text."""
4442
if body["action"] in ["opened", "edited"]:
4543
github_con = Github(gh_token)
46-
repo = github_con.get_repo(body['repository']['full_name'])
47-
issue = repo.get_issue(body['issue']['number'])
48-
text = body['issue']['body']
44+
repo = github_con.get_repo(body["repository"]["full_name"])
45+
issue = repo.get_issue(body["issue"]["number"])
46+
text = body["issue"]["body"]
4947
comment = issue # It's where we update the comment: in the issue itself
5048
return WebhookMetadata(repo, issue, text, comment)
5149
return None
5250

51+
5352
@lru_cache()
5453
def robot_name_from_env_variable():
5554
github_con = Github(os.environ["GH_TOKEN"])
@@ -63,29 +62,31 @@ def __init__(self, handler, robot_name=None, gh_token=None):
6362
self.robot_name = robot_name or robot_name_from_env_variable()
6463

6564
def _is_myself(self, body):
66-
return body['sender']['login'].lower() == self.robot_name.lower()
65+
return body["sender"]["login"].lower() == self.robot_name.lower()
6766

6867
def issue_comment(self, body):
6968
if self._is_myself(body):
70-
return {'message': 'I don\'t talk to myself, I\'m not schizo'}
69+
return {"message": "I don't talk to myself, I'm not schizo"}
7170
webhook_data = build_from_issue_comment(self.gh_token, body)
7271
return self.manage_comment(webhook_data)
7372

7473
def issues(self, body):
7574
if self._is_myself(body):
76-
return {'message': 'I don\'t talk to myself, I\'m not schizo'}
75+
return {"message": "I don't talk to myself, I'm not schizo"}
7776
webhook_data = build_from_issues(self.gh_token, body)
7877
return self.manage_comment(webhook_data)
7978

8079
def orders(self):
81-
"""Return method tagged "order" in the handler.
82-
"""
83-
return [order_cmd for order_cmd in dir(self.handler)
84-
if getattr(getattr(self.handler, order_cmd), "bot_order", False)]
80+
"""Return method tagged "order" in the handler."""
81+
return [
82+
order_cmd
83+
for order_cmd in dir(self.handler)
84+
if getattr(getattr(self.handler, order_cmd), "bot_order", False)
85+
]
8586

8687
def manage_comment(self, webhook_data):
8788
if webhook_data is None:
88-
return {'message': 'Nothing for me'}
89+
return {"message": "Nothing for me"}
8990
# Is someone talking to me:
9091
message = re.search("@{} (.*)".format(self.robot_name), webhook_data.text, re.I)
9192
response = None
@@ -97,7 +98,7 @@ def manage_comment(self, webhook_data):
9798
response = self.help_order()
9899
elif orderstr in self.orders():
99100
try: # Reaction is fun, but it's preview not prod.
100-
# Be careful, don't fail the command if we can't thumbs up...
101+
# Be careful, don't fail the command if we can't thumbs up...
101102
webhook_data.comment.create_reaction("+1")
102103
except GithubException:
103104
pass
@@ -110,8 +111,8 @@ def manage_comment(self, webhook_data):
110111
response += self.help_order()
111112
if response:
112113
webhook_data.issue.create_comment(response)
113-
return {'message': response}
114-
return {'message': 'Nothing for me or exception'}
114+
return {"message": response}
115+
return {"message": "Nothing for me or exception"}
115116

116117
def help_order(self):
117118
orders = ["This is what I can do:"]

tools/azure-devtools/src/azure_devtools/ci_tools/git_tools.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
_LOGGER = logging.getLogger(__name__)
88

9+
910
def checkout_and_create_branch(repo, name):
1011
"""Checkout branch. Create it if necessary"""
1112
local_branch = repo.branches[name] if name in repo.branches else None
@@ -20,24 +21,24 @@ def checkout_and_create_branch(repo, name):
2021
local_branch = repo.create_head(name)
2122
local_branch.checkout()
2223

24+
2325
def checkout_create_push_branch(repo, name):
24-
"""Checkout this branch. Create it if necessary, and push it to origin.
25-
"""
26+
"""Checkout this branch. Create it if necessary, and push it to origin."""
2627
try:
2728
repo.git.checkout(name)
2829
_LOGGER.info("Checkout %s success", name)
2930
except GitCommandError:
3031
_LOGGER.info("Checkout %s was impossible (branch does not exist). Creating it and push it.", name)
3132
checkout_and_create_branch(repo, name)
32-
repo.git.push('origin', name, set_upstream=True)
33+
repo.git.push("origin", name, set_upstream=True)
3334

3435

3536
def do_commit(repo, message_template, branch_name, hexsha):
3637
"Do a commit if modified/untracked files"
3738
repo.git.add(repo.working_tree_dir)
3839

3940
if not repo.git.diff(staged=True):
40-
_LOGGER.warning('No modified files in this Autorest run')
41+
_LOGGER.warning("No modified files in this Autorest run")
4142
return False
4243

4344
checkout_and_create_branch(repo, branch_name)
@@ -46,6 +47,7 @@ def do_commit(repo, message_template, branch_name, hexsha):
4647
_LOGGER.info("Commit done: %s", msg)
4748
return commit.hexsha
4849

50+
4951
def get_repo_hexsha(git_folder):
5052
"""Get the SHA1 of the current repo"""
5153
repo = Repo(str(git_folder))
@@ -57,6 +59,7 @@ def get_repo_hexsha(git_folder):
5759
_LOGGER.info("Found REST API repo SHA1: %s", hexsha)
5860
return hexsha
5961

62+
6063
def checkout_with_fetch(git_folder, refspec, repository="origin"):
6164
"""Fetch the refspec, and checkout FETCH_HEAD.
6265
Beware that you will ne in detached head mode.
@@ -67,6 +70,7 @@ def checkout_with_fetch(git_folder, refspec, repository="origin"):
6770
repo.git.checkout("FETCH_HEAD")
6871
_LOGGER.info("Fetch and checkout success for %s", refspec)
6972

73+
7074
def clone_to_path(https_authenticated_url, folder, branch_or_commit=None):
7175
"""Clone the given URL to the folder.
7276
@@ -82,23 +86,23 @@ def clone_to_path(https_authenticated_url, folder, branch_or_commit=None):
8286

8387
_LOGGER.info("Clone success")
8488

89+
8590
def get_files_in_commit(git_folder, commit_id="HEAD"):
86-
"""List of files in HEAD commit.
87-
"""
91+
"""List of files in HEAD commit."""
8892
repo = Repo(str(git_folder))
89-
output = repo.git.diff("--name-only", commit_id+"^", commit_id)
93+
output = repo.git.diff("--name-only", commit_id + "^", commit_id)
9094
return output.splitlines()
9195

96+
9297
def get_diff_file_list(git_folder):
93-
"""List of unstaged files.
94-
"""
98+
"""List of unstaged files."""
9599
repo = Repo(str(git_folder))
96100
output = repo.git.diff("--name-only")
97101
return output.splitlines()
98-
102+
103+
99104
def get_add_diff_file_list(git_folder):
100-
"""List of new files.
101-
"""
105+
"""List of new files."""
102106
repo = Repo(str(git_folder))
103107
repo.git.add("sdk")
104108
output = repo.git.diff("HEAD", "--name-only")

0 commit comments

Comments
 (0)