Skip to content

Commit

Permalink
Merge pull request #27 from TheJacksonLaboratory/G3-208-batch-upload-…
Browse files Browse the repository at this point in the history
…database-functions

G3 208 Setup and cleanup before adding batch upload database functions
  • Loading branch information
bergsalex authored Mar 19, 2024
2 parents 1a0fd3f + 4648f84 commit 5c82155
Show file tree
Hide file tree
Showing 87 changed files with 257 additions and 57 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/_check-coverage-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,30 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: coverage-report-html
path: htmlcov
path: htmlcov
- name: Upload coverage to Compass
run: |
METRIC_VALUE=$(cat coverage_report.txt | grep 'Total coverage:' | awk '{print $NF}' | sed 's/%//')
curl --request POST \
--url https://jacksonlaboratory.atlassian.net/gateway/api/compass/v1/metrics \
--user "${{ vars.ATLASSIAN_COMPASS_EMAIL }}:${{ secrets.ATLASSIAN_COMPASS_KEY }}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "{
\"metricSourceId\": \"ari:cloud:compass:44257862-6c68-4d47-8211-da38d2bb001b:metric-source/90bb0329-f6c5-429a-abbc-8d174535ad21/a96140ef-9d79-4015-bb9f-68989e182d48\",
\"value\": $METRIC_VALUE,
\"timestamp\": \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"
}"
- name: Upload complexity to Compass
run: |
METRIC_VALUE=$(poetry run radon cc src --total-average | grep 'Average complexity:' | awk '{print $NF}' | sed 's/[\(\)]//g')
curl --request POST \
--url https://jacksonlaboratory.atlassian.net/gateway/api/compass/v1/metrics \
--user "${{ vars.ATLASSIAN_COMPASS_EMAIL }}:${{ secrets.ATLASSIAN_COMPASS_KEY }}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "{
\"metricSourceId\": \"ari:cloud:compass:44257862-6c68-4d47-8211-da38d2bb001b:metric-source/90bb0329-f6c5-429a-abbc-8d174535ad21/6f106703-9bc2-49fc-a65e-4f914b9bf878\",
\"value\": $METRIC_VALUE,
\"timestamp\": \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"
}"
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
check-coverage:
uses: ./.github/workflows/_check-coverage-action.yml
secrets: inherit
with:
required-coverage: ${{ vars.REQUIRED_COVERAGE }}
coverage-module: "geneweaver.db"
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,56 @@
The Geneweaver DB library provides database access functionality for the Geneweaver
project. The library contains SQL queries wrapped in standard python functions, as well
as a database connection manager.


## Installation

To install the Geneweaver DB library, run one of the following commands:

#### Using Pip
```
pip install geneweaver-db
```

#### Using Poetry
```
poetry add geneweaver-db
```

## Usage
The Geneweaver DB library is intended to be used as a dependency for other Geneweaver
packages, but can also be used as a stand-alone pacakge.

The package has three main sections:
- `geneweaver.db` - contains non-async database functions.
- `geneweaver.db.aio` - contains async database functions.
- `geneweaver.db.query` - contains SQL queries and SQL generation functions.

Database functions _usually_ take a `Cursor` or `AsyncCursor` object as their first
argument.

### Non-Async Functions
```python
import psycopg
import geneweaver
from geneweaver.db.core.settings import settings

def get_my_gene():
with psycopg.connect(settings.URI) as conn:
with conn.cursor() as cur:
result = geneweaver.db.gene.get(cur, 'my_gene')
return result
```

### Async Functions
```python
import psycopg
import geneweaver
from geneweaver.db.core.settings import settings

async def get_my_gene():
async with psycopg.AsyncConnection.connect(settings.URI) as conn:
async with conn.cursor() as cur:
result = await geneweaver.db.aio.gene.get(cur, 'my_gene')
return result
```
138 changes: 87 additions & 51 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poetry]
name = "geneweaver-db"
version = "0.3.0a13"
version = "0.3.0a14"
description = "Database Interaction Services for GeneWeaver"
authors = ["Jax Computational Sciences <[email protected]>"]
readme = "README.md"
license = "Apache-2.0"
homepage = "https://bergsalex.github.io/geneweaver-docs/"
repository = "https://bitbucket.org/jacksonlaboratory/geneweaver-db"
homepage = "https://thejacksonlaboratory.github.io/geneweaver-docs/"
repository = "https://github.com/TheJacksonLaboratory/geneweaver-db"
packages = [
{ include = "geneweaver/db", from = "src" },
]
Expand All @@ -19,7 +19,7 @@ psycopg = {extras = ["binary"], version = "^3.1.13"}


[tool.poetry.group.dev.dependencies]
geneweaver-testing = "^0.0.3"
geneweaver-testing = "^0.1.2"
pytest-asyncio = "^0.23.5"

[tool.ruff]
Expand Down
3 changes: 3 additions & 0 deletions src/geneweaver/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
"""The root of the geneweaver database package."""

# ruff: noqa: F401
from geneweaver.db import aio, exceptions, gene, geneset, publication, species, user
Loading

0 comments on commit 5c82155

Please sign in to comment.