Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

style: add new linting checks #34

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [ main ]
Copy link
Contributor

@korikuzma korikuzma Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we only want to run CI on the main branch? I think it's nice when pushing to a branch to see if checks pass before I open a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that makes sense

pull_request:
branches: [ main ]

jobs:
style:
name: Check style
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: python3 -m pip install ".[dev]"

- name: Ruff checks
run: python3 -m ruff check .

- name: isort checks
run: python3 -m isort --check .
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.244
hooks:
- id: ruff
- repo: https://github.com/pycqa/isort
rev: 5.6.4
hooks:
- id: isort
args: ["--check"]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"module": "anyvar.restapi"
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"python.formatting.provider": "yapf"
}
}
22 changes: 13 additions & 9 deletions bin/cv-load-timing
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import logging
import os
import sys

from biocommons.seqrepo import SeqRepo
from bioutils.exceptions import BioutilsError
import coloredlogs
import redis
import tqdm
from biocommons.seqrepo import SeqRepo
from bioutils.exceptions import BioutilsError
from ga4gh.vrs import models
from ga4gh.vrs.dataproxy import SeqRepoDataProxy
from hgvs.exceptions import HGVSParseError
import tqdm

from anyvar import AnyVar
from anyvar.translator import Translator
from anyvar.extras.clinvarparser import ClinvarParser
from anyvar.storage.redisobjectstore import RedisObjectStore

from anyvar.translator import Translator

_logger = logging.getLogger(__name__)

Expand All @@ -30,7 +29,7 @@ def firstn(gen, n=None):
yield e
if i == n:
break



if __name__ == "__main__":
Expand All @@ -55,17 +54,22 @@ if __name__ == "__main__":
n_cvrec = 0
n_exc = 0
for cvrec in pbar:
#_logger.info(f"{cvrec.accession}; {cvrec.record_type}; {len(cvrec.hgvs_expressions)} hgvs expressions")
#_logger.info(
# f"{cvrec.accession}; {cvrec.record_type}; {len(cvrec.hgvs_expressions)} "
# "hgvs expressions"
# )
n_cvrec += 1
n_hgvs += len(cvrec.hgvs_expressions)
if n_cvrec % 10 == 0:
pbar.set_description(f"{n_hgvs} hgvs expressions")
for he in cvrec.hgvs_expressions:
try:
v = tlr.from_hgvs(he)
except (ValueError, HGVSParseError, AttributeError, KeyError, BioutilsError):
except (
ValueError, HGVSParseError, AttributeError, KeyError, BioutilsError
):
v = models.Text(definition=he)
_id = av.put_object(v)
#_logger.info(f"stored {_id} for {he}")
_logger.info(f"stored {_id} for {he}")

_logger.info(f"{n_hgvs} hgvs expressions in {n_cvrec} clinvar records")
4 changes: 2 additions & 2 deletions docker-build
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ tag=$(git describe --tags)
e docker build -t $imagename:$tag "$@" .
e docker push $imagename:$tag

e docker tag $imagename:$tag $imagename:latest
e docker push $imagename:latest
e docker tag $imagename:$tag $imagename:latest
e docker push $imagename:latest
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- seqrepo-rest-service
# - uta
#environment:
# # UTA_DB_URL:
# # UTA_DB_URL:
# # SEQREPO_REST_SERVICE_URL:

redis:
Expand All @@ -28,7 +28,7 @@ services:
volumes:
- anyvar_redis_vol:/data

seqrepo-rest-service:
seqrepo-rest-service:
# Test: curl http://localhost:5000/seqrepo/1/sequence/refseq:NM_000551.3
expose:
- 5000
Expand All @@ -37,7 +37,7 @@ services:
image: biocommons/seqrepo-rest-service:latest
volumes:
- seqrepo_vol:/usr/local/share/seqrepo

# uta:
# # Test:
# # psql -XAt postgres://anonymous@localhost/uta -c 'select count(*) from transcript'
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.ruff]
exclude = [
"venv",
"build",
"dist",
"tests"
]

line-length = 88

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

[tool.isort]
group_by_package = true
12 changes: 4 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ exclude =

[options.extras_require]
dev =
ipython
ruff
pre-commit
isort
test =
pytest
pytest-cov
pytest-mock


[aliases]
Expand All @@ -47,12 +50,5 @@ universal = 1
[build_sphinx]
all_files = 1

