Skip to content

Commit

Permalink
style: set line length to 99
Browse files Browse the repository at this point in the history
The maximum line length recommended in PEP-8 is 99.

> Some teams strongly prefer a longer line length. For code maintained exclusively or primarily by a team that can reach agreement on this issue, it is okay to increase the line length limit up to 99 characters, provided that comments and docstrings are still wrapped at 72 characters.
  • Loading branch information
tdstein committed Sep 13, 2024
1 parent aa540ba commit eb477e0
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 193 deletions.
4 changes: 1 addition & 3 deletions examples/connect/databricks/dash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def get_table():
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])

table = dash_table.DataTable(
id="table",
Expand Down
4 changes: 1 addition & 3 deletions examples/connect/snowflake/streamlit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
TABLE = os.getenv("SNOWFLAKE_TABLE", "lineitem")

session_token = st.context.headers.get("Posit-Connect-User-Session-Token")
auth = PositAuthenticator(
local_authenticator="EXTERNALBROWSER", user_session_token=session_token
)
auth = PositAuthenticator(local_authenticator="EXTERNALBROWSER", user_session_token=session_token)

con = snowflake.connector.connect(
user=USER,
Expand Down
9 changes: 2 additions & 7 deletions integration/tests/posit/connect/oauth/test_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def setup_class(cls):
# requires full bundle deployment to produce an interactive content type
cls.content = cls.client.content.create(name="example-flask-minimal")
# create bundle
path = Path(
"../../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz"
)
path = Path("../../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz")
path = (Path(__file__).parent / path).resolve()
bundle = cls.content.bundles.create(str(path))
# deploy bundle
Expand Down Expand Up @@ -89,10 +87,7 @@ def test_find_update_by_content(self):
updated_associations = self.content.oauth.associations.find()
assert len(updated_associations) == 1
assert updated_associations[0]["app_guid"] == self.content["guid"]
assert (
updated_associations[0]["oauth_integration_guid"]
== self.another_integration.guid
)
assert updated_associations[0]["oauth_integration_guid"] == self.another_integration.guid

# unset content association
self.content.oauth.associations.delete()
Expand Down
8 changes: 2 additions & 6 deletions integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def test_restart(self):
# create content
content = self.client.content.create(name="example-flask-minimal")
# create bundle
path = Path(
"../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz"
)
path = Path("../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz")
path = (Path(__file__).parent / path).resolve()
bundle = content.bundles.create(str(path))
# deploy bundle
Expand All @@ -70,9 +68,7 @@ def test_render(self):
# create content
content = self.client.content.create(name="example-quarto-minimal")
# create bundle
path = Path(
"../../../resources/connect/bundles/example-quarto-minimal/bundle.tar.gz"
)
path = Path("../../../resources/connect/bundles/example-quarto-minimal/bundle.tar.gz")
path = (Path(__file__).parent / path).resolve()
bundle = content.bundles.create(str(path))
# deploy bundle
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ version_file = "src/posit/_version.py"

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

[tool.ruff.format]
docstring-code-format = true
Expand Down
12 changes: 3 additions & 9 deletions src/posit/connect/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def _get_api_key() -> str:
"""
value = os.environ.get("CONNECT_API_KEY")
if not value:
raise ValueError(
"Invalid value for 'CONNECT_API_KEY': Must be a non-empty string."
)
raise ValueError("Invalid value for 'CONNECT_API_KEY': Must be a non-empty string.")
return value


Expand All @@ -42,17 +40,13 @@ def _get_url() -> str:
"""
value = os.environ.get("CONNECT_SERVER")
if not value:
raise ValueError(
"Invalid value for 'CONNECT_SERVER': Must be a non-empty string."
)
raise ValueError("Invalid value for 'CONNECT_SERVER': Must be a non-empty string.")
return value


class Config:
"""Configuration object."""

def __init__(
self, api_key: Optional[str] = None, url: Optional[str] = None
) -> None:
def __init__(self, api_key: Optional[str] = None, url: Optional[str] = None) -> None:
self.api_key = api_key or _get_api_key()
self.url = urls.Url(url or _get_url())
8 changes: 2 additions & 6 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ def find(
...

@overload
def find(
self, *args, include: Optional[str] = "owner,tags", **kwargs
) -> List[ContentItem]:
def find(self, *args, include: Optional[str] = "owner,tags", **kwargs) -> List[ContentItem]:
"""Find content items.
Parameters
Expand All @@ -430,9 +428,7 @@ def find(
"""
...

def find(
self, *args, include: Optional[str] = "owner,tags", **kwargs
) -> List[ContentItem]:
def find(self, *args, include: Optional[str] = "owner,tags", **kwargs) -> List[ContentItem]:
"""Find content items.
Parameters
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/external/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def __call__(self, *args, **kwargs) -> CredentialsProvider:
# If the user-session-token wasn't provided and we're running on Connect then we raise an exception.
# user_session_token is required to impersonate the viewer.
if self._user_session_token is None:
raise ValueError(
"The user-session-token is required for viewer authentication."
)
raise ValueError("The user-session-token is required for viewer authentication.")

if self._client is None:
self._client = Client()
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 @@ -33,9 +33,7 @@ def token(self) -> Optional[str]:
# If the user-session-token wasn't provided and we're running on Connect then we raise an exception.
# user_session_token is required to impersonate the viewer.
if self._user_session_token is None:
raise ValueError(
"The user-session-token is required for viewer authentication."
)
raise ValueError("The user-session-token is required for viewer authentication.")

if self._client is None:
self._client = Client()
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def count(self) -> int:
"""
path = "v1/groups"
url = self.params.url + path
response: requests.Response = self.params.session.get(
url, params={"page_size": 1}
)
response: requests.Response = self.params.session.get(url, params={"page_size": 1})
result: dict = response.json()
return result["total"]
4 changes: 1 addition & 3 deletions src/posit/connect/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def handle_errors(response: Response, *args, **kwargs) -> Response:
payload = data.get("payload")
http_status = response.status_code
http_status_message = responses[http_status]
raise ClientError(
error_code, message, http_status, http_status_message, payload
)
raise ClientError(error_code, message, http_status, http_status_message, payload)
except JSONDecodeError:
# No JSON error message from Connect, so just raise
response.raise_for_status()
Expand Down
4 changes: 1 addition & 3 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def count(self) -> int:
return len(self.find())

@overload
def create(
self, *, principal_guid: str, principal_type: str, role: str
) -> Permission:
def create(self, *, principal_guid: str, principal_type: str, role: str) -> Permission:
"""Create a permission.
Parameters
Expand Down
8 changes: 2 additions & 6 deletions src/posit/connect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ def _create(url: str) -> str:
"""
split = urlsplit(url, allow_fragments=False)
if not split.scheme:
raise ValueError(
f"URL must specify a scheme (e.g., http://example.com/__api__): {url}"
)
raise ValueError(f"URL must specify a scheme (e.g., http://example.com/__api__): {url}")
if not split.netloc:
raise ValueError(
f"URL must be absolute (e.g., http://example.com/__api__): {url}"
)
raise ValueError(f"URL must be absolute (e.g., http://example.com/__api__): {url}")

url = url.rstrip("/")
if "/__api__" not in url:
Expand Down
16 changes: 4 additions & 12 deletions tests/posit/connect/metrics/test_shiny_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/shiny/usage",
json=load_mock(
"v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -66,9 +64,7 @@ def test(self):
)

# setup
params = ResourceParameters(
requests.Session(), "https://connect.example/__api__"
)
params = ResourceParameters(requests.Session(), "https://connect.example/__api__")

# invoke
events = shiny_usage.ShinyUsage(params).find()
Expand Down Expand Up @@ -98,9 +94,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/shiny/usage",
json=load_mock(
"v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -112,9 +106,7 @@ def test(self):
)

# setup
params = ResourceParameters(
requests.Session(), "https://connect.example/__api__"
)
params = ResourceParameters(requests.Session(), "https://connect.example/__api__")

# invoke
event = shiny_usage.ShinyUsage(params).find_one()
Expand Down
28 changes: 7 additions & 21 deletions tests/posit/connect/metrics/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ 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)

Expand Down Expand Up @@ -110,9 +108,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/content/visits",
json=load_mock(
"v1/instrumentation/content/visits?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -137,9 +133,7 @@ def test(self):

mock_get[3] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/shiny/usage",
json=load_mock(
"v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand Down Expand Up @@ -184,9 +178,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/content/visits",
json=load_mock(
"v1/instrumentation/content/visits?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -211,9 +203,7 @@ def test(self):

mock_get[3] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/shiny/usage",
json=load_mock(
"v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand Down Expand Up @@ -246,16 +236,12 @@ def test_none(self):
# return an empty result set to push through the iterator
mock_get[0] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/content/visits",
json=load_mock(
"v1/instrumentation/content/visits?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"),
)

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/shiny/usage",
json=load_mock(
"v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/shiny/usage?limit=500&next=23948901087.json"),
)

# setup
Expand Down
20 changes: 5 additions & 15 deletions tests/posit/connect/metrics/test_visits.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ 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):
Expand Down Expand Up @@ -63,9 +61,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/content/visits",
json=load_mock(
"v1/instrumentation/content/visits?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -77,9 +73,7 @@ def test(self):
)

# setup
params = ResourceParameters(
requests.Session(), "https://connect.example/__api__"
)
params = ResourceParameters(requests.Session(), "https://connect.example/__api__")

# invoke
events = visits.Visits(params).find()
Expand Down Expand Up @@ -109,9 +103,7 @@ def test(self):

mock_get[1] = responses.get(
f"https://connect.example/__api__/v1/instrumentation/content/visits",
json=load_mock(
"v1/instrumentation/content/visits?limit=500&next=23948901087.json"
),
json=load_mock("v1/instrumentation/content/visits?limit=500&next=23948901087.json"),
match=[
matchers.query_param_matcher(
{
Expand All @@ -123,9 +115,7 @@ def test(self):
)

# setup
params = ResourceParameters(
requests.Session(), "https://connect.example/__api__"
)
params = ResourceParameters(requests.Session(), "https://connect.example/__api__")

# invoke
event = visits.Visits(params).find_one()
Expand Down
5 changes: 1 addition & 4 deletions tests/posit/connect/oauth/test_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def test_app_guid(self):
assert self.item["app_guid"] == "f2f37341-e21d-3d80-c698-a935ad614066"

def test_oauth_integration_guid(self):
assert (
self.item["oauth_integration_guid"]
== "22644575-a27b-4118-ad06-e24459b05126"
)
assert self.item["oauth_integration_guid"] == "22644575-a27b-4118-ad06-e24459b05126"

def test_oauth_integration_name(self):
assert self.item["oauth_integration_name"] == "keycloak integration"
Expand Down
Loading

0 comments on commit eb477e0

Please sign in to comment.