Reformat code with black==20.8b1

This commit is contained in:
Ivan Kravets
2020-09-09 16:27:36 +03:00
parent 4f47ca5742
commit f946a0bc08
18 changed files with 262 additions and 95 deletions

View File

@ -80,7 +80,9 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
)
data = self.fetch_json_data(
"post", "/v1/login", data={"username": username, "password": password},
"post",
"/v1/login",
data={"username": username, "password": password},
)
app.set_state_item("account", data)
return data
@ -108,7 +110,9 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
self.delete_local_session()
try:
self.fetch_json_data(
"post", "/v1/logout", data={"refresh_token": refresh_token},
"post",
"/v1/logout",
data={"refresh_token": refresh_token},
)
except AccountError:
pass
@ -153,15 +157,26 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
).get("auth_token")
def forgot_password(self, username):
return self.fetch_json_data("post", "/v1/forgot", data={"username": username},)
return self.fetch_json_data(
"post",
"/v1/forgot",
data={"username": username},
)
def get_profile(self):
return self.send_auth_request("get", "/v1/profile",)
return self.send_auth_request(
"get",
"/v1/profile",
)
def update_profile(self, profile, current_password):
profile["current_password"] = current_password
self.delete_local_state("summary")
response = self.send_auth_request("put", "/v1/profile", data=profile,)
response = self.send_auth_request(
"put",
"/v1/profile",
data=profile,
)
return response
def get_account_info(self, offline=False):
@ -178,7 +193,10 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
"username": account.get("username"),
}
}
result = self.send_auth_request("get", "/v1/summary",)
result = self.send_auth_request(
"get",
"/v1/summary",
)
account["summary"] = dict(
profile=result.get("profile"),
packages=result.get("packages"),
@ -203,7 +221,10 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
return self.send_auth_request("get", "/v1/orgs/%s" % orgname)
def list_orgs(self):
return self.send_auth_request("get", "/v1/orgs",)
return self.send_auth_request(
"get",
"/v1/orgs",
)
def update_org(self, orgname, data):
return self.send_auth_request(
@ -211,19 +232,29 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
)
def destroy_org(self, orgname):
return self.send_auth_request("delete", "/v1/orgs/%s" % orgname,)
return self.send_auth_request(
"delete",
"/v1/orgs/%s" % orgname,
)
def add_org_owner(self, orgname, username):
return self.send_auth_request(
"post", "/v1/orgs/%s/owners" % orgname, data={"username": username},
"post",
"/v1/orgs/%s/owners" % orgname,
data={"username": username},
)
def list_org_owners(self, orgname):
return self.send_auth_request("get", "/v1/orgs/%s/owners" % orgname,)
return self.send_auth_request(
"get",
"/v1/orgs/%s/owners" % orgname,
)
def remove_org_owner(self, orgname, username):
return self.send_auth_request(
"delete", "/v1/orgs/%s/owners" % orgname, data={"username": username},
"delete",
"/v1/orgs/%s/owners" % orgname,
data={"username": username},
)
def create_team(self, orgname, teamname, description):
@ -235,16 +266,21 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
def destroy_team(self, orgname, teamname):
return self.send_auth_request(
"delete", "/v1/orgs/%s/teams/%s" % (orgname, teamname),
"delete",
"/v1/orgs/%s/teams/%s" % (orgname, teamname),
)
def get_team(self, orgname, teamname):
return self.send_auth_request(
"get", "/v1/orgs/%s/teams/%s" % (orgname, teamname),
"get",
"/v1/orgs/%s/teams/%s" % (orgname, teamname),
)
def list_teams(self, orgname):
return self.send_auth_request("get", "/v1/orgs/%s/teams" % orgname,)
return self.send_auth_request(
"get",
"/v1/orgs/%s/teams" % orgname,
)
def update_team(self, orgname, teamname, data):
return self.send_auth_request(

View File

@ -70,12 +70,16 @@ class RegistryClient(HTTPClient):
if version:
path += "/" + version
return self.send_auth_request(
"delete", path, params={"undo": 1 if undo else 0},
"delete",
path,
params={"undo": 1 if undo else 0},
)
def update_resource(self, urn, private):
return self.send_auth_request(
"put", "/v3/resources/%s" % urn, data={"private": int(private)},
"put",
"/v3/resources/%s" % urn,
data={"private": int(private)},
)
def grant_access_for_resource(self, urn, client, level):
@ -87,7 +91,9 @@ class RegistryClient(HTTPClient):
def revoke_access_from_resource(self, urn, client):
return self.send_auth_request(
"delete", "/v3/resources/%s/access" % urn, data={"client": client},
"delete",
"/v3/resources/%s/access" % urn,
data={"client": client},
)
def list_resources(self, owner):

View File

@ -47,27 +47,31 @@ def validate_urn(value):
@cli.command("public", short_help="Make resource public")
@click.argument(
"urn", callback=lambda _, __, value: validate_urn(value),
"urn",
callback=lambda _, __, value: validate_urn(value),
)
@click.option("--urn-type", type=click.Choice(["prn:reg:pkg"]), default="prn:reg:pkg")
def access_public(urn, urn_type):
client = RegistryClient()
client.update_resource(urn=urn, private=0)
return click.secho(
"The resource %s has been successfully updated." % urn, fg="green",
"The resource %s has been successfully updated." % urn,
fg="green",
)
@cli.command("private", short_help="Make resource private")
@click.argument(
"urn", callback=lambda _, __, value: validate_urn(value),
"urn",
callback=lambda _, __, value: validate_urn(value),
)
@click.option("--urn-type", type=click.Choice(["prn:reg:pkg"]), default="prn:reg:pkg")
def access_private(urn, urn_type):
client = RegistryClient()
client.update_resource(urn=urn, private=1)
return click.secho(
"The resource %s has been successfully updated." % urn, fg="green",
"The resource %s has been successfully updated." % urn,
fg="green",
)
@ -79,14 +83,16 @@ def access_private(urn, urn_type):
callback=lambda _, __, value: validate_client(value),
)
@click.argument(
"urn", callback=lambda _, __, value: validate_urn(value),
"urn",
callback=lambda _, __, value: validate_urn(value),
)
@click.option("--urn-type", type=click.Choice(["prn:reg:pkg"]), default="prn:reg:pkg")
def access_grant(level, client, urn, urn_type):
reg_client = RegistryClient()
reg_client.grant_access_for_resource(urn=urn, client=client, level=level)
return click.secho(
"Access for resource %s has been granted for %s" % (urn, client), fg="green",
"Access for resource %s has been granted for %s" % (urn, client),
fg="green",
)
@ -97,14 +103,16 @@ def access_grant(level, client, urn, urn_type):
callback=lambda _, __, value: validate_client(value),
)
@click.argument(
"urn", callback=lambda _, __, value: validate_urn(value),
"urn",
callback=lambda _, __, value: validate_urn(value),
)
@click.option("--urn-type", type=click.Choice(["prn:reg:pkg"]), default="prn:reg:pkg")
def access_revoke(client, urn, urn_type):
reg_client = RegistryClient()
reg_client.revoke_access_from_resource(urn=urn, client=client)
return click.secho(
"Access for resource %s has been revoked for %s" % (urn, client), fg="green",
"Access for resource %s has been revoked for %s" % (urn, client),
fg="green",
)

