Skip to content

Commit 544384c

Browse files
committed
better typing
1 parent f874e3b commit 544384c

File tree

12 files changed

+196
-304
lines changed

12 files changed

+196
-304
lines changed

blocks/sport.yaml

Lines changed: 0 additions & 94 deletions
This file was deleted.

metablock/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .spaces import Block, Service, Space, SpaceExtension
66
from .user import User
77

8-
__version__ = "0.6.2"
8+
__version__ = "0.7.0"
99

1010
__all__ = [
1111
"Metablock",

metablock/cli.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import asyncio
22
import os
33
from pathlib import Path
4-
from typing import cast
54

65
import click
76
import yaml
8-
from metablock import Metablock, Space
7+
from metablock import Metablock
98

109
METABLOCK_SPACE = os.environ.get("METABLOCK_SPACE", "")
1110
METABLOCK_API_TOKEN = os.environ.get("METABLOCK_API_TOKEN", "")
@@ -16,17 +15,19 @@ def manifest(file_path: Path) -> dict:
1615

1716

1817
@click.group()
19-
def cli() -> None:
18+
def main() -> None:
2019
pass
2120

2221

23-
@cli.command()
22+
@main.command()
2423
@click.argument("path", type=click.Path(exists=True))
2524
@click.option("--space", "space_name", help="Space name", default=METABLOCK_SPACE)
2625
@click.option("--token", help="metablock API token", default=METABLOCK_API_TOKEN)
2726
def apply(path: str, space_name: str, token: str) -> None:
2827
"""Apply metablock manifest"""
29-
asyncio.get_event_loop().run_until_complete(_apply(path, space_name, token))
28+
asyncio.get_event_loop().run_until_complete(
29+
_apply(path, space_name or METABLOCK_SPACE, token or METABLOCK_API_TOKEN)
30+
)
3031

3132

3233
async def _apply(path: str, space_name: str, token: str) -> None:
@@ -42,7 +43,7 @@ async def _apply(path: str, space_name: str, token: str) -> None:
4243
name = file_path.name.split(".")[0]
4344
blocks.append((name, manifest(file_path)))
4445
async with Metablock(auth_key=token) as mb:
45-
space: Space = cast(Space, await mb.spaces.get(space_name))
46+
space = await mb.spaces.get(space_name)
4647
svc = await space.blocks.get_list()
4748
click.echo(f"space {space.name} has {len(svc)} blocks")
4849
by_name = {s["name"]: s for s in svc}
@@ -56,7 +57,3 @@ async def _apply(path: str, space_name: str, token: str) -> None:
5657
# create
5758
await space.services.create(name=name, **config)
5859
click.echo(f"created new block {name}")
59-
60-
61-
if __name__ == "__main__":
62-
cli()

metablock/client.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from yarl import URL
1010

1111
from .components import Callback, HttpComponent, MetablockResponseError
12-
from .extensions import Extensions, Plugins
13-
from .orgs import Orgs
14-
from .spaces import Blocks, Domains, Space, Spaces
12+
from .extensions import Extension, Extensions, Plugin, Plugins
13+
from .orgs import Org, Orgs
14+
from .spaces import Block, Blocks, Domains, Space, Spaces
1515
from .user import User
1616

1717
DEFAULT_USER_AGENT = f"Python/{'.'.join(map(str, sys.version_info[:2]))} metablock"
@@ -41,13 +41,13 @@ def __init__(
4141
"user-agent": user_agent,
4242
"accept": "application/json",
4343
}
44-
self.spaces: Spaces = Spaces(self)
44+
self.orgs: Orgs = Orgs(self, Org)
45+
self.spaces: Spaces = Spaces(self, Space)
46+
self.blocks: Blocks = Blocks(self, Block, "services")
47+
self.plugins: Plugins = Plugins(self, Plugin)
48+
self.extensions: Extensions = Extensions(self, Extension)
4549
self.domains = Domains(self)
46-
self.orgs: Orgs = Orgs(self)
47-
self.blocks: Blocks = Blocks(self, "services")
4850
self.services = self.blocks
49-
self.plugins: Plugins = Plugins(self)
50-
self.extensions: Extensions = Extensions(self)
5151

5252
def __repr__(self) -> str:
5353
return self.url
@@ -69,9 +69,29 @@ async def __aexit__(self, exc_type: type, exc_val: Any, exc_tb: Any) -> None:
6969
await self.close()
7070

7171
async def spec(self) -> dict:
72-
return await self.execute(f"{self.url}/spec")
72+
return await self.request(f"{self.url}/spec")
7373

74-
async def execute(
74+
async def get(self, url: str | URL, **kwargs: Any) -> Any:
75+
kwargs["method"] = "GET"
76+
return await self.request(url, **kwargs)
77+
78+
async def patch(self, url: str | URL, **kwargs: Any) -> Any:
79+
kwargs["method"] = "PATCH"
80+
return await self.request(url, **kwargs)
81+
82+
async def post(self, url: str | URL, **kwargs: Any) -> Any:
83+
kwargs["method"] = "POST"
84+
return await self.request(url, **kwargs)
85+
86+
async def put(self, url: str | URL, **kwargs: Any) -> Any:
87+
kwargs["method"] = "PUT"
88+
return await self.request(url, **kwargs)
89+
90+
async def delete(self, url: str | URL, **kwargs: Any) -> Any:
91+
kwargs["method"] = "DELETE"
92+
return await self.request(url, **kwargs)
93+
94+
async def request(
7595
self,
7696
url: str | URL,
7797
method: str = "",

0 commit comments

Comments
 (0)