Skip to content

Commit

Permalink
module: move src/karapace/core/backup to src/karapace/backup
Browse files Browse the repository at this point in the history
- the `schema_tool` runs against avro schemas at a specific path
  • Loading branch information
nosahama committed Jan 24, 2025
1 parent 4675e6a commit 05427f0
Show file tree
Hide file tree
Showing 41 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ requirements:
.PHONY: schema
schema: against := origin/main
schema:
$(PYTHON) -m karapace.core.backup.backends.v3.schema_tool --against=$(against)
$(PYTHON) -m karapace.backup.backends.v3.schema_tool --against=$(against)

.PHONY: pin-requirements
pin-requirements:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ classifiers=[

[project.scripts]
karapace = "karapace.core.karapace_all:main"
karapace_schema_backup = "karapace.core.backup.cli:main"
karapace_schema_backup = "karapace.backup.cli:main"
karapace_mkpasswd = "karapace.core.auth:main"

[project.urls]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
from enum import Enum
from functools import partial
from karapace.core import constants
from karapace.core.backup.backends.v1 import SchemaBackupV1Reader
from karapace.core.backup.backends.v2 import AnonymizeAvroWriter, SchemaBackupV2Reader, SchemaBackupV2Writer, V2_MARKER
from karapace.core.backup.backends.v3.backend import SchemaBackupV3Reader, SchemaBackupV3Writer, VerifyFailure, VerifySuccess
from karapace.backup.backends.v1 import SchemaBackupV1Reader
from karapace.backup.backends.v2 import AnonymizeAvroWriter, SchemaBackupV2Reader, SchemaBackupV2Writer, V2_MARKER
from karapace.backup.backends.v3.backend import SchemaBackupV3Reader, SchemaBackupV3Writer, VerifyFailure, VerifySuccess
from karapace.core.config import Config
from karapace.core.kafka.admin import KafkaAdminClient
from karapace.core.kafka.common import translate_from_kafkaerror
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from collections.abc import Generator
from karapace.core.backup.backends.reader import BaseItemsBackupReader
from karapace.backup.backends.reader import BaseItemsBackupReader
from karapace.core.utils import json_decode
from typing import IO

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

from collections.abc import Generator, Sequence
from karapace.core.anonymize_schemas import anonymize_avro
from karapace.core.backup.backends.reader import BaseItemsBackupReader
from karapace.core.backup.backends.writer import BaseKVBackupWriter, StdOut
from karapace.backup.backends.reader import BaseItemsBackupReader
from karapace.backup.backends.writer import BaseKVBackupWriter, StdOut
from karapace.core.utils import json_decode, json_encode
from pathlib import Path
from typing import Any, ClassVar, Final, IO
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from collections.abc import Callable, Generator, Iterator, Mapping, Sequence
from confluent_kafka import Message
from dataclasses import dataclass
from karapace.core.backup.backends.reader import BaseBackupReader, Instruction, ProducerSend, RestoreTopic
from karapace.core.backup.backends.writer import BytesBackupWriter, StdOut
from karapace.core.backup.safe_writer import bytes_writer, staging_directory
from karapace.backup.backends.reader import BaseBackupReader, Instruction, ProducerSend, RestoreTopic
from karapace.backup.backends.writer import BytesBackupWriter, StdOut
from karapace.backup.safe_writer import bytes_writer, staging_directory
from karapace.core.dataclasses import default_dataclass
from karapace.core.utils import assert_never
from karapace.version import __version__
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
See LICENSE for details
"""

from karapace.core.backup.errors import BackupError
from karapace.backup.errors import BackupError


class DecodeError(BackupError):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from collections.abc import Iterator, Mapping, Sequence
from confluent_kafka import Message
from karapace.core.backup.safe_writer import bytes_writer, str_writer
from karapace.backup.safe_writer import bytes_writer, str_writer
from pathlib import Path
from typing import ContextManager, Generic, IO, Literal, TypeAlias, TypeVar

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .poll_timeout import PollTimeout
from aiokafka.errors import BrokerResponseError
from collections.abc import Iterator
from karapace.core.backup.api import VerifyLevel
from karapace.backup.api import VerifyLevel
from karapace.core.config import Config
from pydantic_settings import BaseSettings, JsonConfigSettingsSource, PydanticBaseSettingsSource
from typing import Type
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from confluent_kafka import TopicPartition
from karapace.core.backup.poll_timeout import PollTimeout
from karapace.backup.poll_timeout import PollTimeout

__all__ = ["BackupError", "BackupTopicAlreadyExists", "EmptyPartition", "PartitionCountError", "StaleConsumerError"]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/integration/backup/test_avro_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
See LICENSE for details
"""

from karapace.core.backup import api
from karapace.core.backup.api import BackupVersion
from karapace.backup import api
from karapace.backup.api import BackupVersion
from karapace.core.client import Client
from karapace.core.config import Config
from karapace.core.utils import json_encode
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/backup/test_get_topic_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from confluent_kafka.admin import NewTopic
from karapace.core.backup.topic_configurations import (
from karapace.backup.topic_configurations import (
ALL_CONFIG_SOURCES,
ConfigSource,
DEFAULT_CONFIGS,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/backup/test_legacy_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""

from aiokafka.errors import InvalidTopicError
from karapace.core.backup import api
from karapace.core.backup.api import BackupVersion
from karapace.core.backup.errors import StaleConsumerError
from karapace.core.backup.poll_timeout import PollTimeout
from karapace.backup import api
from karapace.backup.api import BackupVersion
from karapace.backup.errors import StaleConsumerError
from karapace.backup.poll_timeout import PollTimeout
from karapace.core.client import Client
from karapace.core.config import Config
from karapace.core.kafka.admin import KafkaAdminClient
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/backup/test_session_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from aiokafka.errors import NoBrokersAvailable
from confluent_kafka.admin import NewTopic
from karapace.core.backup.api import BackupVersion, create_backup
from karapace.backup.api import BackupVersion, create_backup
from karapace.core.config import Config
from karapace.core.kafka.admin import KafkaAdminClient
from karapace.core.kafka_utils import kafka_producer_from_config
Expand Down
24 changes: 12 additions & 12 deletions tests/integration/backup/test_v3_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from confluent_kafka import Message, TopicPartition
from confluent_kafka.admin import NewTopic
from dataclasses import fields
from karapace.core.backup import api
from karapace.core.backup.api import _consume_records, BackupVersion, TopicName
from karapace.core.backup.backends.v3.errors import InconsistentOffset
from karapace.core.backup.backends.v3.readers import read_metadata
from karapace.core.backup.backends.v3.schema import Metadata
from karapace.core.backup.errors import BackupDataRestorationError, EmptyPartition
from karapace.core.backup.poll_timeout import PollTimeout
from karapace.core.backup.topic_configurations import ConfigSource, get_topic_configurations
from karapace.backup import api
from karapace.backup.api import _consume_records, BackupVersion, TopicName
from karapace.backup.backends.v3.errors import InconsistentOffset
from karapace.backup.backends.v3.readers import read_metadata
from karapace.backup.backends.v3.schema import Metadata
from karapace.backup.errors import BackupDataRestorationError, EmptyPartition
from karapace.backup.poll_timeout import PollTimeout
from karapace.backup.topic_configurations import ConfigSource, get_topic_configurations
from karapace.core.config import Config
from karapace.core.kafka.admin import KafkaAdminClient
from karapace.core.kafka.consumer import KafkaConsumer
Expand Down Expand Up @@ -573,7 +573,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self._producer.flush()

with patch("karapace.core.backup.api._producer") as p:
with patch("karapace.backup.api._producer") as p:
p.return_value = LowTimeoutProducer()
with pytest.raises(BackupDataRestorationError) as excinfo:
api.restore_backup(
Expand Down Expand Up @@ -622,7 +622,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self._producer.flush()

with patch("karapace.core.backup.api._producer") as p:
with patch("karapace.backup.api._producer") as p:
p.return_value = FailToSendProducerContext()
with pytest.raises(BackupDataRestorationError):
api.restore_backup(
Expand Down Expand Up @@ -672,7 +672,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self._producer.flush()

with patch("karapace.core.backup.api._producer") as p:
with patch("karapace.backup.api._producer") as p:
p.return_value = FailToSendProducerContext()
with pytest.raises(BackupDataRestorationError, match="Kafka producer buffer is full"):
api.restore_backup(
Expand Down Expand Up @@ -1202,7 +1202,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self._consumer.close()

with patch("karapace.core.backup.api._consumer") as consumer_patch:
with patch("karapace.backup.api._consumer") as consumer_patch:
consumer_patch.return_value = ConsumerContext()
try:
api.create_backup(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/backup/backends/test_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"""

from functools import partial
from karapace.core.backup.backends.reader import ProducerSend, RestoreTopicLegacy
from karapace.core.backup.backends.v1 import SchemaBackupV1Reader
from karapace.core.backup.encoders import encode_key, encode_value
from karapace.backup.backends.reader import ProducerSend, RestoreTopicLegacy
from karapace.backup.backends.v1 import SchemaBackupV1Reader
from karapace.backup.encoders import encode_key, encode_value
from karapace.core.key_format import KeyFormatter
from pathlib import Path

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/backup/backends/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from __future__ import annotations

from functools import partial
from karapace.core.backup.backends.reader import ProducerSend, RestoreTopicLegacy
from karapace.core.backup.backends.v2 import AnonymizeAvroWriter, SchemaBackupV2Reader, SchemaBackupV2Writer
from karapace.core.backup.encoders import encode_key, encode_value
from karapace.backup.backends.reader import ProducerSend, RestoreTopicLegacy
from karapace.backup.backends.v2 import AnonymizeAvroWriter, SchemaBackupV2Reader, SchemaBackupV2Writer
from karapace.backup.encoders import encode_key, encode_value
from karapace.core.kafka.types import Timestamp
from karapace.core.key_format import KeyFormatter
from pathlib import Path
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/backup/backends/v3/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"""

from dataclasses import replace
from karapace.core.backup.backends.reader import ProducerSend, RestoreTopic
from karapace.core.backup.backends.v3.backend import _PartitionStats, SchemaBackupV3Reader, SchemaBackupV3Writer
from karapace.core.backup.backends.v3.errors import (
from karapace.backup.backends.reader import ProducerSend, RestoreTopic
from karapace.backup.backends.v3.backend import _PartitionStats, SchemaBackupV3Reader, SchemaBackupV3Writer
from karapace.backup.backends.v3.errors import (
InconsistentOffset,
InvalidChecksum,
OffsetMismatch,
TooFewRecords,
TooManyRecords,
UnknownChecksumAlgorithm,
)
from karapace.core.backup.backends.v3.readers import read_records
from karapace.core.backup.backends.v3.schema import ChecksumAlgorithm, DataFile
from karapace.backup.backends.v3.readers import read_records
from karapace.backup.backends.v3.schema import ChecksumAlgorithm, DataFile
from karapace.core.kafka.types import Timestamp
from pathlib import Path
from tests.utils import StubMessage
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/backup/backends/v3/test_serialisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

from hypothesis import given
from hypothesis.strategies import integers
from karapace.core.backup.backends.v3.errors import (
from karapace.backup.backends.v3.errors import (
IntegerAboveBound,
IntegerBelowBound,
InvalidChecksum,
InvalidHeader,
TooFewRecords,
TooManyRecords,
)
from karapace.core.backup.backends.v3.readers import read_metadata, read_record, read_records, read_uint32, read_uint64
from karapace.core.backup.backends.v3.schema import DataFile, Header, Metadata, Record
from karapace.core.backup.backends.v3.writers import (
from karapace.backup.backends.v3.readers import read_metadata, read_record, read_records, read_uint32, read_uint64
from karapace.backup.backends.v3.schema import DataFile, Header, Metadata, Record
from karapace.backup.backends.v3.writers import (
UINT32_RANGE,
UINT64_RANGE,
write_metadata,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/backup/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from aiokafka.errors import KafkaError, TopicAlreadyExistsError
from collections.abc import Callable
from karapace.core.backup.api import (
from karapace.backup.api import (
_admin,
_consumer,
_handle_restore_topic,
Expand All @@ -18,9 +18,9 @@
normalize_location,
normalize_topic_name,
)
from karapace.core.backup.backends.reader import RestoreTopic, RestoreTopicLegacy
from karapace.core.backup.backends.writer import StdOut
from karapace.core.backup.errors import BackupError, PartitionCountError
from karapace.backup.backends.reader import RestoreTopic, RestoreTopicLegacy
from karapace.backup.backends.writer import StdOut
from karapace.backup.errors import BackupError, PartitionCountError
from karapace.core.config import Config
from karapace.core.constants import DEFAULT_SCHEMA_TOPIC
from karapace.core.container import KarapaceContainer
Expand All @@ -35,7 +35,7 @@
import pytest

patch_admin_new = mock.patch(
"karapace.core.backup.api.KafkaAdminClient.__new__",
"karapace.backup.api.KafkaAdminClient.__new__",
autospec=True,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/backup/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

from karapace.core.backup.encoders import encode_key, encode_value
from karapace.backup.encoders import encode_key, encode_value
from karapace.core.key_format import KeyFormatter
from unittest import mock

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/backup/test_poll_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from datetime import timedelta
from karapace.core.backup.poll_timeout import PollTimeout
from karapace.backup.poll_timeout import PollTimeout

import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/backup/test_safe_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
See LICENSE for details
"""

from karapace.core.backup.safe_writer import (
from karapace.backup.safe_writer import (
_check_destination_file,
bytes_writer,
OverwriteRefused,
Expand Down

0 comments on commit 05427f0

Please sign in to comment.