Skip to content

Commit 309ff36

Browse files
committed
Merged master into allow nested_aliases branch.
2 parents 4c46f55 + cd1dba6 commit 309ff36

File tree

22 files changed

+168
-111
lines changed

22 files changed

+168
-111
lines changed

.github/fly.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# fly.toml file generated for broken-field-1976 on 2022-11-21T21:37:55Z
2+
3+
app = "optimade"
4+
kill_signal = "SIGINT"
5+
kill_timeout = 5
6+
processes = []
7+
8+
[env]
9+
10+
[experimental]
11+
allowed_public_ports = []
12+
auto_rollback = true
13+
14+
[[services]]
15+
http_checks = []
16+
internal_port = 5000
17+
processes = ["app"]
18+
protocol = "tcp"
19+
script_checks = []
20+
[services.concurrency]
21+
hard_limit = 25
22+
soft_limit = 20
23+
type = "connections"
24+
25+
[[services.ports]]
26+
force_https = true
27+
handlers = ["http"]
28+
port = 80
29+
30+
[[services.ports]]
31+
handlers = ["tls", "http"]
32+
port = 443
33+
34+
[[services.tcp_checks]]
35+
grace_period = "1s"
36+
interval = "15s"
37+
restart_limit = 0
38+
timeout = "2s"

.github/workflows/ci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- master
88
- 'push-action/**'
99

10+
env:
11+
PYTEST_ADDOPTS: "--color=yes"
12+
1013
# Cancel running workflows when additional changes are pushed
1114
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
1215
concurrency:
@@ -162,7 +165,7 @@ jobs:
162165
ports:
163166
- 5432:5432
164167
elasticsearch:
165-
image: elasticsearch:7.17.1
168+
image: elasticsearch:7.17.7
166169
ports:
167170
- 9200:9200
168171
- 9300:9300
@@ -246,22 +249,22 @@ jobs:
246249
coverage run --append --source optimade optimade/client/cli.py \
247250
--filter 'nsites = 1' \
248251
--output-file test_get_async.json \
249-
https://optimade.herokuapp.com
252+
https://optimade.fly.dev
250253
test test_get_async.json
251254
252255
coverage run --append --source optimade optimade/client/cli.py \
253256
--filter 'nsites = 1' \
254257
--count \
255258
--output-file test_count.json \
256-
https://optimade.herokuapp.com
259+
https://optimade.fly.dev
257260
test test_count.json
258261
259262
coverage run --append --source optimade optimade/client/cli.py \
260263
--no-async \
261264
--filter 'nsites = 1' \
262265
--count \
263266
--output-file test_count_no_async.json \
264-
https://optimade.herokuapp.com
267+
https://optimade.fly.dev
265268
test test_count_no_async.json
266269
267270
diff test_count_no_async.json test_count.json

.github/workflows/ci_cd_updated_master.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,25 @@ jobs:
135135
sleep: 15
136136
force: ${{ env.FORCE_PUSH }}
137137

138-
deploy-heroku:
138+
deploy-fly:
139+
env:
140+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
141+
OPTIMADE_CONFIG_FILE: /app/tests/test_config.json
142+
OPTIMADE_BASE_URL: https://optimade.fly.dev
139143
runs-on: ubuntu-latest
140144
if: github.repository_owner == 'Materials-Consortia'
141145
steps:
142146
- name: Checkout repository
143147
uses: actions/checkout@v3
144-
145-
- name: Deploy to Heroku
146-
uses: akhileshns/heroku-deploy@v3.12.12
147148
with:
148-
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
149-
heroku_app_name: "optimade"
150-
heroku_email: ${{secrets.HEROKU_EMAIL}}
151-
branch: ${{env.DEFAULT_REPO_BRANCH}}
152-
env:
153-
HD_OPTIMADE_CONFIG_FILE: /app/tests/test_config.json
154-
HD_OPTIMADE_BASE_URL: https://optimade.herokuapp.com
149+
fetch-depth: 0
150+
submodules: true
151+
152+
- name: Set up Fly
153+
uses: superfly/flyctl-actions/setup-flyctl@master
154+
155+
- name: Deploy to Fly
156+
run: flyctl deploy --remote-only -c ./.github/fly.toml
155157

156158
publish_container_image:
157159
name: Publish container image

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
args: [--markdown-linebreak-ext=md]
2525

