Skip to content

Commit

Permalink
style: unset ruff line length; default is 88.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Sep 13, 2024
1 parent 4c306e2 commit aa540ba
Show file tree
Hide file tree
Showing 27 changed files with 82 additions and 247 deletions.
8 changes: 2 additions & 6 deletions examples/connect/databricks/dash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def update_page(_):
Dash example application that shows user information and
the first few rows from a table hosted in Databricks.
"""
session_token = flask.request.headers.get(
"Posit-Connect-User-Session-Token"
)
session_token = flask.request.headers.get("Posit-Connect-User-Session-Token")
posit_strategy = PositCredentialsStrategy(
local_strategy=databricks_cli, user_session_token=session_token
)
Expand All @@ -63,9 +61,7 @@ def get_table():
server_hostname=DATABRICKS_HOST,
http_path=SQL_HTTP_PATH,
# https://github.com/databricks/databricks-sql-python/issues/148#issuecomment-2271561365
credentials_provider=posit_strategy.sql_credentials_provider(
cfg
),
credentials_provider=posit_strategy.sql_credentials_provider(cfg),
) as connection:
with connection.cursor() as cursor:
cursor.execute(query)
Expand Down
8 changes: 2 additions & 6 deletions examples/connect/databricks/shiny/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def server(i: Inputs, o: Outputs, session: Session):
Shiny for Python example application that shows user information and
the first few rows from a table hosted in Databricks.
"""
session_token = session.http_conn.headers.get(
"Posit-Connect-User-Session-Token"
)
session_token = session.http_conn.headers.get("Posit-Connect-User-Session-Token")
posit_strategy = PositCredentialsStrategy(
local_strategy=databricks_cli, user_session_token=session_token
)
Expand All @@ -48,9 +46,7 @@ def result():
with connection.cursor() as cursor:
cursor.execute(query)
rows = cursor.fetchall()
df = pd.DataFrame(
rows, columns=[col[0] for col in cursor.description]
)
df = pd.DataFrame(rows, columns=[col[0] for col in cursor.description])
return df

@render.text
Expand Down
14 changes: 3 additions & 11 deletions integration/tests/posit/connect/oauth/test_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def teardown_class(cls):
def test_find_by_integration(self):
associations = self.integration.associations.find()
assert len(associations) == 1
assert (
associations[0]["oauth_integration_guid"]
== self.integration["guid"]
)
assert associations[0]["oauth_integration_guid"] == self.integration["guid"]

no_associations = self.another_integration.associations.find()
assert len(no_associations) == 0
Expand All @@ -85,15 +82,10 @@ def test_find_update_by_content(self):
associations = self.content.oauth.associations.find()
assert len(associations) == 1
assert associations[0]["app_guid"] == self.content["guid"]
assert (
associations[0]["oauth_integration_guid"]
== self.integration["guid"]
)
assert associations[0]["oauth_integration_guid"] == self.integration["guid"]

# update content association to another_integration
self.content.oauth.associations.update(
self.another_integration["guid"]
)
self.content.oauth.associations.update(self.another_integration["guid"])
updated_associations = self.content.oauth.associations.find()
assert len(updated_associations) == 1
assert updated_associations[0]["app_guid"] == self.content["guid"]
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ version_file = "src/posit/_version.py"

[tool.ruff]
extend-exclude = ["integration/resources"]
line-length = 79

[tool.ruff.format]
docstring-code-format = true
Expand Down
6 changes: 1 addition & 5 deletions src/posit/connect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ def __init__(self, *args, **kwargs) -> None:
url = None
if len(args) == 1 and isinstance(args[0], str):
url = args[0]
elif (
len(args) == 2
and isinstance(args[0], str)
and isinstance(args[1], str)
):
elif len(args) == 2 and isinstance(args[0], str) and isinstance(args[1], str):
url = args[0]
api_key = args[1]
else:
Expand Down
8 changes: 2 additions & 6 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def __init__(self, params: ResourceParameters, content_guid: str) -> None:

@property
def associations(self) -> ContentItemAssociations:
return ContentItemAssociations(
self.params, content_guid=self.content_guid
)
return ContentItemAssociations(self.params, content_guid=self.content_guid)