View File

@ -192,7 +192,10 @@ def account_destroy():
client.logout()
except AccountNotAuthorized:
pass
return click.secho("User account has been destroyed.", fg="green",)
return click.secho(
"User account has been destroyed.",
fg="green",
)
@cli.command("show", short_help="PlatformIO Account information")

View File

@ -203,7 +203,9 @@ def device_monitor(**kwargs): # pylint: disable=too-many-branches
kwargs["port"] = ports[0]["port"]
elif "platform" in project_options and "board" in project_options:
board_hwids = device_helpers.get_board_hwids(
kwargs["project_dir"], platform, project_options["board"],
kwargs["project_dir"],
platform,
project_options["board"],
)
for item in ports:
for hwid in board_hwids:

View File

@ -34,17 +34,21 @@ def validate_orgname(value):
@cli.command("create", short_help="Create a new organization")
@click.argument(
"orgname", callback=lambda _, __, value: validate_orgname(value),
"orgname",
callback=lambda _, __, value: validate_orgname(value),
)
@click.option(
"--email", callback=lambda _, __, value: validate_email(value) if value else value
)
@click.option("--displayname",)
@click.option(
"--displayname",
)
def org_create(orgname, email, displayname):
client = AccountClient()
client.create_org(orgname, email, displayname)
return click.secho(
"The organization `%s` has been successfully created." % orgname, fg="green",
"The organization `%s` has been successfully created." % orgname,
fg="green",
)
@ -121,12 +125,19 @@ def account_destroy(orgname):
abort=True,
)
client.destroy_org(orgname)
return click.secho("Organization `%s` has been destroyed." % orgname, fg="green",)
return click.secho(
"Organization `%s` has been destroyed." % orgname,
fg="green",
)
@cli.command("add", short_help="Add a new owner to organization")
@click.argument("orgname",)
@click.argument("username",)
@click.argument(
"orgname",
)
@click.argument(
"username",
)
def org_add_owner(orgname, username):
client = AccountClient()
client.add_org_owner(orgname, username)
@ -138,8 +149,12 @@ def org_add_owner(orgname, username):
@cli.command("remove", short_help="Remove an owner from organization")
@click.argument("orgname",)
@click.argument("username",)
@click.argument(
"orgname",
)
@click.argument(
"username",
)
def org_remove_owner(orgname, username):
client = AccountClient()
client.remove_org_owner(orgname, username)

