Skip to content

Commit

Permalink
chore: apply flake8 builtin rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tdstein committed Jul 26, 2024
1 parent ceb3331 commit ddbae38
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion examples/connect/shiny-python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
app_ui = ui.page_fluid(ui.output_text("text"), ui.output_data_frame("result"))


def server(input: Inputs, output: Outputs, session: Session):
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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.ruff.lint]
select = ["D", "F401", "I"]
select = ["A", "D", "F401", "I"]
ignore = [
# NumPy style docstring convention with noted exceptions.
# https://docs.astral.sh/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings
Expand Down
22 changes: 11 additions & 11 deletions src/posit/connect/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,16 @@ def __init__(
super().__init__(config, session)
self.content_guid = content_guid

def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
def create(self, archive: io.BufferedReader | bytes | str) -> Bundle:
"""
Create a bundle.
Create a bundle from a file or memory.
Parameters
----------
input : io.BufferedReader, bytes, or str
Input archive for bundle creation. A 'str' type assumes a relative or absolute filepath.
archive : io.BufferedReader, bytes, or str
Archive for bundle creation. A 'str' type assumes a relative or absolute filepath.
Returns
-------
Expand Down Expand Up @@ -278,14 +278,14 @@ def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
>>> bundle.create("bundle.tar.gz")
None
"""
if isinstance(input, (io.BufferedReader, bytes)):
data = input
elif isinstance(input, str):
with open(input, "rb") as file:
if isinstance(archive, (io.BufferedReader, bytes)):
data = archive
elif isinstance(archive, str):
with open(archive, "rb") as file:
data = file.read()
else:
raise TypeError(
f"create() expected argument type 'io.BufferedReader', 'bytes', or 'str', but got '{type(input).__name__}'"
f"create() expected argument type 'io.BufferedReader', 'bytes', or 'str', but got '{type(archive).__name__}'"
)

path = f"v1/content/{self.content_guid}/bundles"
Expand Down Expand Up @@ -321,20 +321,20 @@ def find_one(self) -> Bundle | None:
bundles = self.find()
return next(iter(bundles), None)

def get(self, id: str) -> Bundle:
def get(self, uid: str) -> Bundle:
"""Get a bundle.
Parameters
----------
id : str
uid : str
Identifier of the bundle to retrieve.
Returns
-------
Bundle
The bundle with the specified ID.
"""
path = f"v1/content/{self.content_guid}/bundles/{id}"
path = f"v1/content/{self.content_guid}/bundles/{uid}"
url = self.config.url + path
response = self.session.get(url)
result = response.json()
Expand Down
12 changes: 6 additions & 6 deletions src/posit/connect/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def fetch_pages(self) -> Generator[CursorPage, None, None]:
------
Generator[Page, None, None]
"""
next = None
next_page = None
while True:
page = self.fetch_page(next)
page = self.fetch_page(next_page)
yield page
cursors: dict = page.paging.get("cursors", {})
next = cursors.get("next")
if not next:
next_page = cursors.get("next")
if not next_page:
# stop if a next page is not defined
return

def fetch_page(self, next: str | None = None) -> CursorPage:
def fetch_page(self, next_page: str | None = None) -> CursorPage:
"""Fetch a page.
Parameters
Expand All @@ -69,7 +69,7 @@ def fetch_page(self, next: str | None = None) -> CursorPage:
"""
params = {
**self.params,
"next": next,
"next": next_page,
"limit": _MAX_PAGE_SIZE,
}
response = self.session.get(self.url, params=params)
Expand Down
6 changes: 3 additions & 3 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ def find_one(self, *args, **kwargs) -> Permission | None:
permissions = self.find(*args, **kwargs)
return next(iter(permissions), None)

def get(self, id: str) -> Permission:
def get(self, uid: str) -> Permission:
"""Get a permission.
Parameters
----------
id : str
uid : str
The permission id.
Returns
-------
Permission
"""
path = f"v1/content/{self.content_guid}/permissions/{id}"
path = f"v1/content/{self.content_guid}/permissions/{uid}"
url = self.config.url + path
response = self.session.get(url)
return Permission(self.config, self.session, **response.json())
14 changes: 7 additions & 7 deletions src/posit/connect/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def wait_for(self) -> None:

class Tasks(resources.Resources):
@overload
def get(self, id: str, first: int, wait: int) -> Task:
def get(self, uid: str, first: int, wait: int) -> Task:
"""Get a task.
Parameters
----------
id : str
uid : str
Task identifier.
first : int, default 0
Line to start output on.
Expand All @@ -163,12 +163,12 @@ def get(self, id: str, first: int, wait: int) -> Task:
...

@overload
def get(self, id: str, *args, **kwargs) -> Task:
def get(self, uid: str, *args, **kwargs) -> Task:
"""Get a task.
Parameters
----------
id : str
uid : str
Task identifier.
Returns
Expand All @@ -177,20 +177,20 @@ def get(self, id: str, *args, **kwargs) -> Task:
"""
...

def get(self, id: str, *args, **kwargs) -> Task:
def get(self, uid: str, *args, **kwargs) -> Task:
"""Get a task.
Parameters
----------
id : str
uid : str
Task identifier.
Returns
-------
Task
"""
params = dict(*args, **kwargs)
path = f"v1/tasks/{id}"
path = f"v1/tasks/{uid}"
url = self.config.url + path
response = self.session.get(url, params=params)
result = response.json()
Expand Down
4 changes: 2 additions & 2 deletions src/posit/connect/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def find_one(self, *args, **kwargs) -> User | None:
)
return next(users, None)

def get(self, id: str) -> User:
url = self.config.url + f"v1/users/{id}"
def get(self, uid: str) -> User:
url = self.config.url + f"v1/users/{uid}"
response = self.session.get(url)
return User(
config=self.config,
Expand Down
6 changes: 3 additions & 3 deletions tests/posit/connect/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
from .api import load_mock # type: ignore


@pytest.fixture
@pytest.fixture()
def MockAuth():
with patch("posit.connect.client.Auth") as mock:
yield mock


@pytest.fixture
@pytest.fixture()
def MockConfig():
with patch("posit.connect.client.Config") as mock:
yield mock


@pytest.fixture
@pytest.fixture()
def MockSession():
with patch("posit.connect.client.Session") as mock:
yield mock
Expand Down
4 changes: 2 additions & 2 deletions tests/posit/connect/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ def test_find():
content = c.content.get(guid)

# invoke
vars = content.environment_variables.find()
envvars = content.environment_variables.find()

# assert
assert vars == ["TEST"]
assert envvars == ["TEST"]
assert mock_get_content.call_count == 1
assert mock_get_environment.call_count == 1

Expand Down
34 changes: 17 additions & 17 deletions tests/posit/connect/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class TestPermissionDelete:
@responses.activate
def test(self):
# data
id = "94"
uid = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"

# behavior
mock_delete = responses.delete(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}"
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}"
)

