Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unused imports and organize used imports #246

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/connect/dash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# mypy: ignore-errors
import os

from posit.connect.external.databricks import viewer_credentials_provider

import flask
import pandas as pd
from dash import Dash, Input, Output, dash_table, html
from databricks import sql
from databricks.sdk.service.iam import CurrentUserAPI
from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI

from dash import Dash, html, Output, Input, dash_table
import pandas as pd
import flask
from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
Expand Down
8 changes: 3 additions & 5 deletions examples/connect/fastapi/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
# mypy: ignore-errors
import os

from posit.connect.external.databricks import viewer_credentials_provider

from databricks import sql

from typing import Annotated

from databricks import sql
from fastapi import FastAPI, Header
from fastapi.responses import JSONResponse

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
SQL_HTTP_PATH = os.getenv("DATABRICKS_PATH")
Expand Down
3 changes: 2 additions & 1 deletion examples/connect/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# mypy: ignore-errors
import os

from posit.connect.external.databricks import viewer_credentials_provider
from databricks import sql
from flask import Flask, request

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
SQL_HTTP_PATH = os.getenv("DATABRICKS_PATH")
Expand Down
8 changes: 3 additions & 5 deletions examples/connect/shiny-python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import os

import pandas as pd

from posit.connect.external.databricks import viewer_credentials_provider

from databricks import sql
from databricks.sdk.service.iam import CurrentUserAPI
from databricks.sdk.core import ApiClient, Config

from databricks.sdk.service.iam import CurrentUserAPI
from shiny import App, Inputs, Outputs, Session, render, ui

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
SQL_HTTP_PATH = os.getenv("DATABRICKS_PATH")
Expand Down
11 changes: 5 additions & 6 deletions examples/connect/streamlit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
# mypy: ignore-errors
import os

from posit.connect.external.databricks import viewer_credentials_provider

from databricks import sql
from databricks.sdk.service.iam import CurrentUserAPI
from databricks.sdk.core import ApiClient, Config

import pandas as pd
import streamlit as st
from databricks import sql
from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI
from streamlit.web.server.websocket_headers import _get_websocket_headers

from posit.connect.external.databricks import viewer_credentials_provider

DATABRICKS_HOST = os.getenv("DATABRICKS_HOST")
DATABRICKS_HOST_URL = f"https://{DATABRICKS_HOST}"
SQL_HTTP_PATH = os.getenv("DATABRICKS_PATH")
Expand Down
2 changes: 0 additions & 2 deletions integration/tests/posit/connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from packaging import version

from posit import connect
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from packaging import version

import pytest
from packaging import version

from posit import connect

Expand Down
18 changes: 10 additions & 8 deletions src/posit/connect/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from __future__ import annotations

import io
import requests
from typing import List
from . import config, resources, tasks, urls

import requests

from . import config, resources, tasks


class BundleMetadata(resources.Resource):
Expand Down Expand Up @@ -142,7 +144,7 @@ def metadata(self) -> BundleMetadata:
def delete(self) -> None:
"""Delete the bundle."""
path = f"v1/content/{self.content_guid}/bundles/{self.id}"
url = urls.append(self.config.url, path)
url = self.config.url + path
self.session.delete(url)

