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 dynamic api to support sci viz templating for real time views #116

Merged
merged 50 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0d4758d
Support for metadata component.
jverswijver Nov 22, 2021
47e2c83
Add support for dynamic grid mode.
jverswijver Nov 29, 2021
0ebc76c
pep8
jverswijver Dec 1, 2021
2dc22f3
Add datetime handling.
jverswijver Dec 9, 2021
7bc8364
pep8
jverswijver Dec 9, 2021
37cabd2
Add attribute route to metadata.
jverswijver Dec 13, 2021
6de4d40
Add hotreloading for sci-viz.
jverswijver Dec 14, 2021
f02ddd9
Fix GHA vulnerability.
jverswijver Dec 15, 2021
cc89bff
Add hotreload scripts.
jverswijver Dec 16, 2021
a467448
Add component interface.
jverswijver Dec 20, 2021
375da72
impliment component library.
jverswijver Dec 21, 2021
2bb891f
[WIP] Simplify logic to make it easier for others to contribute to th…
guzman-raphael Dec 22, 2021
a18f816
Fix bug with datetime.
jverswijver Dec 22, 2021
8646bd4
[WIP] Update route template to match.
guzman-raphael Dec 22, 2021
a2d5bf3
Fix typecasting.
jverswijver Dec 22, 2021
c17ac8f
Update dynamic api gen with new inheritance structure.
guzman-raphael Dec 23, 2021
47d6674
Include fixes from jeroen's branch.
guzman-raphael Dec 23, 2021
2ab8f3c
Fix merge conflicts.
guzman-raphael Dec 23, 2021
35f5503
Merge pull request #1 from guzman-raphael/simplification_refactor
jverswijver Dec 23, 2021
7fed3f2
Add image component
jverswijver Jan 4, 2022
177791f
fix docker compose.
jverswijver Jan 4, 2022
4a608df
ignore dynamic api in style tests
jverswijver Jan 4, 2022
fcd635a
pep8
jverswijver Jan 4, 2022
a44fc63
Add sensitive info support.
guzman-raphael Jan 5, 2022
78d2d3d
Merge pull request #2 from guzman-raphael/sensitive-info
jverswijver Jan 5, 2022
e5a05f1
Fix component interface.
jverswijver Jan 5, 2022
1fc0aa1
Using otumat + use black formatting.
guzman-raphael Jan 21, 2022
8f1aea3
Fix multi-line strings + test a long string.
guzman-raphael Jan 21, 2022
f41d7db
Remove test.
guzman-raphael Jan 21, 2022
96013ec
Bump version and add changelog placeholder.
guzman-raphael Jan 21, 2022
18ead24
Update changelog and add otumat as dependency.
guzman-raphael Jan 21, 2022
88b7c6e
Remove whitespace.
guzman-raphael Jan 21, 2022
a73a4c0
Add changelog entry to spec sheet env var rename.
guzman-raphael Jan 21, 2022
0900199
Merge pull request #3 from guzman-raphael/pr_review_116
jverswijver Jan 21, 2022
00fe235
Fix version.py parsing and disable release to verify GH actions.
guzman-raphael Jan 21, 2022
1389fd6
Force GH actions to run.
guzman-raphael Jan 21, 2022
3fa1975
Fix style length limit issue after blacking code.
guzman-raphael Jan 21, 2022
8e774be
Fix line length + update github actions to be fork compatible.
guzman-raphael Jan 21, 2022
52350d4
Add black to CI, docs and blacken the docs' conf.py.
guzman-raphael Jan 21, 2022
b5aa268
Remove unnecessary comment.
guzman-raphael Jan 21, 2022
b0b8b8c
Merge pull request #4 from guzman-raphael/pr_review_116
jverswijver Jan 21, 2022
b007ebd
Add flake8 in style tests as well since it does more than formatting.
guzman-raphael Jan 21, 2022
57e379a
Update changelog.
jverswijver Jan 21, 2022
2ee7e0b
Merge branch 'update_dynamic_api' of https://github.com/jverswijver/p…
jverswijver Jan 21, 2022
15be296
Fix docs and add syntax/style tests for test program.
guzman-raphael Jan 21, 2022
ad38ce4
Remove W503 since not PEP8 compliant and ignore pytest fixture errors.
guzman-raphael Jan 21, 2022
cda4614
Update docs.
guzman-raphael Jan 21, 2022
ad4dd4f
Bump version due to changelog.
guzman-raphael Jan 21, 2022
d2353eb
Fix merge conflict.
guzman-raphael Jan 21, 2022
26617a4
Merge pull request #5 from guzman-raphael/pr_review_116
jverswijver Jan 21, 2022
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
46 changes: 32 additions & 14 deletions .github/workflows/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Development
on:
pull_request:
push:
tags:
- '*.*.*'
jobs:
test-changelog:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -40,7 +38,7 @@ jobs:
- uses: actions/checkout@v2
- name: Compile docs static artifacts
run: |
export PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
export PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
export HOST_UID=$(id -u)
docker-compose -f docker-compose-docs.yaml up --exit-code-from pharus-docs --build
echo "PHARUS_VERSION=${PHARUS_VERSION}" >> $GITHUB_ENV
Expand Down Expand Up @@ -69,7 +67,7 @@ jobs:
- uses: actions/checkout@v2
- name: Compile image
run: |
export PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
export PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
export HOST_UID=$(id -u)
docker-compose -f docker-compose-build.yaml up --exit-code-from pharus --build
IMAGE=$(docker images --filter "reference=datajoint/pharus*" \
Expand Down Expand Up @@ -112,7 +110,7 @@ jobs:
- uses: actions/checkout@v2
- name: Determine package version
run: |
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
echo "PHARUS_VERSION=${PHARUS_VERSION}" >> $GITHUB_ENV
- name: Fetch image artifact
uses: actions/download-artifact@v2
Expand All @@ -124,7 +122,13 @@ jobs:
docker load < "image-pharus-${PHARUS_VERSION}-py${PY_VER}-${DISTRO}.tar.gz"
docker-compose -f docker-compose-test.yaml up --exit-code-from pharus
publish-release:
if: github.event_name == 'push'
if: |
github.event_name == 'push' &&
contains(github.ref, 'refs/tags/*.*.*') &&
(
github.repository_owner == 'datajoint' ||
github.repository_owner == 'vathes'
)
needs: test
runs-on: ubuntu-latest
env:
Expand All @@ -136,7 +140,7 @@ jobs:
- uses: actions/checkout@v2
- name: Determine package version
run: |
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
echo "PHARUS_VERSION=${PHARUS_VERSION}" >> $GITHUB_ENV
- name: Get changelog entry
id: changelog_reader
Expand Down Expand Up @@ -203,7 +207,13 @@ jobs:
asset_name: docker-compose-deploy.yaml
asset_content_type: application/yaml
publish-images:
if: github.event_name == 'push'
if: |
github.event_name == 'push' &&
contains(github.ref, 'refs/tags/*.*.*') &&
(
github.repository_owner == 'datajoint' ||
github.repository_owner == 'vathes'
)
needs: publish-release
runs-on: ubuntu-latest
strategy:
Expand All @@ -216,21 +226,23 @@ jobs:
PY_VER: ${{matrix.py_ver}}
DISTRO: ${{matrix.distro}}
IMAGE: ${{matrix.image}}
DOCKER_USERNAME: ${{secrets.docker_username}}
DOCKER_PASSWORD: ${{secrets.docker_password}}
steps:
- uses: actions/checkout@v2
- name: Determine package version
run: |
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
echo "PHARUS_VERSION=${PHARUS_VERSION}" >> $GITHUB_ENV
- name: Fetch image artifact
uses: actions/download-artifact@v2
with:
name: image-pharus-${{env.PHARUS_VERSION}}-py${{matrix.py_ver}}-${{matrix.distro}}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{secrets.docker_username}}
password: ${{secrets.docker_password}}
- name: Publish image
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker load < "image-pharus-${PHARUS_VERSION}-py${PY_VER}-${DISTRO}.tar.gz"
IMAGE=$(docker images --filter "reference=datajoint/*" --format "{{.Repository}}")
TAG=$(docker images --filter "reference=datajoint/*" --format "{{.Tag}}")
Expand All @@ -253,14 +265,20 @@ jobs:
${{matrix.distro}}.tar.gz"
asset_content_type: application/gzip
publish-docs:
if: github.event_name == 'push'
if: |
github.event_name == 'push' &&
contains(github.ref, 'refs/tags/*.*.*') &&
(
github.repository_owner == 'datajoint' ||
github.repository_owner == 'vathes'
)
needs: publish-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Determine package version
run: |
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}')
PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}')
echo "PHARUS_VERSION=${PHARUS_VERSION}" >> $GITHUB_ENV
- name: Fetch docs static artifacts
uses: actions/download-artifact@v2
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Changelog

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