# setup
config = Config(api_key="12345", url="https://connect.example/")
session = requests.Session()
fake_permission = load_mock(
f"v1/content/{content_guid}/permissions/{id}.json"
f"v1/content/{content_guid}/permissions/{uid}.json"
)
permission = Permission(config, session, **fake_permission)

Expand All @@ -41,7 +41,7 @@ class TestPermissionUpdate:
@responses.activate
def test_request_shape(self):
# test data
id = random.randint(0, 100)
uid = random.randint(0, 100)
content_guid = str(uuid.uuid4())
principal_guid = str(uuid.uuid4())
principal_type = "principal_type"
Expand All @@ -50,7 +50,7 @@ def test_request_shape(self):

# define api behavior
responses.put(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
json={
# doesn't matter for this test
},
Expand All @@ -75,7 +75,7 @@ def test_request_shape(self):
permission = Permission(
config,
session,
id=id,
id=uid,
content_guid=content_guid,
principal_guid=principal_guid,
principal_type=principal_type,
Expand All @@ -92,18 +92,18 @@ def test_role_update(self):
old_role = "owner"
new_role = "viewer"

id = "94"
uid = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
fake_permission = load_mock(
f"v1/content/{content_guid}/permissions/{id}.json"
f"v1/content/{content_guid}/permissions/{uid}.json"
)
fake_permission.update(role=new_role)

# define api behavior
id = random.randint(0, 100)
uid = random.randint(0, 100)
content_guid = str(uuid.uuid4())
responses.put(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
json=fake_permission,
match=[
matchers.json_params_matcher(
Expand All @@ -120,7 +120,7 @@ def test_role_update(self):
config = Config(api_key="12345", url="https://connect.example/")
session = requests.Session()
permission = Permission(
config, session, id=id, content_guid=content_guid, role=old_role
config, session, id=uid, content_guid=content_guid, role=old_role
)

# assert role change with respect to api response
Expand Down Expand Up @@ -160,13 +160,13 @@ class TestPermissionsCreate:
@responses.activate
def test(self):
# data
id = "94"
uid = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
principal_guid = str(uuid.uuid4())
principal_type = "user"
role = "owner"
fake_permission = {
**load_mock(f"v1/content/{content_guid}/permissions/{id}.json"),
**load_mock(f"v1/content/{content_guid}/permissions/{uid}.json"),
"principal_guid": principal_guid,
"principal_type": principal_type,
"role": role,
Expand Down Expand Up @@ -261,15 +261,15 @@ class TestPermissionsGet:
@responses.activate
def test(self):
# data
id = "94"
uid = "94"
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
fake_permission = load_mock(
f"v1/content/{content_guid}/permissions/{id}.json"
f"v1/content/{content_guid}/permissions/{uid}.json"
)

# behavior
responses.get(
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
json=fake_permission,
)

Expand All @@ -279,7 +279,7 @@ def test(self):
permissions = Permissions(config, session, content_guid=content_guid)

# invoke
permission = permissions.get(id)
permission = permissions.get(uid)

# assert
assert permission == fake_permission
Loading

0 comments on commit ddbae38

Please sign in to comment.