Skip to content

Commit

Permalink
Merging from dev.
Browse files Browse the repository at this point in the history
  • Loading branch information
milo-hyben committed Sep 18, 2023
2 parents 1103cb0 + f128b70 commit a61b39c
Show file tree
Hide file tree
Showing 47 changed files with 712 additions and 559 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
run:
shell: bash -eo pipefail -l {0}
steps:
- uses: actions/checkout@main
- uses: actions/checkout@v3

- name: "gcloud setup"
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/setup-gcloud@v1
with:
project_id: sample-metadata
service_account_key: ${{ secrets.GCP_SERVER_DEPLOY_KEY }}
Expand All @@ -33,11 +33,11 @@ jobs:
run: |
gcloud auth configure-docker australia-southeast1-docker.pkg.dev
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: "temurin" # See 'Supported distributions' for available options
java-version: "17"
Expand Down
40 changes: 35 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,52 @@ on: push
jobs:
lint:
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: 1
BUILDKIT_PROGRESS: plain
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
# used for generating API
SM_DOCKER: samplemetadata:dev
defaults:
run:
shell: bash -eo pipefail -l {0}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"

- name: Install packages
- uses: actions/setup-java@v2
with:
distribution: "temurin" # See 'Supported distributions' for available options
java-version: "17"

- name: Setup build env
run: |
set -euxo pipefail
pip install -r requirements-dev.txt
pip install -r requirements.txt
# openapi-generator
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.3.0/openapi-generator-cli-5.3.0.jar -O openapi-generator-cli.jar
- name: "build image"
run: |
docker build \
--build-arg SM_ENVIRONMENT=local \
--tag $SM_DOCKER \
-f deploy/api/Dockerfile \
.
- name: Build + install packages
run: |
export OPENAPI_COMMAND="java -jar openapi-generator-cli.jar"
python regenerate_api.py
pip install -r requirements-dev.txt
pip install .
mkdir .mypy_cache
- name: pre-commit
run: pre-commit run --all-files
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
run:
shell: bash -eo pipefail -l {0}
steps:
- uses: actions/checkout@main
- uses: actions/checkout@v3

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: "temurin" # See 'Supported distributions' for available options
java-version: "17"
Expand Down Expand Up @@ -70,10 +70,10 @@ jobs:
rc=$?
coverage xml
echo "::set-output name=rc::$rc"
echo "rc=$rc" >> $GITHUB_OUTPUT
- name: "Upload coverage report"
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml

Expand All @@ -89,7 +89,7 @@ jobs:
- name: Fail if tests are not passing
if: ${{ steps.runtests.outputs.rc != 0 }}
uses: actions/github-script@v3
uses: actions/github-script@v6
with:
script: |
core.setFailed('Unit tests failed with rc = ${{ steps.runtests.outputs.rc }}')
174 changes: 90 additions & 84 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,92 +1,98 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
exclude: '\.*conda/.*'
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: '\.txt$|\.tsv$'
- id: check-case-conflict
- id: check-merge-conflict
- id: detect-private-key
- id: debug-statements
- id: check-added-large-files
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
exclude: '\.*conda/.*'
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: '\.txt$|\.tsv$'
- id: check-case-conflict
- id: check-merge-conflict
- id: detect-private-key
- id: debug-statements
- id: check-added-large-files

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
- id: markdownlint
args: ["--config", ".markdownlint.json"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
- id: markdownlint
args: ["--config", ".markdownlint.json"]

- repo: https://github.com/ambv/black
rev: 23.3.0
hooks:
- id: black
args: [.]
pass_filenames: false
always_run: true
exclude: ^metamist/
- repo: https://github.com/ambv/black
rev: 23.3.0
hooks:
- id: black
args: [.]
pass_filenames: false
always_run: true
exclude: ^metamist/

- repo: https://github.com/PyCQA/flake8
rev: "6.0.0"
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear, flake8-quotes]
- repo: https://github.com/PyCQA/flake8
rev: "6.0.0"
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear, flake8-quotes]

# Using system installation of pylint to support checking python module imports
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
# Using system installation of pylint to support checking python module imports
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]

# mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
hooks:
- id: mypy
args:
[
--pretty,
--show-error-codes,
--no-strict-optional,
--ignore-missing-imports,
--install-types,
--non-interactive,
]
additional_dependencies:
- strawberry-graphql[fastapi]==0.138.1
# mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
args:
[
--pretty,
--show-error-codes,
--no-strict-optional,
--ignore-missing-imports,
--install-types,
--non-interactive,
--show-error-context,
--check-untyped-defs,
--explicit-package-bases,
--disable-error-code,
operator,
]
additional_dependencies:
- strawberry-graphql[fastapi]==0.206.0
- types-PyMySQL==1.1.0.1

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.4"
hooks:
- id: prettier
# I'm not exactly sure why it changes behaviour, but
# calling `cd web`, then calling `ls src/**/*.tsx`
# returns different results to `cd web && ls src/**/*.tsx`
# so just include both patterns here
entry: bash -c 'cd web && prettier --write --ignore-unknown --check src/*.{ts,tsx,css} src/**/*.{ts,tsx,css}'
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.4"
hooks:
- id: prettier
# I'm not exactly sure why it changes behaviour, but
# calling `cd web`, then calling `ls src/**/*.tsx`
# returns different results to `cd web && ls src/**/*.tsx`
# so just include both patterns here
entry: bash -c 'cd web && prettier --write --ignore-unknown --check src/*.{ts,tsx,css} src/**/*.{ts,tsx,css}'

- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.33.0"
hooks:
- id: eslint
entry: bash -c 'cd web && eslint'
files: \.[jt]sx?$
types: [file]
additional_dependencies:
- eslint@^7.32.0
- eslint-config-airbnb@^19.0.4
- eslint-config-airbnb-base@^15.0.0
- eslint-config-airbnb-typescript@^17.0.0
- eslint-config-prettier@^8.6.0
- eslint-plugin-import@^2.26.0
- eslint-plugin-jsx-a11y@^6.6.1
- eslint-plugin-prettier@^4.2.1
- eslint-plugin-react@^7.31.11
- eslint-plugin-react-hooks@^4.6.0
- "@typescript-eslint/eslint-plugin@^5.48.0"
- "@typescript-eslint/parser@^5.48.0"
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.33.0"
hooks:
- id: eslint
entry: bash -c 'cd web && eslint'
files: \.[jt]sx?$
types: [file]
additional_dependencies:
- eslint@^7.32.0
- eslint-config-airbnb@^19.0.4
- eslint-config-airbnb-base@^15.0.0
- eslint-config-airbnb-typescript@^17.0.0
- eslint-config-prettier@^8.6.0
- eslint-plugin-import@^2.26.0
- eslint-plugin-jsx-a11y@^6.6.1
- eslint-plugin-prettier@^4.2.1
- eslint-plugin-react@^7.31.11
- eslint-plugin-react-hooks@^4.6.0
- "@typescript-eslint/eslint-plugin@^5.48.0"
- "@typescript-eslint/parser@^5.48.0"
38 changes: 27 additions & 11 deletions api/graphql/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
from db.python.connect import NotFoundError
from db.python.layers import (
AnalysisLayer,
SampleLayer,
AssayLayer,
FamilyLayer,
ParticipantLayer,
SampleLayer,
SequencingGroupLayer,
FamilyLayer,
)
from db.python.tables.analysis import AnalysisFilter
from db.python.tables.assay import AssayFilter
from db.python.tables.project import ProjectPermissionsTable
from db.python.tables.sample import SampleFilter
from db.python.tables.sequencing_group import SequencingGroupFilter
from db.python.utils import ProjectId, GenericFilter
from db.python.utils import GenericFilter, ProjectId
from models.models import (
AssayInternal,
SampleInternal,
SequencingGroupInternal,
AnalysisInternal,
ParticipantInternal,
AssayInternal,
FamilyInternal,
ParticipantInternal,
Project,
SampleInternal,
SequencingGroupInternal,
)


Expand All @@ -53,6 +53,8 @@ class LoaderKeys(enum.Enum):
SAMPLES_FOR_PARTICIPANTS = 'samples_for_participants'
SAMPLES_FOR_PROJECTS = 'samples_for_projects'

PHENOTYPES_FOR_PARTICIPANTS = 'phenotypes_for_participants'

PARTICIPANTS_FOR_IDS = 'participants_for_ids'
PARTICIPANTS_FOR_FAMILIES = 'participants_for_families'
PARTICIPANTS_FOR_PROJECTS = 'participants_for_projects'
Expand Down Expand Up @@ -291,9 +293,7 @@ async def load_participants_for_ids(
p_by_id = {p.id: p for p in persons}
missing_pids = set(participant_ids) - set(p_by_id.keys())
if missing_pids:
raise NotFoundError(
f'Could not find participants with ids {missing_pids}'
)
raise NotFoundError(f'Could not find participants with ids {missing_pids}')
return [p_by_id.get(p) for p in participant_ids]


Expand Down Expand Up @@ -400,7 +400,23 @@ async def load_analyses_for_sequencing_groups(
return by_sg_id


async def get_context(request: Request, connection=get_projectless_db_connection): # pylint: disable=unused-argument
@connected_data_loader(LoaderKeys.PHENOTYPES_FOR_PARTICIPANTS)
async def load_phenotypes_for_participants(
participant_ids: list[int], connection
) -> list[dict]:
"""
Data loader for phenotypes for participants
"""
player = ParticipantLayer(connection)
participant_phenotypes = await player.get_phenotypes_for_participants(
participant_ids=participant_ids
)
return [participant_phenotypes.get(pid, {}) for pid in participant_ids]


async def get_context(
request: Request, connection=get_projectless_db_connection
): # pylint: disable=unused-argument
"""Get loaders / cache context for strawberyy GraphQL"""
mapped_loaders = {k: fn(connection) for k, fn in loaders.items()}
return {
Expand Down
Loading

0 comments on commit a61b39c

Please sign in to comment.