From 8c74a630b7602d930a38ee6bb568b0ba561f6642 Mon Sep 17 00:00:00 2001 From: Taylor Steinberg Date: Mon, 29 Jul 2024 09:56:28 -0400 Subject: [PATCH] chore: remove unused imports and organize used imports (#246) --- examples/connect/dash/app.py | 11 +++++------ examples/connect/fastapi/app.py | 8 +++----- examples/connect/flask/app.py | 3 ++- examples/connect/shiny-python/app.py | 8 +++----- examples/connect/streamlit/app.py | 11 +++++------ integration/tests/posit/connect/__init__.py | 2 -- integration/tests/posit/connect/test_content.py | 2 +- src/posit/connect/bundles.py | 6 ++++-- src/posit/connect/client.py | 10 +++++----- src/posit/connect/config.py | 1 - src/posit/connect/content.py | 2 +- src/posit/connect/cursors.py | 2 +- src/posit/connect/env.py | 1 - src/posit/connect/groups.py | 3 +-- src/posit/connect/hooks.py | 2 +- src/posit/connect/me.py | 2 -- src/posit/connect/metrics/__init__.py | 2 -- src/posit/connect/metrics/shiny_usage.py | 2 -- src/posit/connect/metrics/usage.py | 3 +-- src/posit/connect/metrics/visits.py | 2 -- src/posit/connect/oauth.py | 4 ++-- src/posit/connect/paginator.py | 1 - src/posit/connect/permissions.py | 2 -- src/posit/connect/tasks.py | 2 +- src/posit/connect/users.py | 4 ++-- src/posit/connect/variants.py | 2 +- tests/posit/connect/api.py | 4 ++-- tests/posit/connect/metrics/test_shiny_usage.py | 5 ++--- tests/posit/connect/metrics/test_usage.py | 2 -- tests/posit/connect/metrics/test_visits.py | 5 ++--- tests/posit/connect/test_bundles.py | 7 +++---- tests/posit/connect/test_client.py | 4 ++-- tests/posit/connect/test_config.py | 4 ++-- tests/posit/connect/test_content.py | 5 ++--- tests/posit/connect/test_env.py | 1 - tests/posit/connect/test_groups.py | 4 ---- tests/posit/connect/test_hooks.py | 3 +-- tests/posit/connect/test_permissions.py | 3 --- tests/posit/connect/test_resources.py | 10 +++------- tests/posit/connect/test_tasks.py | 2 -- tests/posit/connect/test_users.py | 1 - 41 files changed, 58 insertions(+), 100 deletions(-) diff --git a/examples/connect/dash/app.py b/examples/connect/dash/app.py index ccd3008c..e84d15b1 100644 --- a/examples/connect/dash/app.py +++ b/examples/connect/dash/app.py @@ -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}" diff --git a/examples/connect/fastapi/app.py b/examples/connect/fastapi/app.py index c14bd06a..25a8fb38 100644 --- a/examples/connect/fastapi/app.py +++ b/examples/connect/fastapi/app.py @@ -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") diff --git a/examples/connect/flask/app.py b/examples/connect/flask/app.py index 02835ddf..9239d02c 100644 --- a/examples/connect/flask/app.py +++ b/examples/connect/flask/app.py @@ -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") diff --git a/examples/connect/shiny-python/app.py b/examples/connect/shiny-python/app.py index 92568ef9..e1d6292e 100644 --- a/examples/connect/shiny-python/app.py +++ b/examples/connect/shiny-python/app.py @@ -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") diff --git a/examples/connect/streamlit/app.py b/examples/connect/streamlit/app.py index 37b9f7d9..a7081d06 100644 --- a/examples/connect/streamlit/app.py +++ b/examples/connect/streamlit/app.py @@ -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") diff --git a/integration/tests/posit/connect/__init__.py b/integration/tests/posit/connect/__init__.py index 54792a85..7d8dd0b3 100644 --- a/integration/tests/posit/connect/__init__.py +++ b/integration/tests/posit/connect/__init__.py @@ -1,5 +1,3 @@ -import os - from packaging import version from posit import connect diff --git a/integration/tests/posit/connect/test_content.py b/integration/tests/posit/connect/test_content.py index 50af4fb3..0e520c1d 100644 --- a/integration/tests/posit/connect/test_content.py +++ b/integration/tests/posit/connect/test_content.py @@ -1,7 +1,7 @@ from pathlib import Path -from packaging import version import pytest +from packaging import version from posit import connect diff --git a/src/posit/connect/bundles.py b/src/posit/connect/bundles.py index d4945b8e..11fa8958 100644 --- a/src/posit/connect/bundles.py +++ b/src/posit/connect/bundles.py @@ -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): diff --git a/src/posit/connect/client.py b/src/posit/connect/client.py index 93fff31a..b36cc823 100644 --- a/src/posit/connect/client.py +++ b/src/posit/connect/client.py @@ -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: diff --git a/src/posit/connect/config.py b/src/posit/connect/config.py index 74af0c31..d119bc13 100644 --- a/src/posit/connect/config.py +++ b/src/posit/connect/config.py @@ -1,7 +1,6 @@ """Client configuration.""" import os - from typing import Optional from . import urls diff --git a/src/posit/connect/content.py b/src/posit/connect/content.py index 75b2b30d..42b704fe 100644 --- a/src/posit/connect/content.py +++ b/src/posit/connect/content.py @@ -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 diff --git a/src/posit/connect/cursors.py b/src/posit/connect/cursors.py index 187c2d9a..98a039d6 100644 --- a/src/posit/connect/cursors.py +++ b/src/posit/connect/cursors.py @@ -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 diff --git a/src/posit/connect/env.py b/src/posit/connect/env.py index a21d6e13..c6eedd6b 100644 --- a/src/posit/connect/env.py +++ b/src/posit/connect/env.py @@ -4,7 +4,6 @@ from requests import Session -from . import urls from .config import Config from .resources import Resources diff --git a/src/posit/connect/groups.py b/src/posit/connect/groups.py index 000a3a01..4feeeaee 100644 --- a/src/posit/connect/groups.py +++ b/src/posit/connect/groups.py @@ -1,12 +1,11 @@ """Group resources.""" from __future__ import annotations + from typing import List, overload import requests -from . import me, urls - from .config import Config from .paginator import Paginator from .resources import Resource, Resources diff --git a/src/posit/connect/hooks.py b/src/posit/connect/hooks.py index e553045b..2e689224 100644 --- a/src/posit/connect/hooks.py +++ b/src/posit/connect/hooks.py @@ -1,6 +1,6 @@ import warnings - from http.client import responses + from requests import JSONDecodeError, Response from .errors import ClientError diff --git a/src/posit/connect/me.py b/src/posit/connect/me.py index fce1b852..0349c115 100644 --- a/src/posit/connect/me.py +++ b/src/posit/connect/me.py @@ -1,7 +1,5 @@ import requests -from . import urls - from .config import Config from .users import User diff --git a/src/posit/connect/metrics/__init__.py b/src/posit/connect/metrics/__init__.py index 0d0dafb5..0518826a 100644 --- a/src/posit/connect/metrics/__init__.py +++ b/src/posit/connect/metrics/__init__.py @@ -1,8 +1,6 @@ """Metric resources.""" from .. import resources - -from . import usage from .usage import Usage diff --git a/src/posit/connect/metrics/shiny_usage.py b/src/posit/connect/metrics/shiny_usage.py index 9561da64..12a71079 100644 --- a/src/posit/connect/metrics/shiny_usage.py +++ b/src/posit/connect/metrics/shiny_usage.py @@ -2,8 +2,6 @@ from typing import List, overload -from .. import urls - from ..cursors import CursorPaginator from ..resources import Resource, Resources diff --git a/src/posit/connect/metrics/usage.py b/src/posit/connect/metrics/usage.py index fb838233..a59a6245 100644 --- a/src/posit/connect/metrics/usage.py +++ b/src/posit/connect/metrics/usage.py @@ -6,9 +6,8 @@ from requests.sessions import Session as Session -from . import shiny_usage, visits - from .. import resources +from . import shiny_usage, visits class UsageEvent(resources.Resource): diff --git a/src/posit/connect/metrics/visits.py b/src/posit/connect/metrics/visits.py index 9a5a203f..fb249280 100644 --- a/src/posit/connect/metrics/visits.py +++ b/src/posit/connect/metrics/visits.py @@ -2,8 +2,6 @@ from typing import List, overload -from .. import urls - from ..cursors import CursorPaginator from ..resources import Resource, Resources diff --git a/src/posit/connect/oauth.py b/src/posit/connect/oauth.py index 64bb0711..8b7e3dd7 100644 --- a/src/posit/connect/oauth.py +++ b/src/posit/connect/oauth.py @@ -1,9 +1,9 @@ from __future__ import annotations -from requests import Session from typing import Optional, TypedDict -from . import urls +from requests import Session + from .config import Config diff --git a/src/posit/connect/paginator.py b/src/posit/connect/paginator.py index 19014630..7fcb1959 100644 --- a/src/posit/connect/paginator.py +++ b/src/posit/connect/paginator.py @@ -3,7 +3,6 @@ import requests - # The maximum page size supported by the API. _MAX_PAGE_SIZE = 500 diff --git a/src/posit/connect/permissions.py b/src/posit/connect/permissions.py index 7914f58b..16abcdc5 100644 --- a/src/posit/connect/permissions.py +++ b/src/posit/connect/permissions.py @@ -6,8 +6,6 @@ from requests.sessions import Session as Session -from . import urls - from .config import Config from .resources import Resource, Resources diff --git a/src/posit/connect/tasks.py b/src/posit/connect/tasks.py index 63094ce0..b9f077f9 100644 --- a/src/posit/connect/tasks.py +++ b/src/posit/connect/tasks.py @@ -4,7 +4,7 @@ from typing import List, overload -from . import resources, urls +from . import resources class Task(resources.Resource): diff --git a/src/posit/connect/users.py b/src/posit/connect/users.py index 83475f1c..18bf8769 100644 --- a/src/posit/connect/users.py +++ b/src/posit/connect/users.py @@ -1,12 +1,12 @@ """User resources.""" from __future__ import annotations + from typing import List, overload import requests -from . import me, urls - +from . import me from .config import Config from .content import Content from .paginator import Paginator diff --git a/src/posit/connect/variants.py b/src/posit/connect/variants.py index 4b4e81f1..8ce896da 100644 --- a/src/posit/connect/variants.py +++ b/src/posit/connect/variants.py @@ -1,7 +1,7 @@ from typing import List + from requests import Session -from . import urls from .config import Config from .resources import Resource, Resources from .tasks import Task diff --git a/tests/posit/connect/api.py b/tests/posit/connect/api.py index c8f9567b..b71ea1ee 100644 --- a/tests/posit/connect/api.py +++ b/tests/posit/connect/api.py @@ -1,7 +1,7 @@ -import pyjson5 as json - from pathlib import Path +import pyjson5 as json + def load_mock(path: str) -> dict: """ diff --git a/tests/posit/connect/metrics/test_shiny_usage.py b/tests/posit/connect/metrics/test_shiny_usage.py index 111ec236..037bed08 100644 --- a/tests/posit/connect/metrics/test_shiny_usage.py +++ b/tests/posit/connect/metrics/test_shiny_usage.py @@ -1,9 +1,8 @@ -import responses import requests - +import responses from responses import matchers -from posit.connect import Client, config +from posit.connect import config from posit.connect.metrics import shiny_usage from ..api import load_mock # type: ignore diff --git a/tests/posit/connect/metrics/test_usage.py b/tests/posit/connect/metrics/test_usage.py index 3b5ef3c9..003762cc 100644 --- a/tests/posit/connect/metrics/test_usage.py +++ b/tests/posit/connect/metrics/test_usage.py @@ -1,12 +1,10 @@ import pytest import responses - from responses import matchers from posit import connect from posit.connect.metrics import shiny_usage, usage, visits - from ..api import load_mock # type: ignore diff --git a/tests/posit/connect/metrics/test_visits.py b/tests/posit/connect/metrics/test_visits.py index 11cf4509..a5737497 100644 --- a/tests/posit/connect/metrics/test_visits.py +++ b/tests/posit/connect/metrics/test_visits.py @@ -1,9 +1,8 @@ -import responses import requests - +import responses from responses import matchers -from posit.connect import Client, config +from posit.connect import config from posit.connect.metrics import visits from ..api import load_mock # type: ignore diff --git a/tests/posit/connect/test_bundles.py b/tests/posit/connect/test_bundles.py index 2543a596..959cfcb5 100644 --- a/tests/posit/connect/test_bundles.py +++ b/tests/posit/connect/test_bundles.py @@ -1,17 +1,16 @@ import io +from unittest import mock import pytest import requests import responses - from responses import matchers -from unittest import mock from posit.connect import Client -from posit.connect.config import Config from posit.connect.bundles import Bundle +from posit.connect.config import Config -from .api import load_mock, get_path # type: ignore +from .api import get_path, load_mock # type: ignore class TestBundleProperties: diff --git a/tests/posit/connect/test_client.py b/tests/posit/connect/test_client.py index f563d591..0709f965 100644 --- a/tests/posit/connect/test_client.py +++ b/tests/posit/connect/test_client.py @@ -1,8 +1,8 @@ +from unittest.mock import MagicMock, patch + import pytest import responses -from unittest.mock import MagicMock, patch - from posit.connect import Client from .api import load_mock # type: ignore diff --git a/tests/posit/connect/test_config.py b/tests/posit/connect/test_config.py index 37d08cb4..3f1dacf4 100644 --- a/tests/posit/connect/test_config.py +++ b/tests/posit/connect/test_config.py @@ -1,7 +1,7 @@ -import pytest - from unittest.mock import patch +import pytest + from posit.connect.config import Config, _get_api_key, _get_url diff --git a/tests/posit/connect/test_content.py b/tests/posit/connect/test_content.py index ab378574..208f9d5d 100644 --- a/tests/posit/connect/test_content.py +++ b/tests/posit/connect/test_content.py @@ -1,13 +1,12 @@ -import warnings - import pytest import requests import responses +from responses import matchers + from posit.connect.client import Client from posit.connect.config import Config from posit.connect.content import ContentItem, ContentItemOwner from posit.connect.permissions import Permissions -from responses import matchers from .api import load_mock # type: ignore diff --git a/tests/posit/connect/test_env.py b/tests/posit/connect/test_env.py index a7fc0731..df0b20a7 100644 --- a/tests/posit/connect/test_env.py +++ b/tests/posit/connect/test_env.py @@ -1,6 +1,5 @@ import pytest import responses - from responses import matchers from posit.connect import Client diff --git a/tests/posit/connect/test_groups.py b/tests/posit/connect/test_groups.py index 550f8798..067a5037 100644 --- a/tests/posit/connect/test_groups.py +++ b/tests/posit/connect/test_groups.py @@ -1,11 +1,7 @@ from unittest.mock import Mock -import pytest import requests -import responses - -from posit.connect.client import Client from posit.connect.config import Config from posit.connect.groups import Group diff --git a/tests/posit/connect/test_hooks.py b/tests/posit/connect/test_hooks.py index 9b40c76d..6945bc7a 100644 --- a/tests/posit/connect/test_hooks.py +++ b/tests/posit/connect/test_hooks.py @@ -1,10 +1,9 @@ import io +from unittest.mock import Mock, patch import pytest import responses - from requests import HTTPError, Response -from unittest.mock import Mock, patch from posit.connect import Client from posit.connect.errors import ClientError diff --git a/tests/posit/connect/test_permissions.py b/tests/posit/connect/test_permissions.py index 8ac5a42a..d158dab8 100644 --- a/tests/posit/connect/test_permissions.py +++ b/tests/posit/connect/test_permissions.py @@ -1,11 +1,8 @@ import random import uuid -from unittest.mock import Mock - import requests import responses - from responses import matchers from posit.connect.config import Config diff --git a/tests/posit/connect/test_resources.py b/tests/posit/connect/test_resources.py index fcfff3de..7a7e94fd 100644 --- a/tests/posit/connect/test_resources.py +++ b/tests/posit/connect/test_resources.py @@ -1,12 +1,8 @@ -from unittest.mock import Mock -import pytest import warnings +from typing import Optional +from unittest.mock import Mock -from typing import Any, List, Optional - -from requests.sessions import Session as Session - -from posit.connect.resources import Resource, Resources +from posit.connect.resources import Resource config = Mock() session = Mock() diff --git a/tests/posit/connect/test_tasks.py b/tests/posit/connect/test_tasks.py index a22a5e9c..48b81fa7 100644 --- a/tests/posit/connect/test_tasks.py +++ b/tests/posit/connect/test_tasks.py @@ -1,6 +1,4 @@ -import requests import responses - from responses import matchers from posit import connect diff --git a/tests/posit/connect/test_users.py b/tests/posit/connect/test_users.py index b8a8cd42..ae8a586c 100644 --- a/tests/posit/connect/test_users.py +++ b/tests/posit/connect/test_users.py @@ -3,7 +3,6 @@ import pytest import requests import responses - from responses import matchers from posit.connect.client import Client