Skip to content

Commit

Permalink
Merge branch 'master' into ml-evs/list_queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Feb 15, 2020
2 parents fce4125 + 5f8efab commit 0e7f41d
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 23 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/deps_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
pre-commit:
runs-on: ubuntu-latest

Expand All @@ -53,6 +54,7 @@ jobs:
run: |
pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
openapi:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -87,28 +89,46 @@ jobs:
.ci/openapi_diff.sh
.ci/index_openapi_diff.sh
docker-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Build the Docker image
- name: Build the Docker images
run: docker-compose build

- name: Test server
- name: Start Docker image - server
run: |
docker-compose up optimade &
.github/workflows/wait_for_it.sh localhost:3213 -t 120
sleep 15
docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0
- name: Test index server
- name: Test server
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0

- name: Test server - OPTIONAL base URL; vMAJOR.MINOR
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0.10

- name: Test server - OPTIONAL base URL; vMAJOR.MINOR.PATCH
run: docker exec optimade-python-tools_optimade_1 optimade_validator http://localhost:5000/optimade/v0.10.1

- name: Start Docker image - index server
run: |
docker-compose up optimade-index &
.github/workflows/wait_for_it.sh localhost:3214 -t 120
sleep 15
docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0 --index
- name: Test index server
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0 --index

- name: Test index server - OPTIONAL base URL; vMAJOR.MINOR
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0.10 --index

- name: Test index server - OPTIONAL base URL; vMAJOR.MINOR.PATCH
run: docker exec optimade-python-tools_optimade-index_1 optimade_validator http://localhost:5001/optimade/v0.10.1 --index


deps_static:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion openapi/index_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.2",
"info": {
"title": "OPTiMaDe API - Index meta-database",
"description": "The [Open Databases Integration for Materials Design (OPTiMaDe) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.\nThis is the \"special\" index meta-database.\n\nThis specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v0.4.0) v0.4.0.",
"description": "The [Open Databases Integration for Materials Design (OPTiMaDe) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.\nThis is the \"special\" index meta-database.\n\nThis specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v0.5.0) v0.5.0.",
"version": "0.10.1"
},
"paths": {
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.2",
"info": {
"title": "OPTiMaDe API",
"description": "The [Open Databases Integration for Materials Design (OPTiMaDe) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.\n\nThis specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v0.4.0) v0.4.0.",
"description": "The [Open Databases Integration for Materials Design (OPTiMaDe) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.\n\nThis specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v0.5.0) v0.5.0.",
"version": "0.10.1"
},
"paths": {
Expand Down
2 changes: 1 addition & 1 deletion optimade/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.4.0"
__version__ = "0.5.0"
__api_version__ = "0.10.1"
6 changes: 6 additions & 0 deletions optimade/server/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ index_base_url = http://localhost:5001/optimade
[structures]
band_gap :
_mp_chemsys :

[structures.aliases]
id = task_id
chemical_formula_descriptive = pretty_formula
chemical_formula_reduced = pretty_formula
chemical_formula_anonymous = formula_anonymous
13 changes: 13 additions & 0 deletions optimade/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def load_from_ini(self):
else:
self.provider = self._DEFAULTS("provider")

self.aliases = {}
for endpoint in {"links", "references", "structures"}:
if f"{endpoint}.aliases" in config:
section = config[f"{endpoint}.aliases"]
self.aliases[endpoint] = tuple(section.items())

self.provider_fields = {}
for endpoint in {"links", "references", "structures"}:
self.provider_fields[endpoint] = (
Expand Down Expand Up @@ -233,5 +239,12 @@ def load_from_json(self):
set(config.get("provider_fields", {}).get(endpoint, []))
)

self.aliases = {}
if "aliases" in config:
for endpoint in {"links", "references", "structures"}:
if endpoint in config["aliases"]:
section = config["aliases"][endpoint]
self.aliases[endpoint] = tuple(section.items())


CONFIG = ServerConfig()
1 change: 1 addition & 0 deletions optimade/server/mappers/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def all_aliases(cls) -> Tuple[Tuple[str, str]]:
(CONFIG.provider["prefix"] + field, field)
for field in CONFIG.provider_fields.get(cls.ENDPOINT, [])
)
+ CONFIG.aliases.get(cls.ENDPOINT, ())
+ cls.ALIASES
)

