Skip to content

Commit

Permalink
style: fix ruff settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Dec 12, 2023
1 parent c747340 commit c1d87ac
Show file tree
Hide file tree
Showing 30 changed files with 2,782 additions and 2,786 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: ruff
- id: ruff-format
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
88 changes: 44 additions & 44 deletions docs/scripts/generate_normalize_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from gene.schemas import UnmergedNormalizationService

COLORS = [
"#F8766D",
"#00BA38",
"#00B9E3",
'#F8766D',
'#00BA38',
'#00B9E3',
]


Expand All @@ -30,50 +30,50 @@ def create_gjgf(result: UnmergedNormalizationService) -> Dict:
:param result: result from Unmerged Normalization search
"""
graph = {
"graph": {
"label": "tmp",
"nodes": {},
"edges": [],
"metadata": {
"arrow_size": 15,
"node_size": 15,
"node_label_size": 20,
"edge_size": 2,
'graph': {
'label': 'tmp',
'nodes': {},
'edges': [],
'metadata': {
'arrow_size': 15,
'node_size': 15,
'node_label_size': 20,
'edge_size': 2,
},
}
}

for i, (source, matches) in enumerate(result.source_matches.items()):
for i, (_, matches) in enumerate(result.source_matches.items()):
for match in matches.records:
graph["graph"]["nodes"][match.concept_id] = {
"metadata": {
"color": COLORS[i],
"hover": f"{match.concept_id}\n{match.symbol}\n<i>{match.label}</i>", # noqa: E501
"click": f"<p color='black'>{json.dumps(match.model_dump(), indent=2)}</p>", # noqa: E501
graph['graph']['nodes'][match.concept_id] = {
'metadata': {
'color': COLORS[i],
'hover': f'{match.concept_id}\n{match.symbol}\n<i>{match.label}</i>',
'click': f"<p color='black'>{json.dumps(match.model_dump(), indent=2)}</p>",
}
}
for xref in match.xrefs:
graph["graph"]["edges"].append(
{"source": match.concept_id, "target": xref}
graph['graph']['edges'].append(
{'source': match.concept_id, 'target': xref}
)

included_edges = []
for edge in graph["graph"]["edges"]:
for edge in graph['graph']['edges']:
if (
edge["target"] in graph["graph"]["nodes"]
and edge["source"] in graph["graph"]["nodes"]
edge['target'] in graph['graph']['nodes']
and edge['source'] in graph['graph']['nodes']
):
included_edges.append(edge)
graph["graph"]["edges"] = included_edges
graph['graph']['edges'] = included_edges

included_nodes = {k["source"] for k in graph["graph"]["edges"]}.union(
{k["target"] for k in graph["graph"]["edges"]}
included_nodes = {k['source'] for k in graph['graph']['edges']}.union(
{k['target'] for k in graph['graph']['edges']}
)
new_nodes = {}
for key, value in graph["graph"]["nodes"].items():
for key, value in graph['graph']['nodes'].items():
if key in included_nodes:
new_nodes[key] = value
graph["graph"]["nodes"] = new_nodes
graph['graph']['nodes'] = new_nodes

return graph

Expand All @@ -82,45 +82,45 @@ def gen_norm_figure() -> None:
"""Generate normalized graph figure for docs."""
q = QueryHandler(create_db())

otx2p1 = "OTX2P1"
otx2p2 = "OTX2P2"
otx2p1 = 'OTX2P1'
otx2p2 = 'OTX2P2'

otx2p1_result = q.normalize_unmerged(otx2p1)
otx2p2_result = q.normalize_unmerged(otx2p2)

otx2p1_graph = create_gjgf(otx2p1_result)
otx2p2_graph = create_gjgf(otx2p2_result)

nodes = otx2p1_graph["graph"]["nodes"]
nodes.update(otx2p2_graph["graph"]["nodes"])
nodes = otx2p1_graph['graph']['nodes']
nodes.update(otx2p2_graph['graph']['nodes'])

graph = {
"graph": {
"label": f"Reference network for {otx2p1} and {otx2p2}",
"metadata": otx2p1_graph["graph"]["metadata"],
"nodes": nodes,
"edges": otx2p1_graph["graph"]["edges"] + otx2p2_graph["graph"]["edges"],
'graph': {
'label': f'Reference network for {otx2p1} and {otx2p2}',
'metadata': otx2p1_graph['graph']['metadata'],
'nodes': nodes,
'edges': otx2p1_graph['graph']['edges'] + otx2p2_graph['graph']['edges'],
}
}

fig = gv.d3(
data=graph,
graph_height=250,
node_hover_neighborhood=True,
node_label_font="arial",
node_label_font='arial',
)
fig.export_html(
(
APP_ROOT.parents[0]
/ "docs"
/ "source"
/ "_static"
/ "html"
/ "normalize_example.html"
/ 'docs'
/ 'source'
/ '_static'
/ 'html'
/ 'normalize_example.html'
).absolute(),
overwrite=True,
)


if __name__ == "__main__":
if __name__ == '__main__':
gen_norm_figure()
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
],
}
# -- autodoc things ----------------------------------------------------------
import os # noqa: E402
import sys # noqa: E402
import os
import sys

sys.path.insert(0, os.path.abspath("../../gene"))
autodoc_preserve_defaults = True

# -- get version -------------------------------------------------------------
from gene import __version__ # noqa: E402
from gene import __version__

version = __version__
release = version
Expand All @@ -77,7 +77,7 @@ def linkcode_resolve(domain, info):
if not info["module"]:
return None
filename = info["module"].replace(".", "/")
return f"https://github.com/cancervariants/gene-normalization/blob/main/{filename}.py" # noqa: E501
return f"https://github.com/cancervariants/gene-normalization/blob/main/{filename}.py"


# -- code block style --------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ When running the web server, enable hot-reloading on new code changes: ::
Style
-----

Code style is managed by `Ruff <https://github.com/astral-sh/ruff>`_ and `Black <https://github.com/psf/black>`_, and should be checked via pre-commit hook before commits. Final QC is applied with GitHub Actions to every pull request.
Code style is managed by `Ruff <https://github.com/astral-sh/ruff>`_, and should be checked via pre-commit hook before commits. Final QC is applied with GitHub Actions to every pull request.

Tests
-----
Expand Down
36 changes: 21 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,44 @@ exclude = ["docs/source/conf.py"]
# pycodestyle (E, W)
# Pyflakes (F)
# flake8-annotations (ANN)
# flake8-quotes (Q)
# pydocstyle (D)
# pep8-naming (N)
# isort (I)
select = ["E", "W", "F", "ANN", "Q", "D", "N", "I"]

select = ["E", "W", "F", "ANN", "D", "N", "I"]
fixable = ["I", "F401"]

# D203 - one-blank-line-before-class
# D205 - blank-line-after-summary
# D206 - indent-with-spaces*
# D213 - multi-line-summary-second-line
# D300 - triple-single-quotes
# D400 - ends-in-period
# D415 - ends-in-punctuation
# ANN101 - missing-type-self
# ANN003 - missing-type-kwargs
# E501 - line-too-long
ignore = ["D203", "D205", "D213", "D400", "D415", "ANN101", "ANN003", "E501"]
# E111 - indentation-with-invalid-multiple*
# E114 - indentation-with-invalid-multiple-comment*
# E117 - over-indented*
# E501 - line-too-long*
# W191 - tab-indentation*
# *ignored for compatibility with formatter
ignore = [
"D203", "D205", "D206", "D213", "D300", "D400", "D415",
"ANN101", "ANN003",
"E111", "E114", "E117", "E501",
"W191"
]

[tool.ruff.flake8-quotes]
docstring-quotes = "double"
[tool.ruff.format]
quote-style = "single"

[tool.ruff.per-file-ignores]
# ANN001 - missing-type-function-argument
# ANN102 - missing-type-cls
# ANN2 - missing-return-type
# ANN201 - Missing type annotation
# ANN102 - missing-type-cls
# D103 - Missing docstring in public function
# F821 - undefined-name
# F401 - unused-import
# I001 - Import block unsorted or unformatted
# D301 - escape-sequence-in-docstring
# N805 - invalid-first-argument-name-for-method
"tests/*" = ["ANN001", "ANN102", "ANN2"]
"*__init__.py" = ["F401"]
"gene/schemas.py" = ["ANN001", "ANN201", "N805"]
"docs/source/conf.py" = ["D100", "I001", "D103", "ANN201", "ANN001"]
"src/gene/schemas.py" = ["ANN001", "ANN201", "N805"]
"src/gene/cli.py" = ["D301"]
22 changes: 10 additions & 12 deletions src/gene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
from os import environ
from pathlib import Path

from .version import __version__ # noqa: F401

APP_ROOT = Path(__file__).resolve().parent

logging.basicConfig(
filename="gene.log", format="[%(asctime)s] - %(name)s - %(levelname)s : %(message)s"
filename='gene.log', format='[%(asctime)s] - %(name)s - %(levelname)s : %(message)s'
)
logger = logging.getLogger("gene")
logger = logging.getLogger('gene')
logger.setLevel(logging.DEBUG)
logger.handlers = []

logging.getLogger("boto3").setLevel(logging.INFO)
logging.getLogger("botocore").setLevel(logging.INFO)
logging.getLogger("urllib3").setLevel(logging.INFO)
logging.getLogger("python_jsonschema_objects").setLevel(logging.INFO)
logging.getLogger("biocommons.seqrepo.seqaliasdb.seqaliasdb").setLevel(logging.INFO)
logging.getLogger("biocommons.seqrepo.fastadir.fastadir").setLevel(logging.INFO)
logging.getLogger('boto3').setLevel(logging.INFO)
logging.getLogger('botocore').setLevel(logging.INFO)
logging.getLogger('urllib3').setLevel(logging.INFO)
logging.getLogger('python_jsonschema_objects').setLevel(logging.INFO)
logging.getLogger('biocommons.seqrepo.seqaliasdb.seqaliasdb').setLevel(logging.INFO)
logging.getLogger('biocommons.seqrepo.fastadir.fastadir').setLevel(logging.INFO)


SEQREPO_ROOT_DIR = Path(
environ.get("SEQREPO_ROOT_DIR", "/usr/local/share/seqrepo/latest")
environ.get('SEQREPO_ROOT_DIR', '/usr/local/share/seqrepo/latest')
)


Expand Down Expand Up @@ -61,5 +59,5 @@ class DownloadException(Exception): # noqa: N818
NAMESPACE_LOOKUP = {
v.value.lower(): NamespacePrefix[k].value
for k, v in SourceIDAfterNamespace.__members__.items()
if v.value != ""
if v.value != ''
}
Loading

0 comments on commit c1d87ac

Please sign in to comment.