def deploy(self) -> tasks.Task:
Expand All @@ -162,7 +164,7 @@ def deploy(self) -> tasks.Task:
None
"""
path = f"v1/content/{self.content_guid}/deploy"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.post(url, json={"bundle_id": self.id})
result = response.json()
ts = tasks.Tasks(self.config, self.session)
Expand Down Expand Up @@ -200,7 +202,7 @@ def download(self, output: io.BufferedWriter | str) -> None:
)

path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.get(url, stream=True)
if isinstance(output, io.BufferedWriter):
for chunk in response.iter_content():
Expand Down Expand Up @@ -287,7 +289,7 @@ def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
)

path = f"v1/content/{self.content_guid}/bundles"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.post(url, data=data)
result = response.json()
return Bundle(self.config, self.session, **result)
Expand All @@ -301,7 +303,7 @@ def find(self) -> List[Bundle]:
List of all found bundles.
"""
path = f"v1/content/{self.content_guid}/bundles"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.get(url)
results = response.json()
return [
Expand Down Expand Up @@ -333,7 +335,7 @@ def get(self, id: str) -> Bundle:
The bundle with the specified ID.
"""
path = f"v1/content/{self.content_guid}/bundles/{id}"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.get(url)
result = response.json()
return Bundle(self.config, self.session, **result)
22 changes: 11 additions & 11 deletions src/posit/connect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

from __future__ import annotations

from requests import Response, Session
from typing import Optional, overload
from typing import overload

from . import hooks, me, urls
from requests import Response, Session

from . import hooks, me
from .auth import Auth
from .config import Config
from .oauth import OAuthIntegration
from .content import Content
from .groups import Groups
from .metrics import Metrics
from .oauth import OAuthIntegration
from .tasks import Tasks
from .users import User, Users
from .groups import Groups


class Client:
Expand Down Expand Up @@ -318,7 +318,7 @@ def request(self, method: str, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.request(method, url, **kwargs)

def get(self, path: str, **kwargs) -> Response:
Expand All @@ -339,7 +339,7 @@ def get(self, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.get(url, **kwargs)

def post(self, path: str, **kwargs) -> Response:
Expand All @@ -360,7 +360,7 @@ def post(self, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.post(url, **kwargs)

def put(self, path: str, **kwargs) -> Response:
Expand All @@ -381,7 +381,7 @@ def put(self, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.put(url, **kwargs)

def patch(self, path: str, **kwargs) -> Response:
Expand All @@ -402,7 +402,7 @@ def patch(self, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.patch(url, **kwargs)

def delete(self, path: str, **kwargs) -> Response:
Expand All @@ -423,5 +423,5 @@ def delete(self, path: str, **kwargs) -> Response:
Response
A [](`requests.Response`) object.
"""
url = urls.append(self.config.url, path)
url = self.config.url + path
return self.session.delete(url, **kwargs)
3 changes: 1 addition & 2 deletions src/posit/connect/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Client configuration."""

import os

from typing import Optional

from . import urls
Expand Down Expand Up @@ -56,4 +55,4 @@ 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.create(url or _get_url())
self.url = urls.Url(url or _get_url())
16 changes: 8 additions & 8 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from requests import Session

from . import tasks, urls
from . import tasks
from .bundles import Bundles
from .config import Config
from .env import EnvVars
Expand Down Expand Up @@ -144,7 +144,7 @@ class ContentItem(Resource):
def delete(self) -> None:
"""Delete the content item."""
path = f"v1/content/{self.guid}"
url = urls.append(self.config.url, path)
url = self.config.url + path
self.session.delete(url)

def deploy(self) -> tasks.Task:
Expand All @@ -164,7 +164,7 @@ def deploy(self) -> tasks.Task:
None
"""
path = f"v1/content/{self.guid}/deploy"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.post(url, json={"bundle_id": None})
result = response.json()
ts = tasks.Tasks(self.config, self.session)
Expand Down Expand Up @@ -237,7 +237,7 @@ def restart(self) -> None:
self.environment_variables.create(key, random_hash)
self.environment_variables.delete(key)
# GET via the base Connect URL to force create a new worker thread.
url = urls.append(dirname(self.config.url), f"content/{self.guid}")
url = dirname(self.config.url) + f"/content/{self.guid}"
self.session.get(url)
return None
else:
Expand Down Expand Up @@ -314,7 +314,7 @@ def update(self, *args, **kwargs) -> None:
def update(self, *args, **kwargs) -> None:
"""Update the content item."""
body = dict(*args, **kwargs)
url = urls.append(self.config.url, f"v1/content/{self.guid}")
url = self.config.url + f"v1/content/{self.guid}"
response = self.session.patch(url, json=body)
super().update(**response.json())

Expand Down Expand Up @@ -548,7 +548,7 @@ def __init__(
*,
owner_guid: str | None = None,
) -> None:
self.url = urls.append(config.url, "v1/content")
self.url = config.url + "v1/content"
self.config = config
self.session = session
self.owner_guid = owner_guid
Expand Down Expand Up @@ -656,7 +656,7 @@ def create(self, *args, **kwargs) -> ContentItem:
"""
body = dict(*args, **kwargs)
path = "v1/content"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.post(url, json=body)
return ContentItem(self.config, self.session, **response.json())

Expand Down Expand Up @@ -798,6 +798,6 @@ def get(self, guid: str) -> ContentItem:
-------
ContentItem
"""
url = urls.append(self.url, guid)
url = self.url + guid
response = self.session.get(url)
return ContentItem(self.config, self.session, **response.json())
2 changes: 1 addition & 1 deletion src/posit/connect/cursors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass, make_dataclass
from dataclasses import dataclass
from typing import Generator, List

import requests
Expand Down
7 changes: 3 additions & 4 deletions src/posit/connect/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from requests import Session

from . import urls
from .config import Config
from .resources import Resources

Expand Down Expand Up @@ -71,7 +70,7 @@ def clear(self) -> None:
>>> clear()
"""
path = f"v1/content/{self.content_guid}/environment"
url = urls.append(self.config.url, path)
url = self.config.url + path
self.session.put(url, json=[])

def create(self, key: str, value: str, /) -> None:
Expand Down Expand Up @@ -129,7 +128,7 @@ def find(self) -> List[str]:
['DATABASE_URL']
"""
path = f"v1/content/{self.content_guid}/environment"
url = urls.append(self.config.url, path)
url = self.config.url + path
response = self.session.get(url)
return response.json()

Expand Down Expand Up @@ -204,5 +203,5 @@ def update(self, other=(), /, **kwargs: Optional[str]):

body = [{"name": key, "value": value} for key, value in d.items()]
path = f"v1/content/{self.content_guid}/environment"
url = urls.append(self.config.url, path)
url = self.config.url + path
self.session.patch(url, json=body)
Loading
Loading