View File

@ -45,7 +45,10 @@ class RemoteClientFactory(pb.PBClientFactory, protocol.ReconnectingClientFactory
return d
d = self.login(
credentials.UsernamePassword(auth_token.encode(), get_host_id().encode(),),
credentials.UsernamePassword(
auth_token.encode(),
get_host_id().encode(),
),
client=self.remote_client,
)
d.addCallback(self.remote_client.cb_client_authorization_made)

View File

@ -63,13 +63,16 @@ def cli():
value, teamname_validate=True
),
)
@click.option("--description",)
@click.option(
"--description",
)
def team_create(orgname_teamname, description):
orgname, teamname = orgname_teamname.split(":", 1)
client = AccountClient()
client.create_team(orgname, teamname, description)
return click.secho(
"The team %s has been successfully created." % teamname, fg="green",
"The team %s has been successfully created." % teamname,
fg="green",
)
@ -123,7 +126,9 @@ def team_list(orgname, json_output):
callback=lambda _, __, value: validate_teamname(value),
help="A new team name",
)
@click.option("--description",)
@click.option(
"--description",
)
def team_update(orgname_teamname, **kwargs):
orgname, teamname = orgname_teamname.split(":", 1)
client = AccountClient()
@ -142,7 +147,8 @@ def team_update(orgname_teamname, **kwargs):
new_team.update({key: value for key, value in kwargs.items() if value})
client.update_team(orgname, teamname, new_team)
return click.secho(
"The team %s has been successfully updated." % teamname, fg="green",
"The team %s has been successfully updated." % teamname,
fg="green",
)
@ -163,7 +169,8 @@ def team_destroy(orgname_teamname):
client = AccountClient()
client.destroy_team(orgname, teamname)
return click.secho(
"The team %s has been successfully destroyed." % teamname, fg="green",
"The team %s has been successfully destroyed." % teamname,
fg="green",
)
@ -173,7 +180,9 @@ def team_destroy(orgname_teamname):
metavar="ORGNAME:TEAMNAME",
callback=lambda _, __, value: validate_orgname_teamname(value),
)
@click.argument("username",)
@click.argument(
"username",
)
def team_add_member(orgname_teamname, username):
orgname, teamname = orgname_teamname.split(":", 1)
client = AccountClient()

View File

@ -124,7 +124,9 @@ class Upgrader(object):
continue
result = result[0]
pkg.metadata.spec = PackageSpec(
id=result["id"], owner=result["owner"]["username"], name=result["name"],
id=result["id"],
owner=result["owner"]["username"],
name=result["name"],
)
pkg.dump_meta()
return True

View File

@ -46,7 +46,10 @@ class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-anc
# automatically generate library manifest
with open(os.path.join(root_dir, "library.json"), "w") as fp:
json.dump(
dict(name=spec.name, version=self.generate_rand_version(),),
dict(
name=spec.name,
version=self.generate_rand_version(),
),
fp,
indent=2,
)

View File