# http://pep8.readthedocs.org/en/latest/intro.html#error-codes
[flake8]
max-line-length = 120
exclude = tests/*
max-complexity = 10
ignore = E129,E221,E241,E251,E303,W291

[tool:pytest]
addopts = --cov=anyvar --cov-report term-missing
7 changes: 4 additions & 3 deletions src/anyvar/anyvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@

"""

from collections.abc import MutableMapping
import logging
from collections.abc import MutableMapping

from ga4gh.core import ga4gh_identify
from ga4gh.vrs import models, vrs_deref, vrs_enref

from anyvar.translate.translate import _Translator


_logger = logging.getLogger(__name__)


class AnyVar:
def __init__(self, /, translator: _Translator, object_store: MutableMapping):
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 Down
13 changes: 8 additions & 5 deletions src/anyvar/extras/clinvarparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import lxml.etree as le


_logger = logging.getLogger()


class VariationArchive:
def __init__(self, element):
assert element.tag == "VariationArchive", "Expected node type `VariationArchive`"
assert element.tag == "VariationArchive", \
"Expected node type `VariationArchive`"
self._element = element

@property
Expand Down Expand Up @@ -39,15 +39,15 @@ def record_type(self):
@property
def variation_name(self):
return self._element.get("VariationName")

@property
def variation_type(self):
return self._element.get("VariationType")

@property
def version(self):
return self._element.get("Version")

@property
def xrefs(self):
return [e.attrib for e in self._element.xpath(".//XRefList/XRef")]
Expand Down Expand Up @@ -75,4 +75,7 @@ def clinvar_open(fp):
import sys
fn = sys.argv[1]
for va in clinvar_open(fn):
print(f"{va.acv}\t{va.variation_name}\t{va.variation_type}\t{len(va.hgvs_expressions)}\t{len(va.xrefs)}")
print(
f"{va.acv}\t{va.variation_name}\t{va.variation_type}\t"
f"{len(va.hgvs_expressions)}\t{len(va.xrefs)}"
)
1 change: 0 additions & 1 deletion src/anyvar/restapi/_data/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,3 @@ components:
length: 248956422
alphabet: ACGMNRT
added: 2016-08-27T21:17:00Z

7 changes: 4 additions & 3 deletions src/anyvar/restapi/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from typing import Any, Callable, Optional

from flask import current_app
from ga4gh.vrs.dataproxy import create_dataproxy, _DataProxy
from anyvar.translate.translate import TranslatorSetupException
from ga4gh.vrs.dataproxy import _DataProxy, create_dataproxy

from anyvar.translate.variation_normalizer import VariationNormalizerRestTranslator
from anyvar.translate.translate import TranslatorSetupException
from anyvar.translate.variation_normalizer import \
VariationNormalizerRestTranslator

from ..anyvar import AnyVar
from ..storage import create_storage
Expand Down
4 changes: 3 additions & 1 deletion src/anyvar/restapi/routes/allele.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def put(body):
except TranslationException:
result["messages"].append(f"Unable to translate {defn}")
except NotImplementedError:
result["messages"].append(f"Variation class for {defn} is currently unsupported.")
result["messages"].append(
f"Variation class for {defn} is currently unsupported."
)
else:
v_id = av.put_object(v)
result["object"] = v.as_dict()
Expand Down
4 changes: 2 additions & 2 deletions src/anyvar/restapi/routes/find_alleles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from connexion import NoContent
from anyvar.storage.postgres import PostgresObjectStore

from ..globals import get_anyvar
from anyvar.storage.postgres import PostgresObjectStore


def get_ga4gh_alias(seqrepo_data_proxy, accession):
md = seqrepo_data_proxy.get_metadata(accession)
Expand Down
4 changes: 1 addition & 3 deletions src/anyvar/restapi/routes/info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from connexion import NoContent

import anyvar
import ga4gh.vrs

import anyvar


def search():
Expand Down
3 changes: 1 addition & 2 deletions src/anyvar/restapi/routes/sequence.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from ..globals import get_dataproxy
from .utils import get_sequence_ids, problem
from .utils import problem

_logger = logging.getLogger(__name__)

Expand All @@ -12,4 +12,3 @@ def get(alias, start=None, end=None):
return problem(422, "Invalid coordinates: start > end")
dp = get_dataproxy()
return dp.get_sequence(alias, start, end), 200

4 changes: 0 additions & 4 deletions src/anyvar/restapi/routes/sequence_metadata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import logging

from connexion import NoContent

from ..globals import get_dataproxy
from .utils import get_sequence_ids, problem


_logger = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions src/anyvar/restapi/routes/summary_statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..globals import get_anyvar


def get(vartype):
av = get_anyvar()
if vartype == "substitution":
Expand Down
4 changes: 1 addition & 3 deletions src/anyvar/restapi/routes/text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from connexion import NoContent

from ..globals import get_anyvar


Expand All @@ -8,7 +6,7 @@ def put(body):
request = body
defn = request.pop("definition")
v = av.create_text(defn)
id = av.put_object(v)
av.put_object(v)
result = {
"object": v.as_dict(),
"messages": [],
Expand Down
Loading