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

merge hackathon work #60

Merged
merged 10 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
24 changes: 0 additions & 24 deletions .github/workflows/ci.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Python package

on:
push:
pull_request:

jobs:
cqa:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip
cache-dependency-path: '**/setup.cfg'

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install --use-deprecated=legacy-resolver -e .[dev]

- name: Lint with Ruff
run: python3 -m ruff check src/

- name: Format check with black
run: black --check src

- name: Security check with bandit
run: bandit -ll -r src

12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.244
rev: v0.0.290
hooks:
- id: ruff
- repo: https://github.com/pycqa/isort
rev: 5.6.4
hooks:
- id: isort
args: ["--check"]
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SELF:=$(firstword $(MAKEFILE_LIST))

PKG=eutils
PKGD=$(subst .,/,${PKG})
PYV:=3.8
PYV:=3.11
VEDIR=venv/${PYV}

UNAME = $(shell uname)
Expand Down Expand Up @@ -64,6 +64,12 @@ bdist bdist_egg bdist_wheel build sdist install: %:
#= TESTING
# see test configuration in setup.cfg

#=> cqa: execute code quality tests
cqa:
ruff check src
black --check src
bandit -ll -r src

#=> test: execute tests
.PHONY: test
test:
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ Point `ANYVAR_STORAGE_URI` to an available PostgreSQL database:
export ANYVAR_STORAGE_URI=postgresql://postgres@localhost:5432/anyvar
```

Set `ANYVAR_VARIATION_NORMALIZER_URI` to the address of a running Variation Normalizer process:
Set `SEQREPO_DATAPROXY_URI` to local SeqRepo files or to a REST service instance:

```
export ANYVAR_VARIATION_NORMALIZER_URI=http://localhost:7999/variation
export SEQREPO_DATAPROXY_URI=seqrepo+file:///usr/local/share/seqrepo/latest
# or
export SEQREPO_DATAPROXY_URI=seqrepo+http://localhost:5000/seqrepo
```

Start the AnyVar server:
Expand All @@ -44,15 +46,15 @@ uvicorn anyvar.restapi.main:app --reload
Or, more simply:

make devready
source venv/bin/activate
source venv/3.11/bin/activate

Then, start the REST server with:

python -m anyvar.restapi
uvicorn anyvar.restapi.main:app

In another terminal:

curl http://localhost:5000/info
curl http://localhost:8000/info


### Setting up Postgres
Expand All @@ -63,7 +65,7 @@ Postgres instance.

First, run the commands in (README-pg.md)[src/anyvar/storage/README-pg.md]. This will create and start a local Postgres docker instance.

Next, run the commands in (postgres_init.sql)[src/anyvar/storage/postgres_init.sql]. This will create the `anyvar` user with the appropriate permissions and create the `anyvar_db` database.
Next, run the commands in (postgres_init.sql)[src/anyvar/storage/postgres_init.sql]. This will create the `anyvar` user with the appropriate permissions and create the `anyvar` database.

## Deployment

Expand Down
68 changes: 63 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
[project]
name = "biocommons.anyvar"
authors = [
{ name="biocommons contributors", email="biocommons-dev@googlegroups.com" },
]
description = "AnyVar provides Python and REST interfaces to validate, normalize, generate identifiers, and register biological sequence variation according to the GA4GH Variation Representation standards."
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dynamic = ["version"]

[project.urls]
"Homepage" = "https://github.com/biocommons/anyvar"
"Bug Tracker" = "https://github.com/biocommons/anyvar/issues"


[build-system]
requires = [
"setuptools >= 65.3",
"setuptools_scm[toml] ~= 7.0"
]
build-backend = "setuptools.build_meta"


[tool.setuptools_scm]


[tool.coverage.run]
branch = true
source = ["biocommons.example"]
omit = ["*_test.py", "*/test/*", "*/tests/*"]


[tool.coverage.report]
show_missing = true
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",

# Don't complain about missing debug-only code:
"def __repr__",
"if self.debug",

# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",

# Don't complain if non-runnable code isn't run:
"if __name__ == .__main__.:",
]

[tool.black]
line-length = 100

[tool.ruff]
exclude = [
"venv",
Expand All @@ -6,11 +68,7 @@ exclude = [
"tests"
]

line-length = 88
line-length = 100

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401", "E402"]
"uidoc.py" = ["E501"]

[tool.isort]
group_by_package = true
41 changes: 11 additions & 30 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
[metadata]
name = anyvar
author = Reece Hart
author-email = reece@harts.net
description-file = README.rst
description-content-type = text/x-rst; charset=UTF-8

[options]
zip_safe = false
packages = find_namespace:
package_dir =
= src
install_requires =
canonicaljson
fastapi >= 0.95.0
Expand All @@ -15,11 +10,6 @@ install_requires =
ga4gh.vrs[extras] ~= 0.8.4
ga4gh.vrsatile.pydantic ~= 0.0.11
psycopg[binary]
setup_requires =
setuptools_scm
packages = find:
package_dir =
= src

[options.package_data]
* =
Expand All @@ -35,24 +25,15 @@ exclude =

[options.extras_require]
dev =
ruff
pre-commit
isort
black
ruff
pre-commit
bandit~=1.7
test =
pytest
pytest-cov
pytest-mock
httpx


[aliases]
test = pytest

[bdist_wheel]
universal = 1

[build_sphinx]
all_files = 1
pytest
pytest-cov
pytest-mock
httpx

[tool:pytest]
addopts = --cov=anyvar --cov-report term-missing
30 changes: 9 additions & 21 deletions src/anyvar/anyvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from ga4gh.vrs import vrs_deref, vrs_enref

from anyvar.storage import DEFAULT_STORAGE_URI, _Storage
from anyvar.translate.translate import (DEFAULT_TRANSLATE_URI,
TranslatorSetupException, _Translator)
from anyvar.translate.translate import _Translator
from anyvar.translate.vrs_python import VrsPythonTranslator
from anyvar.utils.types import VrsPythonObject

_logger = logging.getLogger(__name__)
Expand All @@ -35,6 +35,7 @@ def create_storage(uri: Optional[str] = None) -> _Storage:

if parsed_uri.scheme == "postgresql":
from anyvar.storage.postgres import PostgresObjectStore

storage = PostgresObjectStore(uri) # type: ignore

else:
Expand All @@ -44,24 +45,15 @@ def create_storage(uri: Optional[str] = None) -> _Storage:
return storage


def create_translator(uri: Optional[str] = None) -> _Translator:
def create_translator() -> _Translator:
"""Create variation translator middleware.

Currently accepts REST interface only -- we should at least enable a local
proxy instance in the future.
Try to build the VRS-Python wrapper class with default args. In the future, could
provide assistance constructing other kinds of translators.

:param uri: location listening for requests
:return: instantiated Translator instance
"""
if not uri:
uri = os.environ.get("ANYVAR_VARIATION_NORMALIZER_URI", DEFAULT_TRANSLATE_URI)
if not uri:
raise TranslatorSetupException("No Translator URI provided.")

from anyvar.translate.variation_normalizer import \
VariationNormalizerRestTranslator

return VariationNormalizerRestTranslator(uri)
return VrsPythonTranslator()


class AnyVar:
Expand All @@ -73,9 +65,7 @@ def __init__(self, /, translator: _Translator, object_store: _Storage):
:param object_store: Object storage instance
"""
if not isinstance(object_store, MutableMapping):
_logger.warning(
"AnyVar(object_store=) should be a mutable mapping; you're on your own"
)
_logger.warning("AnyVar(object_store=) should be a mutable mapping; you're on your own")

self.object_store = object_store
self.translator = translator
Expand All @@ -93,9 +83,7 @@ def put_object(self, variation_object: VrsPythonObject) -> Optional[str]:
_id = ga4gh_identify(v)
return _id

def get_object(
self, object_id: str, deref: bool = False
) -> Optional[VrsPythonObject]:
def get_object(self, object_id: str, deref: bool = False) -> Optional[VrsPythonObject]:
"""Retrieve registered variation.

:param object_id: object identifier
Expand Down
Loading