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: make python version consistent, prep for release of Windows SDKS #448

Merged
merged 4 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The FFI-based SDKs are currently supported on the following OSes/architectures:
- Linux arm64
- MacOS x86_64
- MacOS arm64
- Windows x86_64

### WASM

Expand Down
3 changes: 2 additions & 1 deletion flipt-client-dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ This SDK currently supports the following OSes/architectures:
- Linux arm64
- MacOS x86_64
- MacOS arm64
- Windows x86_64

> [!IMPORTANT]
> This SDK currently only supports desktop platforms (MacOS and Linux).
> This SDK currently only supports desktop platforms (MacOS, Linux, Windows).
> We are working on adding support for mobile platforms such as iOS and Android.

## Usage
Expand Down
4 changes: 2 additions & 2 deletions flipt-client-go/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func NewEvaluationClient(opts ...clientOption) (*EvaluationClient, error) {
opt(client)
}

engOpts := &EngineOpts[any]{
clientOpts := &clientOptions[any]{
URL: client.url,
UpdateInterval: client.updateInterval,
Authentication: &client.authentication,
Reference: client.ref,
}

b, err := json.Marshal(engOpts)
b, err := json.Marshal(clientOpts)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-go/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type jwtAuthentication struct {
Token string `json:"jwt_token"`
}

type EngineOpts[T any] struct {
type clientOptions[T any] struct {
URL string `json:"url,omitempty"`
Authentication *T `json:"authentication,omitempty"`
UpdateInterval int `json:"update_interval,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions flipt-client-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This SDK currently supports the following OSes/architectures:
- Linux arm64 (musl)
- MacOS x86_64
- MacOS arm64
- Windows x86_64

### Glibc vs Musl

Expand Down
2 changes: 1 addition & 1 deletion flipt-client-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = 'io.flipt'
version = '0.10.0-rc.1'
version = '0.10.0'
description = 'Flipt Client SDK'

java {
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-java/build.musl.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = 'io.flipt'
version = '0.2.0-rc.1'
version = '0.2.0'
description = 'Flipt Client SDK'

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FliptEvaluationClient {
private final ObjectMapper objectMapper;

public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary) Native.load("fliptengine", CLibrary.class);
CLibrary INSTANCE = Native.load("fliptengine", CLibrary.class);

Pointer initialize_engine(String namespace, String opts);

Expand All @@ -38,20 +38,20 @@ public interface CLibrary extends Library {
void destroy_string(Pointer str);
}

private FliptEvaluationClient(String namespace, EngineOpts engineOpts)
private FliptEvaluationClient(String namespace, ClientOptions clientOpts)
throws EvaluationException {

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new Jdk8Module());

String engineOptions;
String clientOptionsSerialized;
try {
engineOptions = objectMapper.writeValueAsString(engineOpts);
clientOptionsSerialized = objectMapper.writeValueAsString(clientOpts);
} catch (JsonProcessingException e) {
throw new EvaluationException(e);
}

Pointer engine = CLibrary.INSTANCE.initialize_engine(namespace, engineOptions);
Pointer engine = CLibrary.INSTANCE.initialize_engine(namespace, clientOptionsSerialized);

this.objectMapper = objectMapper;
this.engine = engine;
Expand Down Expand Up @@ -98,7 +98,7 @@ public FliptEvaluationClientBuilder reference(String reference) {
public FliptEvaluationClient build() throws EvaluationException {
return new FliptEvaluationClient(
namespace,
new EngineOpts(
new ClientOptions(
Optional.of(url),
Optional.ofNullable(updateInterval),
Optional.ofNullable(authentication),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import java.util.Optional;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class EngineOpts {
public class ClientOptions {
private final Optional<String> url;
private final Optional<Long> updateInterval;
private final Optional<AuthenticationStrategy> authentication;
private final Optional<String> reference;

public EngineOpts(
public ClientOptions(
Optional<String> url,
Optional<Duration> updateInterval,
Optional<AuthenticationStrategy> authentication,
Expand Down
1 change: 1 addition & 0 deletions flipt-client-python/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.3
1 change: 1 addition & 0 deletions flipt-client-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This SDK currently supports the following OSes/architectures:
- Linux arm64
- MacOS x86_64
- MacOS arm64
- Windows x86_64

## Usage

Expand Down
48 changes: 34 additions & 14 deletions flipt-client-python/flipt_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import platform

from .models import (
BatchEvaluationResponse,
BatchResult,
BooleanEvaluationResponse,
BooleanResult,
EngineOpts,
ClientOptions,
EvaluationRequest,
FlagList,
ListFlagsResult,
VariantEvaluationResponse,
VariantResult,
)

Expand All @@ -24,7 +28,7 @@ class InternalEvaluationRequest(BaseModel):

class FliptEvaluationClient:
def __init__(
self, namespace: str = "default", engine_opts: EngineOpts = EngineOpts()
self, namespace: str = "default", opts: ClientOptions = ClientOptions()
):
# Mapping of platform-architecture combinations to their respective library file paths
lib_files = {
Expand Down Expand Up @@ -80,19 +84,17 @@ def __init__(

ns = namespace.encode("utf-8")

engine_opts_serialized = engine_opts.model_dump_json(exclude_none=True).encode(
"utf-8"
)
client_opts_serialized = opts.model_dump_json(exclude_none=True).encode("utf-8")

self.engine = self.ffi_core.initialize_engine(ns, engine_opts_serialized)
self.engine = self.ffi_core.initialize_engine(ns, client_opts_serialized)

def __del__(self):
if hasattr(self, "engine") and self.engine is not None:
self.ffi_core.destroy_engine(self.engine)

def evaluate_variant(
self, flag_key: str, entity_id: str, context: dict = {}
) -> VariantResult:
) -> VariantEvaluationResponse:
response = self.ffi_core.evaluate_variant(
self.engine,
serialize_evaluation_request(
Expand All @@ -103,11 +105,15 @@ def evaluate_variant(
bytes_returned = ctypes.cast(response, ctypes.c_char_p).value
variant_result = VariantResult.model_validate_json(bytes_returned)
self.ffi_core.destroy_string(response)
return variant_result

if variant_result.status != "success":
raise Exception(variant_result.error_message)

return variant_result.result

def evaluate_boolean(
self, flag_key: str, entity_id: str, context: dict = {}
) -> BooleanResult:
) -> BooleanEvaluationResponse:
response = self.ffi_core.evaluate_boolean(
self.engine,
serialize_evaluation_request(
Expand All @@ -118,9 +124,15 @@ def evaluate_boolean(
bytes_returned = ctypes.cast(response, ctypes.c_char_p).value
boolean_result = BooleanResult.model_validate_json(bytes_returned)
self.ffi_core.destroy_string(response)
return boolean_result

def evaluate_batch(self, requests: List[EvaluationRequest]) -> BatchResult:
if boolean_result.status != "success":
raise Exception(boolean_result.error_message)

return boolean_result.result

def evaluate_batch(
self, requests: List[EvaluationRequest]
) -> BatchEvaluationResponse:
evaluation_requests = []

for r in requests:
Expand All @@ -146,15 +158,23 @@ def evaluate_batch(self, requests: List[EvaluationRequest]) -> BatchResult:
bytes_returned = ctypes.cast(response, ctypes.c_char_p).value
batch_result = BatchResult.model_validate_json(bytes_returned)
self.ffi_core.destroy_string(response)
return batch_result

def list_flags(self) -> ListFlagsResult:
if batch_result.status != "success":
raise Exception(batch_result.error_message)

return batch_result.result

def list_flags(self) -> FlagList:
response = self.ffi_core.list_flags(self.engine)

bytes_returned = ctypes.cast(response, ctypes.c_char_p).value
result = ListFlagsResult.model_validate_json(bytes_returned)
self.ffi_core.destroy_string(response)
return result

if result.status != "success":
raise Exception(result.error_message)

return result.result


def serialize_evaluation_request(
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-python/flipt_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JWTAuthentication(AuthenticationStrategy):
jwt_token: str


class EngineOpts(BaseModel):
class ClientOptions(BaseModel):
url: Optional[str] = None
update_interval: Optional[int] = None
authentication: Optional[AuthenticationStrategy] = None
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
include = [{ path = "ext/**/*" }, { path = "README.md" }]
name = "flipt-client"
version = "0.10.0"
version = "0.11.0"
description = "Flipt Client Evaluation SDK"
authors = ["Flipt Devs <[email protected]>"]
readme = "README.md"
Expand Down
Loading
Loading