## [0.3.0] - 2022-01-21
### Changed
- Hot-reload mechanism to use `otumat watch` PR #116
- Renamed environment variable defining spec sheet to `PHARUS_SPEC_PATH` PR #116

### Added
- Autoformatting strategy using `black` PR #116
- Support for sci-viz components `metadata`, `image`, `dynamic grid` PR #116
- `component interface` for users to be able to load their own custom interface for sci-viz PR #116

### Fixed
- Various bugs related to datetime PR #116

## [0.2.3] - 2021-11-18
### Added
- Support for plot component PR #155
Expand Down Expand Up @@ -88,6 +102,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
- Check dependency utility to determine child table references.

[0.3.0]: https://github.com/datajoint/pharus/compare/0.2.3...0.3.0
[0.2.3]: https://github.com/datajoint/pharus/compare/0.2.2...0.2.3
[0.2.2]: https://github.com/datajoint/pharus/compare/0.2.1...0.2.2
[0.2.1]: https://github.com/datajoint/pharus/compare/0.2.0...0.2.1
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ HEALTHCHECK \
--retries=5 \
--interval=15s \
CMD \
wget --quiet --tries=1 --spider \
http://localhost:${PHARUS_PORT}${PHARUS_PREFIX}/version > /dev/null 2>&1 || exit 1
wget --quiet --tries=1 --spider \
http://localhost:${PHARUS_PORT}${PHARUS_PREFIX}/version > /dev/null 2>&1 || exit 1
ENV PHARUS_PORT 5000
# ---TEMP---
RUN pip install plotly
# ----------
COPY --chown=anaconda:anaconda ./reload.sh /tmp/
WORKDIR /main

