Skip to content

Commit

Permalink
ci: incorporate more style check and package build elements from Bioc…
Browse files Browse the repository at this point in the history
…ommons template (#58)
  • Loading branch information
jsstevenson authored Sep 18, 2023
1 parent 44ede49 commit b444778
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 306 deletions.
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.10"
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"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
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
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="[email protected]" },
]
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 = [email protected]
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
9 changes: 3 additions & 6 deletions src/anyvar/anyvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -64,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 @@ -84,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
12 changes: 7 additions & 5 deletions src/anyvar/extras/clinvarparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

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 @@ -62,17 +61,20 @@ def __init__(self, fp, current_only=True):
self.current_only = current_only

def __iter__(self):
yield from (va for va in (VariationArchive(e) for _, e in self._xp)
if not self.current_only or va.is_current)
yield from (
va
for va in (VariationArchive(e) for _, e in self._xp)
if not self.current_only or va.is_current
)


def clinvar_open(fp):
yield from ClinvarParser(fp)



if __name__ == "__main__":
import sys

fn = sys.argv[1]
for va in clinvar_open(fn):
print(
Expand Down
18 changes: 13 additions & 5 deletions src/anyvar/extras/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ def __init__(self, av: AnyVar) -> None:
self.av = av

def annotate(
self, vcf_in: str, vcf_out: Optional[str] = None,
vrs_pickle_out: Optional[str] = None, assembly: str = "GRCh38",
self,
vcf_in: str,
vcf_out: Optional[str] = None,
vrs_pickle_out: Optional[str] = None,
assembly: str = "GRCh38",
) -> None:
"""Annotates an input VCF file with VRS Allele IDs & creates a pickle file
containing the vrs object information.
Expand All @@ -42,9 +45,14 @@ def annotate(
super().annotate(vcf_in, vcf_out, vrs_pickle_out, assembly)

def _get_vrs_object(
self, vcf_coords: str, vrs_data: Dict, vrs_allele_ids: List[str], assembly: str,
vrs_data_key: Optional[str] = None, output_pickle: bool = True,
output_vcf: bool = False
self,
vcf_coords: str,
vrs_data: Dict,
vrs_allele_ids: List[str],
assembly: str,
vrs_data_key: Optional[str] = None,
output_pickle: bool = True,
output_vcf: bool = False,
) -> None:
"""Get VRS Object given `vcf_coords`. `vrs_data` and `vrs_allele_ids` will
be mutated. Generally, we expect AnyVar to use the output_vcf option rather than
Expand Down
Loading

0 comments on commit b444778

Please sign in to comment.