diff --git a/Makefile b/Makefile index 1549bb0..8cb3945 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ endif # basename of a YAML file in model/ -.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status +.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status lint lint-python lint-fix-python # note: "help" MUST be the first target in the file, # when the user types "make" they should get help info @@ -148,6 +148,14 @@ test-python: lint: $(RUN) linkml-lint $(SOURCE_SCHEMA_PATH) +lint-python: + $(RUN) ruff format --check + $(RUN) ruff check + +lint-fix-python: + $(RUN) ruff check --fix + $(RUN) ruff format + check-config: ifndef LINKML_SCHEMA_NAME $(error **Project not configured**:\n\n - See '.env.public'\n\n) diff --git a/poetry.lock b/poetry.lock index 8effebc..458be53 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "annotated-types" @@ -1600,13 +1600,13 @@ requests = ">=2.28.1,<3.0.0" [[package]] name = "prefixmaps" -version = "0.2.4" +version = "0.2.5" description = "A python library for retrieving semantic prefix maps" optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "prefixmaps-0.2.4-py3-none-any.whl", hash = "sha256:89bf0e6fb08c276f754f9624c42adf2e87c64ee92a3dde1f7eff01f22d85b512"}, - {file = "prefixmaps-0.2.4.tar.gz", hash = "sha256:ae86a1b31189d0516d199756d5808f75f44b39e86546c356cc78c0fe8d2078af"}, + {file = "prefixmaps-0.2.5-py3-none-any.whl", hash = "sha256:68caa04b3a6a8e058aa1c55affe32c62e44b564d031d63f768e267b796a1f3ee"}, + {file = "prefixmaps-0.2.5.tar.gz", hash = "sha256:aaccd2425ade2ea97a502c58be49fe8f3536e3d5e919712ae0358a39fc800799"}, ] [package.dependencies] @@ -2399,6 +2399,33 @@ files = [ {file = "ruamel.yaml.clib-0.2.8.tar.gz", hash = "sha256:beb2e0404003de9a4cab9753a8805a8fe9320ee6673136ed7f04255fe60bb512"}, ] +[[package]] +name = "ruff" +version = "0.6.9" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.6.9-py3-none-linux_armv6l.whl", hash = "sha256:064df58d84ccc0ac0fcd63bc3090b251d90e2a372558c0f057c3f75ed73e1ccd"}, + {file = "ruff-0.6.9-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:140d4b5c9f5fc7a7b074908a78ab8d384dd7f6510402267bc76c37195c02a7ec"}, + {file = "ruff-0.6.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:53fd8ca5e82bdee8da7f506d7b03a261f24cd43d090ea9db9a1dc59d9313914c"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:645d7d8761f915e48a00d4ecc3686969761df69fb561dd914a773c1a8266e14e"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eae02b700763e3847595b9d2891488989cac00214da7f845f4bcf2989007d577"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7d5ccc9e58112441de8ad4b29dcb7a86dc25c5f770e3c06a9d57e0e5eba48829"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:417b81aa1c9b60b2f8edc463c58363075412866ae4e2b9ab0f690dc1e87ac1b5"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3c866b631f5fbce896a74a6e4383407ba7507b815ccc52bcedabb6810fdb3ef7"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7b118afbb3202f5911486ad52da86d1d52305b59e7ef2031cea3425142b97d6f"}, + {file = "ruff-0.6.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a67267654edc23c97335586774790cde402fb6bbdb3c2314f1fc087dee320bfa"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3ef0cc774b00fec123f635ce5c547dac263f6ee9fb9cc83437c5904183b55ceb"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:12edd2af0c60fa61ff31cefb90aef4288ac4d372b4962c2864aeea3a1a2460c0"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_i686.whl", hash = "sha256:55bb01caeaf3a60b2b2bba07308a02fca6ab56233302406ed5245180a05c5625"}, + {file = "ruff-0.6.9-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:925d26471fa24b0ce5a6cdfab1bb526fb4159952385f386bdcc643813d472039"}, + {file = "ruff-0.6.9-py3-none-win32.whl", hash = "sha256:eb61ec9bdb2506cffd492e05ac40e5bc6284873aceb605503d8494180d6fc84d"}, + {file = "ruff-0.6.9-py3-none-win_amd64.whl", hash = "sha256:785d31851c1ae91f45b3d8fe23b8ae4b5170089021fbb42402d811135f0b7117"}, + {file = "ruff-0.6.9-py3-none-win_arm64.whl", hash = "sha256:a9641e31476d601f83cd602608739a0840e348bda93fec9f1ee816f8b6798b93"}, + {file = "ruff-0.6.9.tar.gz", hash = "sha256:b076ef717a8e5bc819514ee1d602bbdca5b4420ae13a9cf61a0c0a4f53a2baa2"}, +] + [[package]] name = "schemasheets" version = "0.1.24" @@ -2892,4 +2919,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "8e13c7f80b53b48f10b7a73b8a696fda2b6b3d8eb86da0b92afc8a984269f3a6" +content-hash = "b2439849426ac3c0b57afe613cf67c147e8f2bc89b844132d99a363b5c64a509" diff --git a/pyproject.toml b/pyproject.toml index e1558be..4dc27eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ python = "^3.9" click = "^8" linkml-runtime = "^1.1.24" ndex2 = "^3.9.0" +prefixmaps = "^0.2.5" pydantic = "^2" pyyaml = "^6" requests = "^2" @@ -20,6 +21,7 @@ requests = "^2" linkml = "^1.3.5" mkdocs-material = "^8.2.8" mkdocs-mermaid2-plugin = ">=1.1.1" +ruff = "^0.6.9" schemasheets = "^0.1.14" [tool.poetry.group.test.dependencies] @@ -42,3 +44,12 @@ gocam = "gocam.cli:cli" markers = [ "integration" ] + +[tool.ruff] +exclude = [ + "project", + "src/gocam/datamodel" +] + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "I"] diff --git a/src/gocam/__init__.py b/src/gocam/__init__.py index 651774b..1bb9546 100644 --- a/src/gocam/__init__.py +++ b/src/gocam/__init__.py @@ -1 +1 @@ -from gocam._version import __version__ +from gocam._version import __version__ as __version__ diff --git a/src/gocam/_version.py b/src/gocam/_version.py index fe5022e..ca910c2 100644 --- a/src/gocam/_version.py +++ b/src/gocam/_version.py @@ -1,4 +1,4 @@ -from importlib.metadata import version, PackageNotFoundError +from importlib.metadata import PackageNotFoundError, version try: __version__ = version(__package__) diff --git a/src/gocam/cli.py b/src/gocam/cli.py index 78288f7..6f2a15b 100644 --- a/src/gocam/cli.py +++ b/src/gocam/cli.py @@ -135,7 +135,9 @@ def convert(model, input_format, output_format, output, ndex_upload): # Make the network searchable client.set_network_system_properties(network_id, {"index_level": "META"}) - click.echo(f"View network at: 'https://www.ndexbio.org/viewer/networks/{network_id}") + click.echo( + f"View network at: 'https://www.ndexbio.org/viewer/networks/{network_id}" + ) else: click.echo(json.dumps(cx2), file=output) diff --git a/src/gocam/translation/__init__.py b/src/gocam/translation/__init__.py index fb2b2d0..a7c7469 100644 --- a/src/gocam/translation/__init__.py +++ b/src/gocam/translation/__init__.py @@ -1 +1 @@ -from gocam.translation.minerva_wrapper import MinervaWrapper +from gocam.translation.minerva_wrapper import MinervaWrapper as MinervaWrapper diff --git a/src/gocam/translation/cx2/__init__.py b/src/gocam/translation/cx2/__init__.py index 01878d5..f33aac2 100644 --- a/src/gocam/translation/cx2/__init__.py +++ b/src/gocam/translation/cx2/__init__.py @@ -1 +1 @@ -from gocam.translation.cx2.main import model_to_cx2 +from gocam.translation.cx2.main import model_to_cx2 as model_to_cx2 diff --git a/src/gocam/translation/cx2/main.py b/src/gocam/translation/cx2/main.py index a96484a..286c4c9 100644 --- a/src/gocam/translation/cx2/main.py +++ b/src/gocam/translation/cx2/main.py @@ -1,7 +1,10 @@ +import json import logging import re +from functools import cache from typing import Dict, List, Optional, Union +import prefixmaps from ndex2.cx2 import CX2Network from gocam.datamodel import ( @@ -50,13 +53,17 @@ def _remove_species_code_suffix(label: str) -> str: return label +@cache +def _get_context(): + return prefixmaps.load_context("go").as_dict() + + # Regex from # https://github.com/ndexbio/ndex-enrichment-rest/wiki/Enrichment-network-structure#via-node-attributes-preferred-method IQUERY_GENE_SYMBOL_PATTERN = re.compile("(^[A-Z][A-Z0-9-]*$)|(^C[0-9]+orf[0-9]+$)") def model_to_cx2(gocam: Model) -> list: - # Internal state input_output_nodes: Dict[str, int] = {} activity_nodes: Dict[str, int] = {} @@ -101,6 +108,7 @@ def _add_input_output_nodes( cx2_network = CX2Network() cx2_network.set_network_attributes( { + "@context": json.dumps(_get_context()), "name": gocam.title if gocam.title is not None else gocam.id, "represents": gocam.id, }