# development service
# CMD ["pharus"]

# production service
CMD ["sh", "-c", "gunicorn --bind 0.0.0.0:${PHARUS_PORT} pharus.server:app"]
CMD ["sh", "-c", "otumat watch -f ${PHARUS_SPEC_PATH} -s /tmp/reload.sh -i 5"]
2 changes: 1 addition & 1 deletion docker-compose-build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-build.yaml up --exit-code-from pharus --build
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-build.yaml up --exit-code-from pharus --build
#
# Intended for updating dependencies and docker image.
# Used to build release artifacts.
Expand Down
7 changes: 4 additions & 3 deletions docker-compose-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
# With this config and the configuration below in NGINX, you should be able to verify it is
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
version: "2.4"
x-net: &net
x-net:
&net
networks:
- main
- main
services:
pharus:
<<: *net
image: datajoint/pharus:${PHARUS_VERSION}
# environment: # configurable values with defaults
# - PHARUS_PORT=5000
# - PHARUS_PREFIX=/
# - API_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml # for dynamic api spec
# - PHARUS_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml # for dynamic api spec
fakeservices.datajoint.io:
<<: *net
image: datajoint/nginx:v0.0.16
Expand Down
9 changes: 5 additions & 4 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-dev.yaml up
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-dev.yaml up
#
# Intended for normal development. Supports hot/live reloading.
# Note: If requirements or Dockerfile change, will need to add --build flag to docker-compose.
Expand All @@ -7,9 +7,10 @@
# With this config and the configuration below in NGINX, you should be able to verify it is
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
version: "2.4"
x-net: &net
x-net:
&net
networks:
- main
- main
services:
local-db:
<<: *net
Expand All @@ -25,7 +26,7 @@ services:
service: pharus
environment:
- FLASK_ENV=development # enables logging to console from Flask
- API_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml # for dynamic api spec
- PHARUS_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml # for dynamic api spec
volumes:
- ./pharus:/opt/conda/lib/python3.8/site-packages/pharus
command: pharus
Expand Down
15 changes: 10 additions & 5 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# PY_VER=3.8 IMAGE=djtest DISTRO=alpine AS_SCRIPT=FALSE PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-test.yaml up --exit-code-from pharus
# PY_VER=3.8 IMAGE=djtest DISTRO=alpine AS_SCRIPT=FALSE PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\" '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-test.yaml up --exit-code-from pharus
#
# Intended for running test suite locally.
# Note: If requirements or Dockerfile change, will need to add --build flag.
version: "2.4"
x-net: &net
x-net:
&net
networks:
- main
- main
services:
db:
<<: *net
Expand All @@ -23,7 +24,7 @@ services:
- TEST_DB_USER=root
- TEST_DB_PASS=simple
- AS_SCRIPT
- API_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml
- PHARUS_SPEC_PATH=tests/init/test_dynamic_api_spec.yaml
volumes:
- ./requirements_test.txt:/tmp/pip_requirements.txt
- ./pharus:/opt/conda/lib/python3.8/site-packages/pharus
Expand All @@ -36,10 +37,14 @@ services:
echo "------ SYNTAX TESTS ------"
PKG_DIR=/opt/conda/lib/python3.8/site-packages/pharus
flake8 $${PKG_DIR} --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 /main/tests --count --select=E9,F63,F7,F82 --show-source --statistics
echo "------ UNIT TESTS ------"
pytest -sv --cov-report term-missing --cov=pharus /main/tests
echo "------ STYLE TESTS ------"
flake8 $${PKG_DIR} --count --max-complexity=20 --max-line-length=95 --statistics
black $${PKG_DIR} --check -v --extend-exclude "^.*dynamic_api.py$$"
flake8 $${PKG_DIR} --count --max-complexity=20 --max-line-length=94 --statistics --exclude=*dynamic_api.py --ignore=W503
black /main/tests --check -v
flake8 /main/tests --count --max-complexity=20 --max-line-length=94 --statistics --ignore=F401,F811,W503
else
echo "=== Running ==="
echo "Please see 'docker-compose-test.yaml' for detail on running tests."
Expand Down
19 changes: 10 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,41 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