Expand Down
6 changes: 0 additions & 6 deletions optimade/server/mappers/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@
class StructureMapper(ResourceMapper):

ENDPOINT = "structures"
ALIASES = (
("id", "task_id"),
("chemical_formula_descriptive", "pretty_formula"),
("chemical_formula_reduced", "pretty_formula"),
("chemical_formula_anonymous", "formula_anonymous"),
)
4 changes: 2 additions & 2 deletions optimade/server/routers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

BASE_URL_PREFIXES = {
"major": f"/optimade/v{__api_version__.split('.')[0]}",
"minor": f"/optimade/v{__api_version__.split('.')[1]}",
"patch": f"/optimade/v{__api_version__.split('.')[2]}",
"minor": f"/optimade/v{'.'.join(__api_version__.split('.')[:2])}",
"patch": f"/optimade/v{__api_version__}",
}


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name="optimade",
version="0.4.0",
version="0.5.0",
url="https://github.com/Materials-Consortia/optimade-python-tools",
license="MIT",
author="OPTiMaDe Development Team",
Expand Down
27 changes: 21 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ def update_openapijson(c):
def set_optimade_ver(_, ver=""):
if not ver:
raise Exception("Please specify --ver='Major.Minor.Patch'")
if not re.match("[0-9]+.[0-9]+.[0-9]+", ver):
raise Exception("ver MUST be expressed as 'Major.Minor.Patch'")

with open("optimade/__init__.py", "r") as f:
lines = [
re.sub(
"__api_version__ = .+", '__api_version__ = "{}"'.format(ver), l.rstrip()
)
re.sub("__api_version__ = .+", f'__api_version__ = "{ver}"', l.rstrip())
for l in f
]
with open("optimade/__init__.py", "w") as f:
Expand All @@ -69,11 +70,25 @@ def set_optimade_ver(_, ver=""):

with open(".ci/optimade-version.json", "r") as f:
lines = [
re.sub('"message": .+', '"message": "v{}",'.format(ver), l.rstrip())
for l in f
re.sub('"message": .+', f'"message": "v{ver}",', l.rstrip()) for l in f
]
with open(".ci/optimade-version.json", "w") as f:
f.write("\n".join(lines))
f.write("\n")

print("Bumped OPTiMaDe version to {}".format(ver))
with open(".github/workflows/deps_lint.yml", "r") as f:
lines = f
for regex, version in (
("[0-9]+", ver.split(".")[0]),
("[0-9]+.[0-9]+", ".".join(ver.split(".")[:2])),
("[0-9]+.[0-9]+.[0-9]+", ver),
):
lines = [
re.sub(f"/optimade/v{regex}", f"/optimade/v{version}", l.rstrip())
for l in lines
]
with open(".github/workflows/deps_lint.yml", "w") as f:
f.write("\n".join(lines))
f.write("\n")

print(f"Bumped OPTiMaDe version to {ver}")
6 changes: 6 additions & 0 deletions tests/server/config_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ index_base_url = http://localhost:5001/optimade
[structures]
band_gap :
_mp_chemsys :

[structures.aliases]
id = task_id
chemical_formula_descriptive = pretty_formula
chemical_formula_reduced = pretty_formula
chemical_formula_anonymous = formula_anonymous
8 changes: 8 additions & 0 deletions tests/server/config_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
"band_gap",
"_mp_chemsys"
]
},
"aliases": {
"structures": {
"id": "task_id",
"chemical_formula_descriptive": "pretty_formula",
"chemical_formula_reduced": "pretty_formula",
"chemical_formula_anonymous": "formula_anonymous"
}
}
}

0 comments on commit 0e7f41d

Please sign in to comment.