Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
Update dependencies + docs fixes (#38)
Browse files Browse the repository at this point in the history
* Update with features

* Add support for positional arguments;
* Move to nox;
* Update driver;
* Fix tests for new EdgeDB's alpha release;
* Fix docs;
  • Loading branch information
nsidnev authored Aug 11, 2020
1 parent 8faa2bd commit ee1d8a7
Show file tree
Hide file tree
Showing 38 changed files with 964 additions and 669 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/deploy-on-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
poetry install
- name: Build MkDocs for GitHub Pages
run: |
source .venv/bin/activate
./scripts/docs.py build
poetry run nox -s docs-build
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/deploy-on-netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
poetry install
- name: Build MkDocs for Netlify
run: |
source .venv/bin/activate
./scripts/docs.py build
poetry run nox -s docs-build
- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ jobs:
poetry install
- name: Run linters
run: |
source .venv/bin/activate
./scripts/lint
poetry run nox -s lint
14 changes: 8 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
python-version: [3.7, 3.8]
services:
edgedb:
image: edgedb/edgedb:latest
image: edgedb/edgedb:1-alpha4
ports:
- 5656:5656
steps:
Expand All @@ -25,13 +25,15 @@ jobs:
pip install poetry==1.0
poetry config virtualenvs.in-project true
poetry install
- name: Install EdgeDB CLI
run: |
mkdir -p ~/.local/bin/
curl https://packages.edgedb.com/dist/linux-x86_64/edgedb-cli_latest > ~/.local/bin/edgedb
chmod +x ~/.local/bin/edgedb
- name: Run tests
env:
EDGEDB_DSN: edgedb://edgedb@localhost/edgedb
run: |
# sleep for 1 minute for EdgeDB bootstraping.
# TODO: remove after release cli with --wait-until-available
sleep 60
source .venv/bin/activate
./scripts/test --cov-report=xml
export PATH="$HOME/.local/bin:$PATH"
poetry run nox -s test
- uses: codecov/[email protected]
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Add support for positional arguments.
* Move to `nox` from scripts.
* Add `py.typed` file for providing types information for type checkers.
* Update `edgedb-python` to `0.9.0`.
* Update CI to use new EdgeDB alpha release.
* Check support for pools.
* Fix typos and examples in docs.

## [0.0.1] - 2020-04-09

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

services:
edgedb:
image: edgedb/edgedb:1-alpha4
ports:
- 5656:5656
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can install `edgeql-queries` using `pip`:
{!./src/index/install_using_pip.sh!}
```

Or if you are use `poetry`:
Or if you are using `poetry`:
```bash
{!./src/index/install_using_poetry.sh!}
```
Expand Down
12 changes: 7 additions & 5 deletions docs/queries-definition/queries-definition-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ An EdgeQL query that can be parsed using `edgeql-queries` has some limitations:
these queries are executed:
* `*`: query will be executed as a script using the `.execute` method from the driver.
* `!`: query will always return a single object, and therefore such query will be
executed using the `.fetchone` method from the driver.
executed using the `.query_one` method from the driver.
* empty: a regular query that returns a set of objects and will be executed by the
`.fetchall` method from the driver.
`.query` method from the driver.


## Names

The query name must be a valid Python identifier, but it can contain a `-` character,
which will be converted to `_`. An example of valid query names:

*
* Example 1:
```edgeql
{!./src/queries-definition/right-names/right_name0.edgeql!}
```
*

* Example 2:
```edgeql
{!./src/queries-definition/right-names/right_name1.edgeql!}
```
*

* Example 3:
```edgeql
{!./src/queries-definition/right-names/right_name2.edgeql!}
```
6 changes: 3 additions & 3 deletions docs/src/grouping-queries/grouping_queries0.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import edgedb
from edgeql_queries import from_path
import edgeql_queries

# or from_path('./edgeql', async_driver=False) for directory
queries = from_path("./queries.edgeql", async_driver=False)
# or edgeql_queries.from_path('./edgeql', async_driver=False) for directory
queries = edgeql_queries.from_path("./queries.edgeql", async_driver=False)

conn = edgedb.connect("edgedb://edgedb@localhost/edgedb")

Expand Down
4 changes: 2 additions & 2 deletions docs/src/grouping-queries/grouping_queries1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import edgedb
from edgeql_queries import from_path
import edgeql_queries

queries = from_path("./edgeql", async_driver=False)
queries = edgeql_queries.from_path("./edgeql", async_driver=False)

conn = edgedb.connect("edgedb://edgedb@localhost/edgedb")

Expand Down
24 changes: 9 additions & 15 deletions docs/src/improve-typing/impove_typing0.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
from dataclasses import dataclass
from typing import Set, cast
from typing import Protocol, Set, Union, cast
from uuid import UUID

import edgedb
from edgeql_queries import from_path
import edgeql_queries


@dataclass
class EdgeDBObject:
id: UUID
EdgeDBFetcher = Union[edgedb.AsyncIOPool, edgedb.AsyncIOConnection]


@dataclass
class Person(EdgeDBObject):
class Person(Protocol):
id: UUID
first_name: str
last_name: str


class Queries:
async def select_users_by_last_name(
self, conn: edgedb.AsyncIOConnection, last_name: str
self, fetcher: EdgeDBFetcher, last_name: str,
) -> Set[Person]:
...

async def select_user_by_id(
self, conn: edgedb.AsyncIOConnection, user_id: UUID
) -> Person:
async def select_user_by_id(self, fetcher: EdgeDBFetcher, user_id: UUID,) -> Person:
...

async def create_keanu_reeves(self, conn: edgedb.AsyncIOConnection) -> None:
async def create_keanu_reeves(self, fetcher: EdgeDBFetcher) -> None:
...


queries = cast(Queries, from_path("./queries.edgeql"))
queries = cast(Queries, edgeql_queries.from_path("./queries.edgeql"))
4 changes: 2 additions & 2 deletions docs/src/index/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import edgedb
from edgeql_queries import from_path
import edgeql_queries

queries = from_path("./queries.edgeql", async_driver=False)
queries = edgeql_queries.from_path("./queries.edgeql", async_driver=False)

conn = edgedb.connect("edgedb://edgedb@localhost/edgedb")

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index/queries.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ FILTER .id = <uuid>$user_id
INSERT Person {
first_name := "Keanu",
last_name := "Reeves",
}
}
20 changes: 11 additions & 9 deletions edgeql_queries/executors/async_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@

from functools import partial
from types import MappingProxyType
from typing import Any, Callable, Mapping
from typing import Any, Callable, Mapping, Union

from edgedb import AsyncIOConnection
from edgedb import AsyncIOConnection, AsyncIOPool
from edgedb.datatypes import datatypes

from edgeql_queries.models import EdgeQLOperationType, Query

_AsyncFetcher = Union[AsyncIOConnection, AsyncIOPool]

async def _execute(conn: AsyncIOConnection, *, query: Query) -> None:
return await conn.execute(query.edgeql)

async def _execute(__edgeql_query__: Query, conn: _AsyncFetcher) -> None:
return await conn.execute(__edgeql_query__.edgeql)


async def _set_return(
conn: AsyncIOConnection, *, query: Query, **query_args: Any,
__edgeql_query__: Query, conn: _AsyncFetcher, *query_args: Any, **query_kwargs: Any,
) -> datatypes.Set:
return await conn.fetchall(query.edgeql, **query_args)
return await conn.query(__edgeql_query__.edgeql, *query_args, **query_kwargs)


async def _single_return(
conn: AsyncIOConnection, *, query: Query, **query_args: Any,
__edgeql_query__: Query, conn: _AsyncFetcher, *query_args: Any, **query_kwargs: Any,
) -> Any:
return await conn.fetchone(query.edgeql, **query_args)
return await conn.query_one(__edgeql_query__.edgeql, *query_args, **query_kwargs)


_OPERATION_TO_EXECUTOR: Mapping[EdgeQLOperationType, Callable] = MappingProxyType(
Expand All @@ -45,4 +47,4 @@ def create_async_executor(query: Query) -> Callable:
Created async executor.
"""
executor = _OPERATION_TO_EXECUTOR[query.operation_type]
return partial(executor, query=query)
return partial(executor, query)
20 changes: 13 additions & 7 deletions edgeql_queries/executors/sync_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
from edgeql_queries.models import EdgeQLOperationType, Query


def _execute(conn: BlockingIOConnection, *, query: Query) -> None:
return conn.execute(query.edgeql)
def _execute(__edgeql_query__: Query, conn: BlockingIOConnection) -> None:
return conn.execute(__edgeql_query__.edgeql)


def _set_return(
conn: BlockingIOConnection, *, query: Query, **query_args: Any,
__edgeql_query__: Query,
conn: BlockingIOConnection,
*query_args: Any,
**query_kwargs: Any,
) -> datatypes.Set:
return conn.fetchall(query.edgeql, **query_args)
return conn.query(__edgeql_query__.edgeql, *query_args, **query_kwargs)


def _single_return(
conn: BlockingIOConnection, *, query: Query, **query_args: Any,
__edgeql_query__: Query,
conn: BlockingIOConnection,
*query_args: Any,
**query_kwargs: Any,
) -> Any:
return conn.fetchone(query.edgeql, **query_args)
return conn.query_one(__edgeql_query__.edgeql, *query_args, **query_kwargs)


_OPERATION_TO_EXECUTOR: Mapping[EdgeQLOperationType, Callable] = MappingProxyType(
Expand All @@ -45,4 +51,4 @@ def create_sync_executor(query: Query) -> Callable:
Created sync executor.
"""
executor = _OPERATION_TO_EXECUTOR[query.operation_type]
return partial(executor, query=query)
return partial(executor, query)
6 changes: 4 additions & 2 deletions edgeql_queries/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def from_path(edgeql_path: Union[str, Path], async_driver: bool = True) -> Queri
path = Path(edgeql_path)

if not path.exists():
raise EdgeQLLoadError(f"{path} does not exist")
raise EdgeQLLoadError("{0} does not exist".format(path))

queries = Queries(async_driver)

Expand All @@ -39,4 +39,6 @@ def from_path(edgeql_path: Union[str, Path], async_driver: bool = True) -> Queri
query_data_tree = load_query_data_from_dir_path(path)
return load_from_tree(queries, query_data_tree)

raise EdgeQLLoadError(f"edgeql_path must be a directory or file, got {edgeql_path}")
raise EdgeQLLoadError(
"edgeql_path must be a directory or file, got {0}".format(edgeql_path),
)
12 changes: 6 additions & 6 deletions edgeql_queries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
class EdgeQLOperationType(IntEnum):
"""Enumeration for operation types for queries."""

#: type for operation that returns a single object.
single_return = auto()
"""type for operation that returns a single object."""

#: type for operation that returns a common set of object.
set_return = auto()
"""type for operation that returns a common set of object."""

#: type for operation that returns nothing.
execute = auto()
"""type for operation that returns nothing."""


@dataclass
class Query:
"""Parsed query."""

#: name of parsed query.
name: str
"""name of parsed query."""

#: query operation type.
operation_type: EdgeQLOperationType
"""query operation type."""

#: EdgeQL query that should be executed.
edgeql: str
"""EdgeQL query that should be executed."""

def __hash__(self) -> int:
"""Hash query.
Expand Down
6 changes: 4 additions & 2 deletions edgeql_queries/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_query_name_and_operation(header_line: str) -> Tuple[str, EdgeQLOperation
name = name_match.group(1).replace("-", "_")

operation_suffix = ""
for suffix in _OPERATION_SUFFFIXES_TO_TYPES:
for suffix in _OPERATION_SUFFFIXES_TO_TYPES: # pragma: no branch
if name.endswith(suffix):
operation_suffix = suffix
break
Expand All @@ -89,7 +89,9 @@ def get_query_name_and_operation(header_line: str) -> Tuple[str, EdgeQLOperation

if not VALID_QUERY_NAME_PATTERN.match(query_name):
raise EdgeQLParsingError(
f'name must convert to valid python variable, got "{query_name}".',
'name must be convertable to valid python variable, got "{0}"'.format(
query_name,
),
)

return (
Expand Down
2 changes: 1 addition & 1 deletion edgeql_queries/query_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def load_query_data_from_dir_path(dir_path: Path) -> QueriesTree:
ValueError: if dir_path is not directory.
"""
if not dir_path.is_dir():
raise ValueError(f"path {dir_path} must be a directory")
raise ValueError("path {0} must be a directory".format(dir_path))

return _load_query_data_tree(dir_path, dir_path)

Expand Down
4 changes: 2 additions & 2 deletions example/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def main() -> None:

direcror_id = (
await queries.create_new_person(
conn, first_name="Denis", last_name="Villeneuve"
conn, first_name="Denis", last_name="Villeneuve",
)
).id

Expand All @@ -25,7 +25,7 @@ async def main() -> None:
person_ids = []
for person in persons:
created_person = await queries.create_new_person(
conn, first_name=person.first_name, last_name=person.last_name
conn, first_name=person.first_name, last_name=person.last_name,
)
person_ids.append(created_person.id)

Expand Down
Loading

1 comment on commit ee1d8a7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.