project = 'Pharus'
copyright = '2021, DataJoint Contributors'
author = 'DataJoint Contributors'
project = "Pharus"
copyright = "2021, DataJoint Contributors"
author = "DataJoint Contributors"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinxcontrib.httpdomain']
extensions = ["sphinx.ext.autodoc", "sphinxcontrib.httpdomain"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
11 changes: 8 additions & 3 deletions docs/dev_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Run Locally w/ Python
- For development, use CLI command ``pharus``. This method supports hot-reloading so probably best coupled with ``pip install -e ...``.
- For production, use ``gunicorn --bind 0.0.0.0:${PHARUS_PORT} pharus.server:app``.

Run Tests for Development w/ Pytest and Flake8
----------------------------------------------
Run Tests for Development w/ Pytest, Flake8, Black
--------------------------------------------------

- Set ``pharus`` testing environment variables:

Expand All @@ -45,7 +45,12 @@ Run Tests for Development w/ Pytest and Flake8

- For syntax tests, run ``flake8 ${PKG_DIR} --count --select=E9,F63,F7,F82 --show-source --statistics``
- For pytest integration tests, run ``pytest -sv --cov-report term-missing --cov=${PKG_DIR} /main/tests``
- For style tests, run ``flake8 ${PKG_DIR} --count --max-complexity=20 --max-line-length=95 --statistics``
- For style tests, run:

.. code-block:: bash

black ${PKG_DIR} --check -v --extend-exclude "^.*dynamic_api.py$"
flake8 ${PKG_DIR} --count --max-complexity=20 --max-line-length=94 --statistics --exclude=*dynamic_api.py --ignore=W503

Creating Sphinx Documentation from Scratch
------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions pharus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from os import path, environ

try:
if path.exists(environ.get('API_SPEC_PATH')):
if path.exists(environ.get("PHARUS_SPEC_PATH")):
dynamic_api_gen.populate_api()
except TypeError:
print('No Dynamic API path found')
print("No Dynamic API path found")

try:
from .dynamic_api import app
except ImportError:
from .server import app

__all__ = ['__version__', 'app']
__all__ = ["__version__", "app"]
Loading