class ContentItemOwner(Resource):
Expand Down Expand Up @@ -124,9 +122,7 @@ def restart(self) -> None:
self.environment_variables.create(key, unix_epoch_in_seconds)
self.environment_variables.delete(key)
# GET via the base Connect URL to force create a new worker thread.
url = posixpath.join(
dirname(self.params.url), f"content/{self.guid}"
)
url = posixpath.join(dirname(self.params.url), f"content/{self.guid}")
self.params.session.get(url)
return None
else:
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class CursorPage:


class CursorPaginator:
def __init__(
self, session: requests.Session, url: str, params: dict = {}
) -> None:
def __init__(self, session: requests.Session, url: str, params: dict = {}) -> None:
self.session = session
self.url = url
self.params = params
Expand Down
8 changes: 2 additions & 6 deletions src/posit/connect/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def __setitem__(self, key: str, value: Optional[str], /) -> None:
Examples
--------
>>> vars = EnvVars(params, content_guid)
>>> vars["DATABASE_URL"] = (
... "postgres://user:password@localhost:5432/database"
... )
>>> vars["DATABASE_URL"] = "postgres://user:password@localhost:5432/database"
"""
self.update({key: value})

Expand Down Expand Up @@ -153,9 +151,7 @@ def update(self, other=(), /, **kwargs: Optional[str]):
Examples
--------
Update using keyword arguments:
>>> update(
... DATABASE_URL="postgres://user:password@localhost:5432/database"
... )
>>> update(DATABASE_URL="postgres://user:password@localhost:5432/database")
Update using multiple keyword arguments:
>>> update(
Expand Down
8 changes: 2 additions & 6 deletions src/posit/connect/external/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ def __init__(self, client: Client, user_session_token: str):
self._user_session_token = user_session_token

def __call__(self) -> Dict[str, str]:
credentials = self._client.oauth.get_credentials(
self._user_session_token
)
credentials = self._client.oauth.get_credentials(self._user_session_token)
access_token = credentials.get("access_token")
if access_token is None:
raise ValueError(
"Missing value for field 'access_token' in credentials."
)
raise ValueError("Missing value for field 'access_token' in credentials.")
return {"Authorization": f"Bearer {access_token}"}


Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/external/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,5 @@ def token(self) -> Optional[str]:
if self._client is None:
self._client = Client()

credentials = self._client.oauth.get_credentials(
self._user_session_token
)
credentials = self._client.oauth.get_credentials(self._user_session_token)
return credentials.get("access_token")
4 changes: 1 addition & 3 deletions src/posit/connect/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def handle_errors(response: Response, *args, **kwargs) -> Response:
return response


def check_for_deprecation_header(
response: Response, *args, **kwargs
) -> Response:
def check_for_deprecation_header(response: Response, *args, **kwargs) -> Response:
"""
Check for deprecation warnings from the server.
Expand Down
16 changes: 4 additions & 12 deletions src/posit/connect/oauth/associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class Association(Resource):
class IntegrationAssociations(Resources):
"""IntegrationAssociations resource."""

def __init__(
self, params: ResourceParameters, integration_guid: str
) -> None:
def __init__(self, params: ResourceParameters, integration_guid: str) -> None:
super().__init__(params)
self.integration_guid = integration_guid

Expand Down Expand Up @@ -52,9 +50,7 @@ def find(self) -> List[Association]:
-------
List[Association]
"""
path = (
f"v1/content/{self.content_guid}/oauth/integrations/associations"
)
path = f"v1/content/{self.content_guid}/oauth/integrations/associations"
url = self.params.url + path
response = self.params.session.get(url)
return [
Expand All @@ -69,18 +65,14 @@ def delete(self) -> None:
"""Delete integration associations."""
data = []

path = (
f"v1/content/{self.content_guid}/oauth/integrations/associations"
)
path = f"v1/content/{self.content_guid}/oauth/integrations/associations"
url = self.params.url + path
self.params.session.put(url, json=data)

def update(self, integration_guid: str) -> None:
"""Set integration associations."""
data = [{"oauth_integration_guid": integration_guid}]

path = (
f"v1/content/{self.content_guid}/oauth/integrations/associations"
)
path = f"v1/content/{self.content_guid}/oauth/integrations/associations"
url = self.params.url + path
self.params.session.put(url, json=data)
4 changes: 1 addition & 3 deletions src/posit/connect/oauth/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class Integration(Resource):

@property
def associations(self) -> IntegrationAssociations:
return IntegrationAssociations(
self.params, integration_guid=self["guid"]
)
return IntegrationAssociations(self.params, integration_guid=self["guid"])

def delete(self) -> None:
"""Delete the OAuth integration."""
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/oauth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def integrations(self):
def sessions(self):
return Sessions(self.params)

def get_credentials(
self, user_session_token: Optional[str] = None
) -> Credentials:
def get_credentials(self, user_session_token: Optional[str] = None) -> Credentials:
url = self.params.url + "v1/oauth/integrations/credentials"

# craft a credential exchange request
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class Paginator:
url (str): The URL of the paginated API endpoint.
"""

