Skip to content

Commit

Permalink
Merge pull request #618 from permitio/dan/per-10298-fix-relative-impo…
Browse files Browse the repository at this point in the history
…rts-and-import-conflicts-in-opal

dan/per-10298-fix-relative-imports-and-import-conflicts-in-opal
  • Loading branch information
danyi1212 authored Jul 23, 2024
2 parents 8bc8924 + 0310701 commit d42310b
Show file tree
Hide file tree
Showing 61 changed files with 96 additions and 101 deletions.
2 changes: 1 addition & 1 deletion packages/opal-client/opal_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import OpalClient
from opal_client.client import OpalClient
2 changes: 1 addition & 1 deletion packages/opal-client/opal_client/callbacks/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from opal_client.callbacks.register import CallbackConfig, CallbacksRegister
from opal_client.data.fetcher import DataFetcher
from opal_common.fetcher.providers.http_fetch_provider import HttpFetcherConfig
from opal_common.http import is_http_error_response
from opal_common.http_utils import is_http_error_response
from opal_common.logger import logger
from opal_common.schemas.data import DataUpdateReport

Expand Down
2 changes: 1 addition & 1 deletion packages/opal-client/opal_client/data/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from opal_common.async_utils import TakeANumberQueue, TasksPool, repeated_call
from opal_common.config import opal_common_config
from opal_common.fetcher.events import FetcherConfig
from opal_common.http import is_http_error_response
from opal_common.http_utils import is_http_error_response
from opal_common.schemas.data import (
DataEntryReport,
DataSourceConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/opal-client/opal_client/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .client import OpalClient
from opal_client.client import OpalClient

client = OpalClient()
# expose app for Uvicorn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from typing import Any, Dict, List, Optional

import jsonpatch
from opal_client.policy_store.base_policy_store_client import (
BasePolicyStoreClient,
JsonableValue,
)
from opal_client.utils import exclude_none_fields
from opal_common.schemas.policy import PolicyBundle
from opal_common.schemas.store import JSONPatchAction, StoreTransaction
from pydantic import BaseModel

from .base_policy_store_client import BasePolicyStoreClient, JsonableValue


class MockPolicyStoreClient(BasePolicyStoreClient):
"""A naive mock policy and policy-data store for tests."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from opal_client.policy_store.schemas import PolicyStoreAuth
from opal_client.utils import exclude_none_fields, proxy_response
from opal_common.engine.parsing import get_rego_package
from opal_common.git.bundle_utils import BundleUtils
from opal_common.git_utils.bundle_utils import BundleUtils
from opal_common.paths import PathUtils
from opal_common.schemas.policy import DataModule, PolicyBundle, RegoModule
from opal_common.schemas.store import JSONPatchAction, StoreTransaction, TransactionType
Expand Down
1 change: 0 additions & 1 deletion packages/opal-common/opal_common/authentication/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from opal_common.authentication.types import EncryptionKeyFormat, PrivateKey, PublicKey
from opal_common.logging.decorators import log_exception

logger = logging.getLogger("opal.authentication")

Expand Down
3 changes: 1 addition & 2 deletions packages/opal-common/opal_common/cli/typer_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typer

from .commands import all_commands
from opal_common.cli.commands import all_commands


def get_typer_app():
Expand Down
2 changes: 1 addition & 1 deletion packages/opal-common/opal_common/confi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .confi import *
from opal_common.confi.confi import *
3 changes: 1 addition & 2 deletions packages/opal-common/opal_common/confi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import click
import typer
from opal_common.confi.types import ConfiEntry
from typer.main import Typer

from .types import ConfiEntry


def create_click_cli(confi_entries: Dict[str, ConfiEntry], callback: Callable):
cli = callback
Expand Down
7 changes: 3 additions & 4 deletions packages/opal-common/opal_common/confi/confi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
from decouple import Csv, UndefinedValueError, config, text_type, undefined
from opal_common.authentication.casting import cast_private_key, cast_public_key
from opal_common.authentication.types import EncryptionKeyFormat, PrivateKey, PublicKey
from opal_common.logging.decorators import log_exception
from opal_common.confi.cli import get_cli_object_for_config_objects
from opal_common.confi.types import ConfiDelay, ConfiEntry, no_cast
from opal_common.logging_utils.decorators import log_exception
from pydantic import BaseModel, ValidationError
from typer import Typer

from .cli import get_cli_object_for_config_objects
from .types import ConfiDelay, ConfiEntry, no_cast


class Placeholder(object):
"""Placeholder instead of default value for decouple."""
Expand Down
3 changes: 1 addition & 2 deletions packages/opal-common/opal_common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from sys import prefix

from opal_common.authentication.types import EncryptionKeyFormat, JWTAlgorithm

from .confi import Confi, confi
from opal_common.confi import Confi, confi

_LOG_FORMAT_WITHOUT_PID = "<green>{time}</green> | <blue>{name: <40}</blue>|<level>{level:^6} | {message}</level>\n{exception}"
_LOG_FORMAT_WITH_PID = "<green>{time}</green> | {process} | <blue>{name: <40}</blue>|<level>{level:^6} | {message}</level>\n{exception}"
Expand Down
4 changes: 2 additions & 2 deletions packages/opal-common/opal_common/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .parsing import get_rego_package
from .paths import is_data_module, is_policy_module
from opal_common.engine.parsing import get_rego_package
from opal_common.engine.paths import is_data_module, is_policy_module
6 changes: 3 additions & 3 deletions packages/opal-common/opal_common/fetcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .engine.fetching_engine import FetchingEngine
from .events import FetcherConfig, FetchEvent
from .fetcher_register import FetcherRegister
from opal_common.fetcher.engine.fetching_engine import FetchingEngine
from opal_common.fetcher.events import FetcherConfig, FetchEvent
from opal_common.fetcher.fetcher_register import FetcherRegister
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Coroutine

from ..events import FetcherConfig, FetchEvent
from ..fetcher_register import FetcherRegister
from .core_callbacks import OnFetchFailureCallback
from opal_common.fetcher.engine.core_callbacks import OnFetchFailureCallback
from opal_common.fetcher.events import FetcherConfig, FetchEvent
from opal_common.fetcher.fetcher_register import FetcherRegister


class BaseFetchingEngine:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..events import FetchEvent
from opal_common.fetcher.events import FetchEvent


# Callback signatures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
from typing import Coroutine

from ..events import FetchEvent
from ..fetcher_register import FetcherRegister
from ..logger import get_logger
from .base_fetching_engine import BaseFetchingEngine
from opal_common.fetcher.engine.base_fetching_engine import BaseFetchingEngine
from opal_common.fetcher.events import FetchEvent
from opal_common.fetcher.fetcher_register import FetcherRegister
from opal_common.fetcher.logger import get_logger

logger = get_logger("fetch_worker")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import uuid
from typing import Coroutine, Dict, List, Union

from ..events import FetcherConfig, FetchEvent
from ..fetch_provider import BaseFetchProvider
from ..fetcher_register import FetcherRegister
from ..logger import get_logger
from .base_fetching_engine import BaseFetchingEngine
from .core_callbacks import OnFetchFailureCallback
from .fetch_worker import fetch_worker
from opal_common.fetcher.engine.base_fetching_engine import BaseFetchingEngine
from opal_common.fetcher.engine.core_callbacks import OnFetchFailureCallback
from opal_common.fetcher.engine.fetch_worker import fetch_worker
from opal_common.fetcher.events import FetcherConfig, FetchEvent
from opal_common.fetcher.fetch_provider import BaseFetchProvider
from opal_common.fetcher.fetcher_register import FetcherRegister
from opal_common.fetcher.logger import get_logger

logger = get_logger("engine")

Expand Down
5 changes: 2 additions & 3 deletions packages/opal-common/opal_common/fetcher/fetch_provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from opal_common.fetcher.events import FetchEvent
from opal_common.fetcher.logger import get_logger
from tenacity import retry, stop, wait

from .events import FetchEvent
from .logger import get_logger

logger = get_logger("opal.providers")


Expand Down
11 changes: 5 additions & 6 deletions packages/opal-common/opal_common/fetcher/fetcher_register.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Dict, Optional, Type

from opal_common.config import opal_common_config
from opal_common.fetcher.events import FetchEvent
from opal_common.fetcher.fetch_provider import BaseFetchProvider
from opal_common.fetcher.logger import get_logger

from ..config import opal_common_config
from .events import FetchEvent
from .fetch_provider import BaseFetchProvider
from .providers.http_fetch_provider import HttpFetchProvider
from opal_common.fetcher.providers.http_fetch_provider import HttpFetchProvider

logger = get_logger("opal.fetcher_register")

Expand All @@ -30,7 +29,7 @@ def __init__(self, config: Optional[Dict[str, BaseFetchProvider]] = None) -> Non
if config is not None:
self._config = config
else:
from ..emport import emport_objects_by_class
from opal_common.emport import emport_objects_by_class

# load fetchers
fetchers = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ...emport import dynamic_all
from opal_common.emport import dynamic_all

__all__ = dynamic_all(__file__)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from fastapi_websocket_rpc.rpc_methods import RpcMethodsBase
from fastapi_websocket_rpc.websocket_rpc_client import WebSocketRpcClient

from ..events import FetcherConfig, FetchEvent
from ..fetch_provider import BaseFetchProvider
from ..logger import get_logger
from opal_common.fetcher.events import FetcherConfig, FetchEvent
from opal_common.fetcher.fetch_provider import BaseFetchProvider
from opal_common.fetcher.logger import get_logger

logger = get_logger("rpc_fetch_provider")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import httpx
from aiohttp import ClientResponse, ClientSession
from opal_common.config import opal_common_config
from opal_common.fetcher.events import FetcherConfig, FetchEvent
from opal_common.fetcher.fetch_provider import BaseFetchProvider
from opal_common.fetcher.logger import get_logger
from opal_common.http_utils import is_http_error_response
from opal_common.security.sslcontext import get_custom_ssl_context
from pydantic import validator

from ...http import is_http_error_response
from ...security.sslcontext import get_custom_ssl_context
from ..events import FetcherConfig, FetchEvent
from ..fetch_provider import BaseFetchProvider
from ..logger import get_logger

logger = get_logger("http_fetch_provider")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from git import GitCommandError, Head, Remote, Repo
from git.objects.commit import Commit
from opal_common.git.env import provide_git_ssh_environment
from opal_common.git.exceptions import GitFailed
from opal_common.git_utils.env import provide_git_ssh_environment
from opal_common.git_utils.exceptions import GitFailed
from opal_common.logger import logger
from tenacity import retry, stop_after_attempt, wait_fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from git import Repo
from git.objects import Commit
from opal_common.engine import get_rego_package, is_data_module, is_policy_module
from opal_common.git.commit_viewer import (
from opal_common.git_utils.commit_viewer import (
CommitViewer,
VersionedDirectory,
VersionedFile,
find_ignore_match,
has_extension,
is_under_directories,
)
from opal_common.git.diff_viewer import (
from opal_common.git_utils.diff_viewer import (
DiffViewer,
diffed_file_has_extension,
diffed_file_is_under_directories,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from git import Repo
from git.diff import Diff, DiffIndex
from git.objects.commit import Commit
from opal_common.git.commit_viewer import VersionedFile
from opal_common.git_utils.commit_viewer import VersionedFile
from opal_common.paths import PathUtils

DiffFilter = Callable[[Diff], bool]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from git import GitCommandError, GitError, Repo
from opal_common.config import opal_common_config
from opal_common.git.env import provide_git_ssh_environment
from opal_common.git.exceptions import GitFailed
from opal_common.git_utils.env import provide_git_ssh_environment
from opal_common.git_utils.exceptions import GitFailed
from opal_common.logger import logger
from opal_common.utils import get_filepaths_with_glob
from tenacity import RetryError, retry, stop, wait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

from git import Repo
from git.objects.commit import Commit
from opal_common.git.branch_tracker import BranchTracker
from opal_common.git.exceptions import GitFailed
from opal_common.git_utils.branch_tracker import BranchTracker
from opal_common.git_utils.exceptions import GitFailed


def test_pull_with_no_changes(local_repo_clone: Repo):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

from git import Repo
from git.objects import Commit
from opal_common.git.bundle_maker import BundleMaker
from opal_common.git.commit_viewer import CommitViewer
from opal_common.git_utils.bundle_maker import BundleMaker
from opal_common.git_utils.commit_viewer import CommitViewer
from opal_common.schemas.policy import PolicyBundle, RegoModule

OPA_FILE_EXTENSIONS = (".rego", ".json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from git import Repo
from git.objects import Commit
from opal_common.git.commit_viewer import CommitViewer, VersionedNode
from opal_common.git_utils.commit_viewer import CommitViewer, VersionedNode


def node_paths(nodes: List[VersionedNode]) -> List[Path]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

from git import Diff, Repo
from git.objects import Commit
from opal_common.git.commit_viewer import VersionedFile
from opal_common.git.diff_viewer import DiffViewer, diffed_file_is_under_directories
from opal_common.git_utils.commit_viewer import VersionedFile
from opal_common.git_utils.diff_viewer import (
DiffViewer,
diffed_file_is_under_directories,
)


def diff_paths(diffs: List[Diff]) -> List[Path]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

from git import Repo
from opal_common.confi import Confi
from opal_common.git.exceptions import GitFailed
from opal_common.git.repo_cloner import RepoCloner
from opal_common.git_utils.exceptions import GitFailed
from opal_common.git_utils.repo_cloner import RepoCloner

VALID_REPO_REMOTE_URL_HTTPS = "https://github.com/permitio/fastapi_websocket_pubsub.git"

Expand Down
File renamed without changes.
13 changes: 6 additions & 7 deletions packages/opal-common/opal_common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import sys

from loguru import logger

from .config import opal_common_config
from .logging.filter import ModuleFilter
from .logging.formatter import Formatter
from .logging.intercept import InterceptHandler
from .logging.thirdparty import hijack_uvicorn_logs
from .monitoring.apm import fix_ddtrace_logging
from opal_common.config import opal_common_config
from opal_common.logging_utils.filter import ModuleFilter
from opal_common.logging_utils.formatter import Formatter
from opal_common.logging_utils.intercept import InterceptHandler
from opal_common.logging_utils.thirdparty import hijack_uvicorn_logs
from opal_common.monitoring.apm import fix_ddtrace_logging


def configure_logs():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import aiohttp
from fastapi import status
from fastapi.exceptions import HTTPException
from opal_common.git.tar_file_to_local_git_extractor import TarFileToLocalGitExtractor
from opal_common.git_utils.tar_file_to_local_git_extractor import (
TarFileToLocalGitExtractor,
)
from opal_common.logger import logger
from opal_common.sources.base_policy_source import BasePolicySource
from opal_common.utils import (
Expand Down
Loading

0 comments on commit d42310b

Please sign in to comment.