Skip to content

Commit

Permalink
Moving monarch-py into monarch-app (#189)
Browse files Browse the repository at this point in the history
- Merge monarch-py and monarch-api into backend of monarch-app
- Combine and update documentation
- api is now an optional extra and comes with its own command:
    - `cd <monarch-app>`
    - `poetry -C backend install -E api`
    - `monarch-api`
- add option to download specific version of solr kg
- bump minor version
- update testing a bit, disabled a couple until we can get a decent mock
solr implementation
- they still run locally though, so before each commit/pr we should
absolutely spin up a local solr and run `make test-backend` for now (not
ideal, but. where we're at)
  • Loading branch information
glass-ships authored Jul 5, 2023
1 parent 130f011 commit 73aa7df
Show file tree
Hide file tree
Showing 81 changed files with 5,616 additions and 660 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry -C backend install --no-interaction
run: poetry -C backend install --no-interaction -E api

#----------------------------------------------
# run pytest
Expand Down
69 changes: 38 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RUN = poetry -C backend/ run
VERSION = $(shell cd backend && poetry version -s)
RUN = poetry -C backend run
VERSION = $(shell poetry -C backend version -s)
ROOTDIR = $(shell pwd)
SCHEMADIR = $(ROOTDIR)/backend/src/monarch_py/datamodels

### Help ###
.PHONY: help
Expand Down Expand Up @@ -62,7 +63,7 @@ install: install-backend install-frontend
.PHONY: install-backend
install-backend:
cd backend && \
poetry install
poetry install -E api --with dev


.PHONY: install-frontend
Expand All @@ -73,24 +74,21 @@ install-frontend:


.PHONY: model
model: schema/
$(RUN) monarch schema > schema/model.yaml
$(RUN) gen-pydantic schema/model.yaml > backend/src/monarch_api/model.py
$(RUN) gen-typescript schema/model.yaml > frontend/src/api/model.ts
$(RUN) black backend/src/monarch_api/model.py
model: install-backend
$(RUN) gen-pydantic $(SCHEMADIR)/model.yaml > $(SCHEMADIR)/model.py
$(RUN) gen-typescript $(SCHEMADIR)/model.yaml > frontend/src/api/model.ts
$(RUN) black backend/src/monarch_py/datamodels/model.py


.PHONY: fixtures
fixtures: install-backend
@echo "Generating fixtures..."
@echo "This requires a running instance of Monarch Solr."
$(RUN) python scripts/generate_fixtures.py
$(RUN) black backend/tests/fixtures/
### Documentation ###

docs/Data-Model:
mkdir -p $@

# Documentation
.PHONY: docs
docs: install-backend model
$(RUN) gen-doc -d $(ROOTDIR)/docs/Data-Model/ $(ROOTDIR)/schema/model.yaml
docs: install-backend docs/Data-Model
$(RUN) gen-doc -d $(ROOTDIR)/docs/Data-Model/ $(SCHEMADIR)/model.yaml
$(RUN) typer backend/src/monarch_py/cli.py utils docs --name monarch --output docs/Usage/CLI.md
$(RUN) mkdocs build


Expand All @@ -101,16 +99,25 @@ test: test-backend test-frontend


.PHONY: test-backend
test-backend: install-backend model
test-backend:
$(RUN) pytest backend/tests


.PHONY: test-frontend
test-frontend: install-frontend model
test-frontend:
cd frontend && \
yarn test


.PHONY: fixtures
fixtures:
@echo "Generating fixtures..."
@echo "This requires a running instance of Monarch Solr."
$(RUN) python scripts/generate_fixtures.py
$(RUN) black backend/tests/fixtures/
cd frontend && \
yarn lint

### Development ###

.PHONY: dev-frontend
Expand All @@ -119,10 +126,10 @@ dev-frontend: frontend/src/api/model.ts
yarn dev


.PHONY: dev-backend
dev-backend: backend/src/monarch_api/model.py
.PHONY: dev-api
dev-api:
cd backend && \
poetry run uvicorn src.monarch_api.main:app --reload
poetry run uvicorn src.monarch_py.api.main:app --reload


### Docker ###
Expand Down Expand Up @@ -151,34 +158,34 @@ clean:

.PHONY: clobber
clobber:
rm -f schema/monarch-py.yaml \
backend/src/monarch_api/model.py \
rm -f schema/model.yaml \
backend/src/monarch_py/datamodels/model.py \
frontend/src/api/model.ts


.PHONY: lint
lint: install lint-frontend lint-backend
lint: lint-frontend lint-backend


.PHONY: lint-frontend
lint-frontend: install-frontend
lint-frontend:
cd frontend && \
yarn test:lint


.PHONY: lint-backend
lint-backend: install-backend
lint-backend:
$(RUN) flake8 --exit-zero --max-line-length 120 backend/src backend/tests
$(RUN) isort --check-only --diff backend/src backend/tests
$(RUN) black --check --diff backend/src backend/tests
$(RUN) black --check --diff -l 120 backend/src backend/tests


.PHONY: format
format: format-frontend format-backend


.PHONY: format-backend
format-backend: install-backend
format-backend:
$(RUN) autoflake \
--recursive \
--remove-all-unused-imports \
Expand All @@ -187,10 +194,10 @@ format-backend: install-backend
--in-place \
backend/src backend/tests
$(RUN) isort backend/src backend/tests
$(RUN) black backend/src backend/tests
$(RUN) black -l 120 backend/src backend/tests


.PHONY: format-frontend
format-frontend: install-frontend
format-frontend:
cd frontend && \
yarn lint
145 changes: 145 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
model/biolink-model.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
*-env/
# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# data input and ouptut
data/
output/
test-output/

#IDE stuff
.idea/

#MacOS DS Store
.DS_STORE

# Transform logs
logs/
8 changes: 4 additions & 4 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN apt-get update -y && \

# copy project requirement files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY . /opt/monarch-api
COPY . /opt/monarch-app

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN curl -sSL https://install.python-poetry.org | python3 && \
Expand All @@ -41,11 +41,11 @@ RUN curl -sSL https://install.python-poetry.org | python3 && \

FROM builder-base as production
ENV SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
WORKDIR /opt/monarch-api/backend
WORKDIR /opt/monarch-app/backend

RUN poetry install
RUN poetry install -E api

CMD ["/opt/poetry/bin/poetry", "run", "uvicorn", "src.monarch_api.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["/opt/poetry/bin/poetry", "run", "uvicorn", "src.monarch_py.api.main:app", "--host", "0.0.0.0", "--port", "8000"]

### Image URLs for reference ###
#
Expand Down
Loading

0 comments on commit 73aa7df

Please sign in to comment.