Skip to content

Commit 75dcd7c

Browse files
committed
Address reviews
1 parent af34483 commit 75dcd7c

File tree

12 files changed

+41
-32
lines changed

12 files changed

+41
-32
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ private void generateConfig(GenerationContext context, PythonWriter writer) {
344344
// Only add config resolution imports if there are descriptor properties
345345
if (hasDescriptors) {
346346
writer.addDependency(SmithyPythonDependency.SMITHY_CORE);
347-
writer.addImport("smithy_core.config.property", "ConfigProperty");
348-
writer.addImport("smithy_core.config.resolver", "ConfigResolver");
347+
writer.addImport("smithy_aws_core.config.property", "ConfigProperty");
348+
writer.addImport("smithy_aws_core.config.resolver", "ConfigResolver");
349349
writer.addImport("smithy_aws_core.config.sources", "EnvironmentSource");
350350

351351
// Add validator and resolver imports for properties that use descriptors

packages/smithy-aws-core/src/smithy_aws_core/config/custom_resolvers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from smithy_core.config.resolver import ConfigResolver
5-
from smithy_core.config.source_info import ComplexSource
64
from smithy_core.retries import RetryStrategyOptions
75

6+
from smithy_aws_core.config.resolver import ConfigResolver
7+
from smithy_aws_core.config.source_info import ComplexSource, SourceName
88
from smithy_aws_core.config.validators import validate_max_attempts, validate_retry_mode
99

1010

@@ -24,7 +24,7 @@ def resolve_retry_strategy(
2424
are resolved. Returns (None, None) if both values are missing.
2525
2626
For mixed sources, the source name includes both component sources:
27-
"retry_mode=environment, max_attempts=config_file"
27+
{"retry_mode": "environment", "max_attempts": "default"}
2828
"""
2929

3030
retry_mode, mode_source = resolver.get("retry_mode")
@@ -48,8 +48,10 @@ def resolve_retry_strategy(
4848
# Construct mixed source string showing where each component came from
4949
source = ComplexSource(
5050
{
51-
"retry_mode": mode_source.name if mode_source else "default",
52-
"max_attempts": attempts_source.name if attempts_source else "default",
51+
"retry_mode": mode_source.name if mode_source else SourceName.DEFAULT,
52+
"max_attempts": attempts_source.name
53+
if attempts_source
54+
else SourceName.DEFAULT,
5355
}
5456
)
5557

packages/smithy-core/src/smithy_core/config/property.py renamed to packages/smithy-aws-core/src/smithy_aws_core/config/property.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from collections.abc import Callable
44
from typing import Any
55

6-
from smithy_core.config.resolver import ConfigResolver
7-
from smithy_core.config.source_info import SimpleSource, SourceInfo
6+
from smithy_aws_core.config.resolver import ConfigResolver
7+
from smithy_aws_core.config.source_info import SimpleSource, SourceInfo, SourceName
88

99

1010
class ConfigProperty:
@@ -80,7 +80,7 @@ def __get__(self, obj: Any, objtype: type | None = None) -> Any:
8080

8181
if value is None:
8282
value = self.default_value
83-
source = SimpleSource("default")
83+
source = SimpleSource(SourceName.DEFAULT)
8484

8585
if self.validator:
8686
value = self.validator(value, source)
@@ -102,9 +102,9 @@ def __set__(self, obj: Any, value: Any) -> None:
102102
# If cache already exists, it means it was not set during initialization
103103
# In that case source will be set to in-code
104104
source = (
105-
SimpleSource("in-code")
105+
SimpleSource(SourceName.IN_CODE)
106106
if hasattr(obj, self.cache_attr)
107-
else SimpleSource("instance")
107+
else SimpleSource(SourceName.INSTANCE)
108108
)
109109
if self.validator:
110110
value = self.validator(value, source)

packages/smithy-core/src/smithy_core/config/resolver.py renamed to packages/smithy-aws-core/src/smithy_aws_core/config/resolver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from collections.abc import Sequence
44
from typing import Any
55

6-
from smithy_core.config.source_info import SimpleSource
76
from smithy_core.interfaces.config import ConfigSource
87

8+
from smithy_aws_core.config.source_info import SimpleSource
9+
910

1011
class ConfigResolver:
1112
"""Resolves configuration values from multiple sources.

packages/smithy-core/src/smithy_core/config/source_info.py renamed to packages/smithy-aws-core/src/smithy_aws_core/config/source_info.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
from dataclasses import dataclass
5+
from enum import StrEnum
6+
7+
8+
class SourceName(StrEnum):
9+
"""Known source names for config value provenance tracking."""
10+
11+
INSTANCE = "instance" # value provided via Config constructor
12+
13+
IN_CODE = "in-code" # value set via setter after Config construction
14+
15+
ENVIRONMENT = "environment" # value resolved from environment variable
16+
17+
DEFAULT = "default" # value fall back to default
518

619

720
@dataclass(frozen=True)

packages/smithy-aws-core/src/smithy_aws_core/config/sources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import os
44

5+
from smithy_aws_core.config.source_info import SourceName
6+
57

68
class EnvironmentSource:
79
"""Configuration from environment variables."""
@@ -16,7 +18,7 @@ def __init__(self, prefix: str = "AWS_"):
1618
@property
1719
def name(self) -> str:
1820
"""Returns the source name."""
19-
return "environment"
21+
return SourceName.ENVIRONMENT
2022

2123
def get(self, key: str) -> str | None:
2224
"""Returns a configuration value from environment variables.

packages/smithy-aws-core/src/smithy_aws_core/config/validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import re
55
from typing import Any, get_args
66

7-
from smithy_core.config.source_info import SourceInfo
87
from smithy_core.interfaces.retries import RetryStrategy
98
from smithy_core.retries import RetryStrategyOptions, RetryStrategyType
109

10+
from smithy_aws_core.config.source_info import SourceInfo
11+
1112

1213
class ConfigValidationError(ValueError):
1314
"""Raised when a configuration value fails validation."""

packages/smithy-aws-core/tests/unit/config/test_custom_resolver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from typing import Any
55

66
from smithy_aws_core.config.custom_resolvers import resolve_retry_strategy
7-
from smithy_core.config.resolver import ConfigResolver
8-
from smithy_core.config.source_info import ComplexSource
7+
from smithy_aws_core.config.resolver import ConfigResolver
8+
from smithy_aws_core.config.source_info import ComplexSource
99
from smithy_core.retries import RetryStrategyOptions
1010

1111

packages/smithy-core/tests/unit/config/test_property.py renamed to packages/smithy-aws-core/tests/unit/config/test_property.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from typing import Any, NoReturn
66

77
import pytest
8-
from smithy_core.config.property import ConfigProperty
9-
from smithy_core.config.resolver import ConfigResolver
10-
from smithy_core.config.source_info import SimpleSource, SourceInfo
8+
from smithy_aws_core.config.property import ConfigProperty
9+
from smithy_aws_core.config.resolver import ConfigResolver
10+
from smithy_aws_core.config.source_info import SimpleSource, SourceInfo
1111
from smithy_core.retries import RetryStrategyOptions
1212

1313

packages/smithy-core/tests/unit/config/test_resolver.py renamed to packages/smithy-aws-core/tests/unit/config/test_resolver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from typing import Any
44

5-
from smithy_core.config.resolver import ConfigResolver
6-
from smithy_core.config.source_info import SimpleSource
5+
from smithy_aws_core.config.resolver import ConfigResolver
6+
from smithy_aws_core.config.source_info import SimpleSource
77

88

99
class StubSource:

0 commit comments

Comments
 (0)