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

Update dev doc rebase2 #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ jobs:

- name: Upload to Codecov
if: matrix.python-version == 3.8
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
name: pytests
flags: pytests
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ repos:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies:
- pydantic~=1.8.2
- pydantic~=1.10.0
- types-python-dateutil
- types-docutils
exclude: >
(?x)^(
docs/.*|
Expand All @@ -34,14 +36,14 @@ repos:
)$

- repo: https://github.com/PyCQA/pylint
rev: v2.8.3
rev: v3.2.2
hooks:
- id: pylint
additional_dependencies:
- aiida-core~=2.0
- fastapi~=0.65.1
- uvicorn[standard]~=0.19.0
- pydantic~=1.8.2
- pydantic~=1.10.0
- graphene<3
- lark
- python-dateutil~=2.0
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,36 @@ See the [examples](https://github.com/aiidateam/aiida-restapi/tree/master/exampl
```shell
git clone https://github.com/aiidateam/aiida-restapi .
cd aiida-restapi
pip install -e .[pre-commit,testing] # install extra dependencies
pre-commit install # install pre-commit hooks
pytest -v # discover and run all tests
```

### Setting up pre-commit

We use pre-commit to take care for the formatting, type checking and linting.
```shell
pip install -e .[pre-commit] # install extra dependencies
pre-commit run # running pre-commit on changes
pre-commit run --all-files # running pre-commit on every file
pre-commit run pylint --all-files # run only the linter on every file
```
One can also set up pre-commit to be run on every commit
```shell
pre-commit install
# pre-commit uninstall # to disable it again
```

### Running tests

With tox the tests can be run
```shell
pip install tox
tox -e py311 # run all tests for Python 3.11
tox -av # see all supported environments
```
tox will creat a custom environment to run the tests in. If you want to run the
tests inside your current environment
```shell
pip install -e .[testing] # install extra dependencies
pytest -v
```

See the [developer guide](http://aiida-restapi.readthedocs.io/en/latest/developer_guide/index.html) for more information.
Expand Down
4 changes: 1 addition & 3 deletions aiida_restapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def get_entities(
order_by
), f"order_by not subset of projectable properties: {project!r}"
query.order_by({"fields": order_by})
return [
cls(**result["fields"]) for result in query.dict() # type: ignore[call-arg]
]
return [cls(**result["fields"]) for result in query.dict()]


class Comment(AiidaModel):
Expand Down
4 changes: 2 additions & 2 deletions aiida_restapi/routers/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ async def read_computer(comp_id: int) -> Optional[Computer]:
@with_dbenv()
async def create_computer(
computer: Computer,
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> Computer:
"""Create new AiiDA computer."""
orm_computer = orm.Computer(**computer.dict(exclude_unset=True)).store()
Expand Down
8 changes: 4 additions & 4 deletions aiida_restapi/routers/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ async def get_daemon_status() -> DaemonStatusModel:
@router.post("/daemon/start", response_model=DaemonStatusModel)
@with_dbenv()
async def get_daemon_start(
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> DaemonStatusModel:
"""Start the daemon."""
client = get_daemon_client()
Expand All @@ -64,9 +64,9 @@ async def get_daemon_start(
@router.post("/daemon/stop", response_model=DaemonStatusModel)
@with_dbenv()
async def get_daemon_stop(
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> DaemonStatusModel:
"""Stop the daemon."""
client = get_daemon_client()
Expand Down
4 changes: 2 additions & 2 deletions aiida_restapi/routers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ async def read_group(group_id: int) -> Optional[Group]:
@with_dbenv()
async def create_group(
group: Group_Post,
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> Group:
"""Create new AiiDA group."""
orm_group = orm.Group(**group.dict(exclude_unset=True)).store()
Expand Down
8 changes: 4 additions & 4 deletions aiida_restapi/routers/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async def read_node(nodes_id: int) -> Optional[models.Node]:
@with_dbenv()
async def create_node(
node: models.Node_Post,
current_user: models.User = Depends(
current_user: models.User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> models.Node:
"""Create new AiiDA node."""
node_dict = node.dict(exclude_unset=True)
Expand All @@ -68,9 +68,9 @@ async def create_node(
async def create_upload_file(
upload_file: bytes = File(...),
params: models.Node_Post = Depends(models.Node_Post.as_form), # type: ignore # pylint: disable=maybe-no-member
current_user: models.User = Depends(
current_user: models.User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> models.Node:
"""Endpoint for uploading file data"""
node_dict = params.dict(exclude_unset=True, exclude_none=True)
Expand Down
6 changes: 3 additions & 3 deletions aiida_restapi/routers/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ async def read_process(proc_id: int) -> Optional[Process]:
@with_dbenv()
async def post_process(
process: Process_Post,
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> Optional[Process]:
"""Create new process."""
process_dict = process.dict(exclude_unset=True, exclude_none=True)
Expand All @@ -93,7 +93,7 @@ async def post_process(
except ValueError as exc:
raise HTTPException(
status_code=404,
detail="Entry point '{}' not recognized.".format(entry_point),
detail=f"Entry point '{entry_point}' not recognized.",
) from exc

process_node = submit(entry_point_process, **inputs)
Expand Down
4 changes: 2 additions & 2 deletions aiida_restapi/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ async def read_user(user_id: int) -> Optional[User]:
@with_dbenv()
async def create_user(
user: User,
current_user: User = Depends(
current_user: User = Depends( # pylint: disable=unused-argument
get_current_active_user
), # pylint: disable=unused-argument
),
) -> User:
"""Create new AiiDA user."""
orm_user = orm.User(**user.dict(exclude_unset=True)).store()
Expand Down
11 changes: 7 additions & 4 deletions examples/daemon_management/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def request(
else:
headers = {}

response = requests.request(
method, f"{BASE_URL}/{url}", json=json, data=data, headers=headers
response = requests.request( # pylint: disable=missing-timeout
method,
f"{BASE_URL}/{url}",
json=json,
data=data,
headers=headers,
)

try:
Expand All @@ -62,8 +66,7 @@ def request(
click.echo(error["message"])

return None
else:
return response.json()
return response.json()


def authenticate(
Expand Down
5 changes: 2 additions & 3 deletions examples/process_management/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def request(
else:
headers = {}

response = requests.request(
response = requests.request( # pylint: disable=missing-timeout
method, f"{BASE_URL}/{url}", json=json, data=data, headers=headers
)

Expand All @@ -63,8 +63,7 @@ def request(
click.echo(error["message"])

return None
else:
return response.json()
return response.json()


def authenticate(
Expand Down
5 changes: 2 additions & 3 deletions examples/submit_quantumespresso_pw/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def request(
else:
headers = {}

response = requests.request(
response = requests.request( # pylint: disable=missing-timeout
method, f"{BASE_URL}/{url}", json=json, data=data, headers=headers
)

Expand All @@ -62,8 +62,7 @@ def request(
click.echo(error["message"])

return None
else:
return response.json()
return response.json()


def authenticate(
Expand Down
19 changes: 17 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pre-commit = [
'pre-commit~=2.12'
]
testing = [
'aiida-restapi[auth]',
'pgtest~=1.3.1',
'wheel~=0.31',
'coverage',
Expand Down Expand Up @@ -130,12 +131,19 @@ warn_untyped_fields = false
[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38
envlist =
py38
py311

[testenv]
usedevelop = true

[testenv:py{38,39,310}]
[testenv:py{38,39,310,311}]
description =
py38: Installs test dependencies and runs tests using python 3.8
py39: Installs test dependencies and runs tests using python 3.9
py310: Installs test dependencies and runs tests using python 3.10
py311: Installs test dependencies and runs tests using python 3.11
extras =
auth
testing
Expand All @@ -149,18 +157,25 @@ commands = pytest {posargs}
# now you can run `tox -e verdi quicksetup`, then `tox -e serve`

[testenv:verdi]
description =
Runs a verdi command within a tox environment that sets the AIIDA_PATH
setenv =
AIIDA_PATH = {toxinidir}/.tox/.aiida
commands = verdi {posargs}

[testenv:serve]
description =
Start the web API server within a tox environment that sets the AIIDA_PATH
extras =
auth
setenv =
AIIDA_PATH = {toxinidir}/.tox/.aiida
commands = uvicorn aiida_restapi:app {posargs:--reload}

[testenv:docs-{update,clean}]
description =
docs-clean: Build the documentation (remove any existing build)
docs-update: Build the documentation (modify any existing build)
extras =
auth
docs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_single_computers(
"""Test retrieving a single computer."""

for comp_id in default_computers:
response = client.get("/computers/{}".format(comp_id))
response = client.get(f"/computers/{comp_id}")
assert response.status_code == 200


Expand Down
2 changes: 1 addition & 1 deletion tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_get_single_group(default_groups, client): # pylint: disable=unused-arg
"""Test retrieving a single group."""

for group_id in default_groups:
response = client.get("/groups/{}".format(group_id))
response = client.get(f"/groups/{group_id}")
assert response.status_code == 200


Expand Down
4 changes: 2 additions & 2 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_get_single_nodes(default_nodes, client): # pylint: disable=unused-argu
"""Test retrieving a single nodes."""

for nodes_id in default_nodes:
response = client.get("/nodes/{}".format(nodes_id))
response = client.get(f"/nodes/{nodes_id}")
assert response.status_code == 200


Expand Down Expand Up @@ -299,7 +299,7 @@ def test_create_bool_with_extra(
},
)

check_response = client.get("/nodes/{}".format(response.json()["id"]))
check_response = client.get(f"/nodes/{response.json()['id']}")

assert check_response.status_code == 200, response.content
assert check_response.json()["extras"]["extra_one"] == "value_1"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_get_single_processes(
): # pylint: disable=unused-argument
"""Test retrieving a single processes."""
for proc_id in example_processes:
response = client.get("/processes/{}".format(proc_id))
response = client.get(f"/processes/{proc_id}")
assert response.status_code == 200


Expand Down
2 changes: 1 addition & 1 deletion tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def test_get_single_user(default_users, client): # pylint: disable=unused-argument
"""Test retrieving a single user."""
for user_id in default_users:
response = client.get("/users/{}".format(user_id))
response = client.get(f"/users/{user_id}")
assert response.status_code == 200


Expand Down
Loading