Skip to content

Commit 340b8d8

Browse files
Merge pull request #112 from jverswijver/update_dynamic_api
Update dynamic api path handling.
2 parents c6af1f0 + 90560cd commit 340b8d8

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
44

5+
## [0.2.1] - 2021-11-08
6+
### Fixed
7+
- Error with retrieving the module's installation root path.
8+
59
## [0.2.0] - 2021-11-02
610
### Added
711
- Dynamic api generation from spec sheet.(#103, #104, #105, #107, #108, #110) PR #106, #109
@@ -76,6 +80,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
7680
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
7781
- Check dependency utility to determine child table references.
7882

83+
[0.2.1]: https://github.com/datajoint/pharus/compare/0.2.0...0.2.1
7984
[0.2.0]: https://github.com/datajoint/pharus/compare/0.1.0...0.2.0
8085
[0.1.0]: https://github.com/datajoint/pharus/compare/0.1.0b2...0.1.0
8186
[0.1.0b2]: https://github.com/datajoint/pharus/compare/0.1.0b0...0.1.0b2

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ COPY --chown=anaconda:anaconda ./README.rst ./requirements.txt ./setup.py \
66
/main/
77
COPY --chown=anaconda:anaconda ./pharus/*.py /main/pharus/
88
RUN \
9+
umask u+rwx,g+rwx,o-rwx && \
910
cd /main && \
1011
pip install . && \
1112
rm -R /main/*

pharus/dynamic_api_gen.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
import os
44
import yaml
5+
import pkg_resources
56

67

78
def populate_api():
@@ -59,8 +60,10 @@ def {method_name}_attributes(jwt_payload: dict) -> dict:
5960
return str(e), 500
6061
"""
6162

63+
pharus_root = f"{pkg_resources.get_distribution('pharus').module_path}/pharus"
64+
api_path = f'{pharus_root}/dynamic_api.py'
6265
spec_path = os.environ.get('API_SPEC_PATH')
63-
api_path = 'pharus/dynamic_api.py'
66+
6467
with open(Path(api_path), 'w') as f, open(Path(spec_path), 'r') as y:
6568
f.write(header_template)
6669
values_yaml = yaml.load(y, Loader=yaml.FullLoader)
@@ -70,7 +73,8 @@ def {method_name}_attributes(jwt_payload: dict) -> dict:
7073
for page in pages.values():
7174
for grid in page['grids'].values():
7275
for comp in grid['components'].values():
73-
f.write(route_template.format(route=comp['route'],
74-
method_name=comp['route'].replace('/', ''),
75-
query=indent(comp['dj_query'], ' '),
76-
restriction=indent(comp['restriction'], ' ')))
76+
if comp['type'] == 'table':
77+
f.write(route_template.format(route=comp['route'],
78+
method_name=comp['route'].replace('/', ''),
79+
query=indent(comp['dj_query'], ' '),
80+
restriction=indent(comp['restriction'], ' ')))

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = '0.2.0'
2+
__version__ = '0.2.1'

tests/init/test_dynamic_api_spec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SciViz: # top level tab
1818
route: /query1
1919
row_span: 0
2020
column_span: 0
21-
type: plot:png
21+
type: table
2222
restriction: >
2323
def restriction(**kwargs):
2424
return dict(**kwargs)
@@ -32,7 +32,7 @@ SciViz: # top level tab
3232
route: /query2
3333
row_span: 0
3434
column_span: 0
35-
type: plot:png
35+
type: table
3636
restriction: >
3737
def restriction(**kwargs):
3838
return dict(**kwargs)
@@ -58,7 +58,7 @@ SciViz: # top level tab
5858
route: /query3
5959
row_span: 0
6060
column_span: 0
61-
type: plot:png
61+
type: table
6262
restriction: >
6363
def restriction(**kwargs):
6464
return dict(**kwargs)
@@ -70,7 +70,7 @@ SciViz: # top level tab
7070
route: /query4
7171
row_span: 0
7272
column_span: 1
73-
type: plot:plotly1
73+
type: table
7474
restriction: >
7575
def restriction(**kwargs):
7676
return dict(**kwargs)
@@ -85,7 +85,7 @@ SciViz: # top level tab
8585
route: /query5
8686
row_span: 0
8787
column_span: 1
88-
type: plot:plotly1
88+
type: table
8989
restriction: >
9090
def restriction(**kwargs):
9191
return dict(a_id=0, **kwargs)

0 commit comments

Comments
 (0)