Skip to content

Commit bf96b02

Browse files
authored
Move to flat layout (#3)
1 parent 47e0b43 commit bf96b02

File tree

13 files changed

+63
-56
lines changed

13 files changed

+63
-56
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- name: Install project
3232
run: |
33-
uv sync
33+
make install-dev
3434
3535
- name: Install LocalStack
3636
run: |

Makefile

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,28 @@ TEST_EXEC ?= python -m
88
PYTEST_LOGLEVEL ?= warning
99
PIP_CMD ?= pip
1010

11-
venv: $(VENV_ACTIVATE) ## Create a new (empty) virtual environment
11+
install: ## omit dev dependencies
12+
uv sync --no-dev
1213

13-
$(VENV_ACTIVATE): src
14-
test -d $(VENV_DIR) || $(VENV_BIN) $(VENV_DIR)
15-
$(VENV_RUN); $(PIP_CMD) install --upgrade pip
16-
touch $(VENV_ACTIVATE)
17-
18-
install: venv #
19-
$(VENV_RUN); $(PIP_CMD) install -r ./localstack-sdk-generated/requirements.txt
20-
$(VENV_RUN); pip install -e ./localstack-sdk-generated
21-
$(VENV_RUN); pip install -e ./localstack-sdk-python
22-
23-
install-dev: install
24-
$(VENV_RUN); pip install -e ./localstack-sdk-python[test]
14+
install-dev: ## create the venv and install
15+
uv sync
2516

2617
build-spec: ## build the entire localstack api spec (openapi.yaml in the root folder)
2718
$(VENV_RUN); python scripts/create_spec.py
2819

29-
clean: ## Clean up
20+
clean: ## Clean up the virtual environment
3021
rm -rf $(VENV_DIR)
3122

3223
clean-generated: ## Cleanup generated code
3324
rm -rf packages/localstack-sdk-generated/localstack/
3425

35-
format: ## Run ruff to format the whole codebase
36-
($(VENV_RUN); python -m ruff format .; python -m ruff check --output-format=full --exclude packages --fix .)
26+
format:
27+
($(VENV_RUN); python -m ruff format --exclude packages .; python -m ruff check --output-format=full --exclude packages --fix .)
3728

3829
lint:
39-
($(VENV_RUN); python -m ruff check --exclude localstack-sdk/localstack/generated --output-format=full . && python -m ruff format --exclude packages --check .)
30+
($(VENV_RUN); python -m ruff check --exclude packages --output-format=full . && python -m ruff format --exclude packages --check .)
4031

4132
test: ## Run automated tests
4233
($(VENV_RUN); $(TEST_EXEC) pytest --durations=10 --log-cli-level=$(PYTEST_LOGLEVEL) $(PYTEST_ARGS) $(TEST_PATH))
4334

44-
.PHONY: venv clean
35+
.PHONY: clean install install-dev

src/localstack/clients.py renamed to localstack-sdk-python/localstack/clients.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class BaseClient:
88
"""A BaseClient creates a configuration and instantiate a ApiClient"""
9+
910
configuration: Configuration
1011
_api_client: ApiClient
1112
auth_token: str | None
@@ -14,4 +15,4 @@ def __init__(self, host: str | None = None, auth_token: str | None = None, **kwa
1415
_host = host or "http://localhost.localstack.cloud:4566"
1516
self.auth_token = auth_token or os.getenv("LOCALSTACK_AUTH_TOKEN", "").strip("'\" ")
1617
self.configuration = Configuration(host=_host)
17-
self._api_client = ApiClient(configuration=self.configuration)
18+
self._api_client = ApiClient(configuration=self.configuration)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
from localstack.sdk.chaos.client import ChaosClient
22

3-
__all__ = [
4-
"ChaosClient"
5-
]
3+
__all__ = ["ChaosClient"]

src/localstack/sdk/chaos/client.py renamed to localstack-sdk-python/localstack/sdk/chaos/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ def get_network_effects(self) -> NetworkEffectsConfig:
3131
def set_network_effects(
3232
self, network_effects_config: NetworkEffectsConfig
3333
) -> NetworkEffectsConfig:
34-
return self._client.set_network_effects_0(
35-
network_effects_config=network_effects_config
36-
)
34+
return self._client.set_network_effects_0(network_effects_config=network_effects_config)
3735

3836

3937
def get_default(**args) -> ChaosClient:
4038
"""Return a default chaos client with a default configuration"""
41-
return ChaosClient(**args)
39+
return ChaosClient(**args)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
from localstack.sdk.pods.client import PodsClient
22

3-
__all__ = [
4-
"PodsClient"
5-
]
3+
__all__ = ["PodsClient"]

src/localstack/sdk/pods/client.py renamed to localstack-sdk-python/localstack/sdk/pods/client.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
import base64
22
import json
33

4-
from localstack.sdk.api import PodsApi
54
from localstack.clients import BaseClient
6-
from localstack.sdk.models import RemoteConfig, PodSaveRequest
5+
from localstack.sdk.api import PodsApi
6+
from localstack.sdk.models import PodSaveRequest, RemoteConfig
77

88

99
def _empty_remote_config() -> RemoteConfig:
10-
return RemoteConfig(
11-
oneof_schema_1_validator={},
12-
actual_instance={}
13-
)
10+
return RemoteConfig(oneof_schema_1_validator={}, actual_instance={})
1411

1512

1613
def _read_ndjson(raw_content: bytes) -> list[dict]:
17-
ndjson_str = raw_content.decode('utf-8')
14+
ndjson_str = raw_content.decode("utf-8")
1815
return [json.loads(line) for line in ndjson_str.splitlines()]
1916

2017

2118
def _get_completion_event(streamed_response: list[dict]) -> dict | None:
22-
completion_events = [
23-
line for line in streamed_response if line.get("event") == "completion"
24-
]
19+
completion_events = [line for line in streamed_response if line.get("event") == "completion"]
2520
return completion_events[0] if completion_events else None
2621

27-
class PodsClient(BaseClient):
2822

23+
class PodsClient(BaseClient):
2924
def __init__(self, **args) -> None:
3025
super().__init__(**args)
3126
self._client = PodsApi(self._api_client)
@@ -39,9 +34,11 @@ def save_pod(self, pod_name: str) -> None:
3934
:raise exception if the save does not succeed
4035
"""
4136
try:
42-
response = self._client.save_pod_0_with_http_info(name=pod_name, pod_save_request=PodSaveRequest())
37+
response = self._client.save_pod_0_with_http_info(
38+
name=pod_name, pod_save_request=PodSaveRequest()
39+
)
4340
except Exception as e:
44-
raise(e)
41+
raise (e)
4542
if response.status_code != 200:
4643
pass
4744
streamed_response = _read_ndjson(response.raw_data)
@@ -54,7 +51,9 @@ def load_pod(self, pod_name: str) -> None:
5451
"""
5552
:raise exception if the load does not succeed
5653
"""
57-
response = self._client.load_pod_0_with_http_info(name=pod_name, remote_config=_empty_remote_config())
54+
response = self._client.load_pod_0_with_http_info(
55+
name=pod_name, remote_config=_empty_remote_config()
56+
)
5857
if response.status_code != 200:
5958
pass
6059
streamed_response = _read_ndjson(response.raw_data)
@@ -74,6 +73,5 @@ def list_pods(self):
7473

7574
def get_platform_auth_header(token: str) -> dict[str, str]:
7675
_token = f":{token}"
77-
auth_encoded = base64.b64encode(_token.encode('utf-8')).decode('utf-8')
76+
auth_encoded = base64.b64encode(_token.encode("utf-8")).decode("utf-8")
7877
return {"Authorization": f"Basic {auth_encoded}"}
79-

pyproject.toml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,46 @@ members = ["packages/*"]
2929
[tool.setuptools]
3030
include-package-data = false
3131

32+
package-dir = { "" = "localstack-sdk-python"}
33+
3234
[tool.setuptools.packages.find]
33-
where = ["src"]
34-
include = ["*"]
35+
where = ["localstack-sdk-python/"]
36+
include = ["localstack*"]
3537
exclude = ["tests*"]
3638

3739
[tool.ruff]
38-
# Extend the ruff config in the root dir
39-
extend = "../ruff.toml"
4040
# Always generate Python 3.8-compatible code.
4141
target-version = "py38"
4242
line-length = 100
43-
src = ["tests", "localstack"]
43+
src = ["localstack-sdk-python", "tests"]
4444
exclude = [
4545
".venv*",
4646
"venv*",
4747
"dist",
4848
"build",
4949
"target",
5050
"*.egg-info",
51+
"localstack-sdk-python/*.egg-info",
5152
".git",
52-
]
53+
]
54+
55+
[tool.ruff.lint]
56+
ignore = [
57+
"B007", # TODO Loop control variable x not used within loop body
58+
"B017", # TODO `pytest.raises(Exception)` should be considered evil
59+
"B019", # TODO Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
60+
"B022", # TODO No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant
61+
"B023", # TODO Function definition does not bind loop variable `server`
62+
"B024", # TODO x is an abstract base class, but it has no abstract methods
63+
"B027", # TODO `Server.do_shutdown` is an empty method in an abstract base class, but has no abstract decorator
64+
"B904", # TODO Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
65+
"C408", # TODO Unnecessary `list` call (rewrite as a literal)
66+
"C416", # TODO Unnecessary `set` comprehension
67+
"C901", # TODO function is too complex
68+
"E402", # TODO Module level import not at top of file
69+
"E501", # E501 Line too long - handled by black, see https://docs.astral.sh/ruff/faq/#is-ruff-compatible-with-black
70+
"E721", # TODO Do not compare types, use `isinstance()`
71+
"T201", # TODO `print` found
72+
"T203", # TODO `pprint` found
73+
]
74+
select = ["B", "C", "E", "F", "I", "W", "T", "B9", "G"]

scripts/create_spec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
import yaml
7+
78
from localstack.utils.openapi import get_localstack_openapi_spec
89

910
openapi_path = Path(os.path.dirname(__file__)) / ".." / "openapi.yaml"

0 commit comments

Comments
 (0)