def __init__(
self, session: requests.Session, url: str, params: dict = {}
) -> None:
def __init__(self, session: requests.Session, url: str, params: dict = {}) -> None:
self.session = session
self.url = url
self.params = params
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,4 @@ def _append(url: str, path) -> str:
path = str(path).strip("/")
split = urlsplit(url, allow_fragments=False)
new_path = posixpath.join(split.path, path)
return urlunsplit(
(split.scheme, split.netloc, new_path, split.query, None)
)
return urlunsplit((split.scheme, split.netloc, new_path, split.query, None))
8 changes: 2 additions & 6 deletions tests/posit/connect/metrics/test_shiny_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ class TestShinyUsageEventAttributes:
def setup_class(cls):
cls.event = shiny_usage.ShinyUsageEvent(
mock.Mock(),
**load_mock("v1/instrumentation/shiny/usage?limit=500.json")[
"results"
][0],
**load_mock("v1/instrumentation/shiny/usage?limit=500.json")["results"][0],
)

def test_content_guid(self):
assert (
self.event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"
)
assert self.event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"

def test_user_guid(self):
assert self.event.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"
Expand Down
32 changes: 9 additions & 23 deletions tests/posit/connect/metrics/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ class TestUsageEventFromVisitEvent:
def setup_class(cls):
visit_event = visits.VisitEvent(
mock.Mock(),
**load_mock("v1/instrumentation/content/visits?limit=500.json")[
"results"
][0],
**load_mock("v1/instrumentation/content/visits?limit=500.json")["results"][
0
],
)
cls.view_event = usage.UsageEvent.from_visit_event(visit_event)

def test_content_guid(self):
assert (
self.view_event.content_guid
== "bd1d2285-6c80-49af-8a83-a200effe3cb3"
)
assert self.view_event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"

def test_user_guid(self):
assert (
self.view_event.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"
)
assert self.view_event.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"

def test_variant_key(self):
assert self.view_event.variant_key == "HidI2Kwq"
Expand Down Expand Up @@ -63,22 +58,15 @@ class TestUsageEventFromShinyUsageEvent:
def setup_class(cls):
visit_event = shiny_usage.ShinyUsageEvent(
mock.Mock(),
**load_mock("v1/instrumentation/shiny/usage?limit=500.json")[
"results"
][0],
**load_mock("v1/instrumentation/shiny/usage?limit=500.json")["results"][0],
)
cls.view_event = usage.UsageEvent.from_shiny_usage_event(visit_event)

def test_content_guid(self):
assert (
self.view_event.content_guid
== "bd1d2285-6c80-49af-8a83-a200effe3cb3"
)
assert self.view_event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"

def test_user_guid(self):
assert (
self.view_event.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"
)
assert self.view_event.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"

def test_variant_key(self):
assert self.view_event.variant_key is None
Expand Down Expand Up @@ -248,9 +236,7 @@ def test(self):
assert mock_get[2].call_count == 0
assert mock_get[3].call_count == 0
assert view_event
assert (
view_event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"
)
assert view_event.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"

@responses.activate
def test_none(self):
Expand Down
10 changes: 4 additions & 6 deletions tests/posit/connect/metrics/test_visits.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ class TestVisitAttributes:
def setup_class(cls):
cls.visit = visits.VisitEvent(
mock.Mock(),
**load_mock("v1/instrumentation/content/visits?limit=500.json")[
"results"
][0],
**load_mock("v1/instrumentation/content/visits?limit=500.json")["results"][
0
],
)

def test_content_guid(self):
assert (
self.visit.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"
)
assert self.visit.content_guid == "bd1d2285-6c80-49af-8a83-a200effe3cb3"

def test_user_guid(self):
assert self.visit.user_guid == "08e3a41d-1f8e-47f2-8855-f05ea3b0d4b2"
Expand Down
Loading

0 comments on commit aa540ba

Please sign in to comment.