@ -51,7 +51,9 @@ class PackagePacker(object):
r"[^\da-zA-Z\-\._\+]+",
"",
"{name}{system}-{version}.tar.gz".format(
name=name, system=("-" + system) if system else "", version=version,
name=name,
system=("-" + system) if system else "",
version=version,
),
)

View File

@ -301,7 +301,11 @@ def on_command():
def on_exception(e):
skip_conditions = [
isinstance(e, cls)
for cls in (IOError, exception.ReturnErrorCode, exception.UserSideException,)
for cls in (
IOError,
exception.ReturnErrorCode,
exception.UserSideException,
)
]
if any(skip_conditions):
return

View File

@ -100,14 +100,21 @@ def test_account_register(
def test_account_login(
clirunner, validate_cliresult, isolated_pio_core,
clirunner,
validate_cliresult,
isolated_pio_core,
):
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
result = clirunner.invoke(
cmd_account,
["login", "-u", username, "-p", password],
)
validate_cliresult(result)
def test_account_summary(
clirunner, validate_cliresult, isolated_pio_core,
clirunner,
validate_cliresult,
isolated_pio_core,
):
result = clirunner.invoke(cmd_account, ["show", "--json-output", "--offline"])
validate_cliresult(result)
@ -160,13 +167,21 @@ def test_account_summary(
def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(cmd_account, ["token", "--password", password,],)
result = clirunner.invoke(
cmd_account,
[
"token",
"--password",
password,
],
)
validate_cliresult(result)
assert "Personal Authentication Token:" in result.output
token = result.output.strip().split(": ")[-1]
result = clirunner.invoke(
cmd_account, ["token", "--password", password, "--json-output"],
cmd_account,
["token", "--password", password, "--json-output"],
)
validate_cliresult(result)
json_result = json.loads(result.output.strip())
@ -177,7 +192,14 @@ def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
clirunner.invoke(cmd_account, ["logout"])
result = clirunner.invoke(cmd_account, ["token", "--password", password,],)
result = clirunner.invoke(
cmd_account,
[
"token",
"--password",
password,
],
)
assert result.exit_code > 0
assert result.exception
assert "You are not authorized! Please log in to PIO Account" in str(
@ -187,7 +209,8 @@ def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
os.environ["PLATFORMIO_AUTH_TOKEN"] = token
result = clirunner.invoke(
cmd_account, ["token", "--password", password, "--json-output"],
cmd_account,
["token", "--password", password, "--json-output"],
)
validate_cliresult(result)
json_result = json.loads(result.output.strip())
@ -197,7 +220,10 @@ def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
os.environ.pop("PLATFORMIO_AUTH_TOKEN")
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
result = clirunner.invoke(
cmd_account,
["login", "-u", username, "-p", password],
)
validate_cliresult(result)
@ -205,7 +231,13 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
new_password = "Testpassword123"
result = clirunner.invoke(
cmd_account,
["password", "--old-password", password, "--new-password", new_password,],
[
"password",
"--old-password",
password,
"--new-password",
new_password,
],
)
validate_cliresult(result)
assert "Password successfully changed!" in result.output
@ -213,13 +245,20 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
clirunner.invoke(cmd_account, ["logout"])
result = clirunner.invoke(
cmd_account, ["login", "-u", username, "-p", new_password],
cmd_account,
["login", "-u", username, "-p", new_password],
)
validate_cliresult(result)
result = clirunner.invoke(
cmd_account,
["password", "--old-password", new_password, "--new-password", password,],
[
"password",
"--old-password",
new_password,
"--new-password",
password,
],
)
validate_cliresult(result)
@ -272,14 +311,20 @@ def test_account_update(
link = link.replace("&", "&")
session.get(link)
result = clirunner.invoke(cmd_account, ["show"],)
result = clirunner.invoke(
cmd_account,
["show"],
)
assert result.exit_code > 0
assert result.exception
assert "You are not authorized! Please log in to PIO Account" in str(
result.exception
)
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
result = clirunner.invoke(
cmd_account,
["login", "-u", username, "-p", password],
)
validate_cliresult(result)
@ -317,7 +362,8 @@ def test_account_update(
def test_org_create(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(
cmd_org, ["create", "--email", email, "--displayname", display_name, orgname],
cmd_org,
["create", "--email", email, "--displayname", display_name, orgname],
)
validate_cliresult(result)
@ -405,13 +451,21 @@ def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
def test_team_create(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(
cmd_team,
["create", "%s:%s" % (orgname, teamname), "--description", team_description,],
[
"create",
"%s:%s" % (orgname, teamname),
"--description",
team_description,
],
)
validate_cliresult(result)
def test_team_list(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
result = clirunner.invoke(
cmd_team,
["list", "%s" % orgname, "--json-output"],
)
validate_cliresult(result)
json_result = json.loads(result.output.strip())
for item in json_result:
@ -423,22 +477,30 @@ def test_team_list(clirunner, validate_cliresult, isolated_pio_core):
def test_team_add_member(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(
cmd_team, ["add", "%s:%s" % (orgname, teamname), second_username],
cmd_team,
["add", "%s:%s" % (orgname, teamname), second_username],
)
validate_cliresult(result)
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
result = clirunner.invoke(
cmd_team,
["list", "%s" % orgname, "--json-output"],
)
validate_cliresult(result)
assert second_username in result.output
def test_team_remove(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(
cmd_team, ["remove", "%s:%s" % (orgname, teamname), second_username],
cmd_team,
["remove", "%s:%s" % (orgname, teamname), second_username],
)
validate_cliresult(result)
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
result = clirunner.invoke(
cmd_team,
["list", "%s" % orgname, "--json-output"],
)
validate_cliresult(result)
assert second_username not in result.output
@ -459,7 +521,10 @@ def test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_
)
validate_cliresult(result)
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
result = clirunner.invoke(
cmd_team,
["list", "%s" % orgname, "--json-output"],
)
validate_cliresult(result)
json_result = json.loads(result.output.strip())
for item in json_result:

View File

@ -446,7 +446,10 @@ int main() {
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
validate_cliresult(result)
defects = sum(count_defects(result.output))
assert defects > 0, "Failed %s with %s" % (framework, tool,)
assert defects > 0, "Failed %s with %s" % (
framework,
tool,
)
def test_check_skip_includes_from_packages(clirunner, validate_cliresult, tmpdir):

View File

@ -339,14 +339,17 @@ def test_lib_stats(clirunner, validate_cliresult):
result = clirunner.invoke(cmd_lib, ["stats", "--json-output"])
validate_cliresult(result)
assert set(
[
"dlweek",
"added",
"updated",
"topkeywords",
"dlmonth",
"dlday",
"lastkeywords",
]
) == set(json.loads(result.output).keys())
assert (
set(
[
"dlweek",
"added",
"updated",
"topkeywords",
"dlmonth",
"dlday",
"lastkeywords",
]
)
== set(json.loads(result.output).keys())
)

View File

@ -60,7 +60,8 @@ def test_install_unknown_from_registry(clirunner):
def test_install_core_3_dev_platform(clirunner, validate_cliresult, isolated_pio_core):
result = clirunner.invoke(
cli_platform.platform_install, ["atmelavr@1.2.0", "--skip-default-package"],
cli_platform.platform_install,
["atmelavr@1.2.0", "--skip-default-package"],
)
assert result.exit_code == 0

View File

@ -77,7 +77,8 @@ void loop() {}
)
result = clirunner.invoke(
cmd_test, ["-d", str(project_dir), "--without-testing", "--without-uploading"],
cmd_test,
["-d", str(project_dir), "--without-testing", "--without-uploading"],
)
validate_cliresult(result)
@ -127,7 +128,8 @@ int main() {
)
native_result = clirunner.invoke(
cmd_test, ["-d", str(project_dir), "-e", "native"],
cmd_test,
["-d", str(project_dir), "-e", "native"],
)
test_dir.join("unittest_transport.h").write(

View File

@ -239,19 +239,19 @@ def test_install_lib_depndencies(isolated_pio_core, tmpdir_factory):
root_dir.join("library.json").write(
"""
{
"name": "lib-with-deps",
"version": "2.0.0",
"dependencies": [
{
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "^6.16.1"
},
{
"name": "external-repo",
"version": "https://github.com/milesburton/Arduino-Temperature-Control-Library.git#4a0ccc1"
}
]
"name": "lib-with-deps",
"version": "2.0.0",
"dependencies": [
{
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "^6.16.1"
},
{
"name": "external-repo",
"version": "https://github.com/milesburton/Arduino-Temperature-Control-Library.git#4a0ccc1"
}
]
}
"""
)