2626
- repo: https://github.com/pycqa/flake8
27-
rev: '3.9.2'
27+
rev: '5.0.4'
2828
hooks:
2929
- id: flake8
3030

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ These commands should be run from a local optimade-python-tools directory.
101101
The following command starts a local Elasticsearch v6 instance, runs the test suite, then stops and deletes the containers (required as the tests insert some data):
102102

103103
```shell
104-
docker run -d --name elasticsearch_test -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" elasticsearch:7.17.1 \
104+
docker run -d --name elasticsearch_test -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" elasticsearch:7.17.7 \
105105
&& sleep 10 \
106106
&& OPTIMADE_DATABASE_BACKEND="elastic" py.test; \
107107
docker container stop elasticsearch_test; docker container rm elasticsearch_test

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ OPTIMADE Python tools
3131
<td align="center">
3232
<a href="https://github.com/Materials-Consortia/optimade-python-tools/actions?query=branch%3Amaster+"><img alt="Build Status" src="https://img.shields.io/github/workflow/status/Materials-Consortia/optimade-python-tools/CI%20tests?logo=github"></a><br>
3333
<a href="https://codecov.io/gh/Materials-Consortia/optimade-python-tools"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/Materials-Consortia/optimade-python-tools?logo=codecov&logoColor=white&token=UJAtmqkZZO"></a><br>
34-
<a href="https://optimade.herokuapp.com"><img alt="Heroku App Status" src="https://heroku-shields.herokuapp.com/optimade??logo=heroku"></a>
3534
</td>
3635
<td align="center">
3736
<a href="https://github.com/Materials-Consortia/optimade-python-tools/pulse"><img alt="Commit Activity" src="https://img.shields.io/github/commit-activity/m/Materials-Consortia/optimade-python-tools?logo=github"></a><br>
@@ -50,7 +49,7 @@ This is to enable interoperability among databases that serve crystal structures
5049
This repository contains a library of tools for implementing and consuming [OPTIMADE APIs](https://www.optimade.org) using Python:
5150

5251
1. [pydantic](https://github.com/pydantic/pydantic) data models for all [OPTIMADE entry types](https://www.optimade.org/optimade-python-tools/latest/all_models/) and endpoint responses, and a [Lark](https://github.com/lark-parser/lark) [EBNF grammar](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) implementation for the OPTIMADE filter language.
53-
1. A configurable reference server implementation that can make use of either MongoDB or Elasticsearch database backends out-of-the-box, and is readily extensible to other backends. Try it out on the [demo site](https://optimade.herokuapp.com)! The OpenAPI schemas of the server are used to construct the [OPTIMADE schemas](https://schemas.optimade.org/) site.
52+
1. A configurable reference server implementation that can make use of either MongoDB or Elasticsearch database backends out-of-the-box, and is readily extensible to other backends. Try it out on the [demo site](https://optimade.fly.dev)! The OpenAPI schemas of the server are used to construct the [OPTIMADE schemas](https://schemas.optimade.org/) site.
5453
1. An [OPTIMADE client](https://www.optimade.org/optimade-python-tools/latest/getting_started/client/) (`optimade-get`) that can query multiple [OPTIMADE providers](https://optimade.org/providers-dashboard) concurrently with a given filter, at the command-line or from Python code.
5554
1. A fuzzy API validator tool, which may be called from the shell (`optimade-validator`) or used as a GitHub Action from [optimade-validator-action](https://github.com/Materials-Consortia/optimade-validator-action); this validator is used to construct the [providers dashboard](https://optimade.org/providers-dashboard).
5655

docs/concepts/validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ To run the script, simply provide an OPTIMADE URL to the script at the command-l
1212
You can use the following to validate the Heroku deployment of our reference server:
1313

1414
```shell
15-
$ optimade-validator https://optimade.herokuapp.com/
16-
Testing entire implementation at https://optimade.herokuapp.com
15+
$ optimade-validator https://optimade.fly.dev/
16+
Testing entire implementation at https://optimade.fly.dev
1717
...
1818
```
1919

docs/getting_started/client.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ We can refine the search by manually specifying some URLs:
6060

6161
=== "Command line"
6262
```shell
63-
optimade-get --output-file results.json https://optimade.herokuapp.com https://optimade.odbx.science
63+
optimade-get --output-file results.json https://optimade.fly.dev https://optimade.odbx.science
6464
```
6565

6666
=== "Python"
6767
```python
6868
from optimade.client import OptimadeClient
6969
client = OptimadeClient(
70-
base_urls=["https://optimade.herokuapp.com", "https://optimade.odbx.science"]
70+
base_urls=["https://optimade.fly.dev", "https://optimade.odbx.science"]
7171
)
7272
client.get()
7373
```
@@ -97,22 +97,22 @@ At the command-line, the results of the query will be printed to `stdout`, ready
9797
For example:
9898

9999
```shell
100-
optimade-get --filter 'nsites = 1' --output-file results.json https://optimade.herokuapp.com
100+
optimade-get --filter 'nsites = 1' --output-file results.json https://optimade.fly.dev
101101
cat results.json
102102
```
103103

104104
has the following (truncated) output:
105105

106106
```json
107-
{
107+
{
108108
// The endpoint that was queried
109-
"structures": {
109+
"structures": {
110110
// The filter applied to that endpointk
111-
"nsites = 1": {
111+
"nsites = 1": {
112112
// The base URL of the OPTIMADE API
113-
"https://optimade.herokuapp.com": {
113+
"https://optimade.fly.dev": {
114114
// The OPTIMADE API response as if called with an infinite `page_limit`
115-
"data": [
115+
"data": [
116116
{
117117
"id": "mpf_1",
118118
"type": "structures",
@@ -147,7 +147,7 @@ This is the same format as the cached results of the Python client:
147147

148148
```python
149149
from optimade.client import OptimadeClient
150-
client = OptimadeClient(base_urls="https://optimade.herokuapp.com")
150+
client = OptimadeClient(base_urls="https://optimade.fly.dev")
151151
client.get('nsites = 1')
152152
client.get('nsites = 2')
153153
print(client.all_results)
@@ -158,10 +158,10 @@ will return a dictionary with top-level keys:
158158
{
159159
"structures": {
160160
"nsites = 1": {
161-
"https://optimade.herokuapp.com": {...}
161+
"https://optimade.fly.dev": {...}
162162
},
163163
"nsites = 2": {
164-
"https://optimade.herokuapp.com": {...}
164+
"https://optimade.fly.dev": {...}
165165
}
166166
}
167167
}

optimade/server/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ServerConfig(BaseSettings):
153153
description="Which database backend to use out of the supported backends.",
154154
)
155155

156-
elastic_hosts: Optional[List[Dict]] = Field(
156+
elastic_hosts: Optional[Union[str, List[str], Dict, List[Dict]]] = Field(
157157
None, description="Host settings to pass through to the `Elasticsearch` class."
158158
)
159159

optimade/server/entry_collections/elasticsearch.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def create_optimade_index(self) -> None:
7272
]["properties"].pop(field)
7373
properties["id"] = {"type": "keyword"}
7474
body["mappings"]["properties"] = properties
75-
self.client.indices.create(index=self.name, body=body, ignore=400)
75+
self.client.indices.create(index=self.name, ignore=400, **body)
7676

77-
LOGGER.debug(f"Created Elastic index for {self.name!r} with body {body}")
77+
LOGGER.debug(f"Created Elastic index for {self.name!r} with parameters {body}")
7878

7979
@property
8080
def predefined_index(self) -> Dict[str, Any]:
@@ -94,7 +94,8 @@ def create_elastic_index_from_mapper(
9494
fields: The list of fields to use in the index.
9595
9696
Returns:
97-
The `body` parameter to pass to `client.indices.create(..., body=...)`.
97+
The parameters to pass to `client.indices.create(...)` (previously
98+
the 'body' parameters).
9899
99100
"""
100101
properties = {
@@ -135,15 +136,14 @@ def get_id(item):
135136

136137
bulk(
137138
self.client,
138-
[
139+
(
139140
{
140141
"_index": self.name,
141142
"_id": get_id(item),
142-
"_type": "_doc",
143143
"_source": item,
144144
}
145145
for item in data
146-
],
146+
),
147147
)
148148

149149
def _run_db_query(
@@ -177,9 +177,9 @@ def _run_db_query(
177177
for field, sort_dir in criteria.get("sort", {})
178178
]
179179
if not elastic_sort:
180-
elastic_sort = {
181-
self.resource_mapper.get_backend_field("id"): {"order": "asc"}
182-
}
180+
elastic_sort = [
181+
{self.resource_mapper.get_backend_field("id"): {"order": "asc"}}
182+
]
183183

184184
search = search.sort(*elastic_sort)
185185

0 commit comments

Comments
 (0)