Skip to content

Commit

Permalink
🔀 fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalebi committed Feb 29, 2024
2 parents 2ab35fc + e7820ee commit e66cde5
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 82 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/pytest.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
# Workflow name
name: PyTest and Black
name: PyTest, Black and Pylint

# Controls when the workflow will run
on:
# Triggers the workflow on pull request (on main only) events
# Triggers the workflow on pull request (on main and develop only) events
pull_request:
branches:
- main
- develop

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "test"
test:
# This workflow contains a single job called "tests"
tests:
# The type of runner that the job will run on and timeout in minutes
name: Run Python Tests and Black formatter
name: Run Python Tests, Black formatter and Pylint
runs-on: ubuntu-latest
timeout-minutes: 10

# Include a strategy matrix in order to allow the job to run multiple times with different versions of Python
strategy:
matrix:
python-version: [3.8, 3.9]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out our repository under $GITHUB_WORKSPACE, so our job can access it
- name: Check out repository code
uses: actions/checkout@v3

# Set up Python version
- name: Set up Python 3.7
# Set up Python version from the matrix
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: ${{ matrix.python-version }}

# Runs a set of commands installing Python dependencies using the runners shell (Run a multi-line script)
- name: Install Python dependencies
Expand All @@ -47,4 +53,9 @@ jobs:
# Check code has been formatted
- name: Run Black code formatter
run: |
black . --check --verbose --diff --color
black . --check --verbose --diff --color
# Run Pylint
- name: Run Pylint
run: |
pylint $(git ls-files '*.py') --fail-under=9.5
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[MASTER]
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
max-line-length=120
ignore-paths=^graphql_service/tests/snapshots/.*$,
^graphql_service/tests/fixtures/.*$

disable=missing-class-docstring, missing-function-docstring, line-too-long
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Ensembl
Copyright [2020-2023] EMBL-European Bioinformatics Institute
Copyright [2020-2024] EMBL-European Bioinformatics Institute

This product includes software developed at:
- EMBL-European Bioinformatics Institute
8 changes: 4 additions & 4 deletions common/crossrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def _index_identifiers_org_data(self):
Provide prefix-based indexes for the flat list of entities from
the identifiers.org api
"""
for ns in self.identifiers_org_data["payload"]["namespaces"]:
self.id_org_indexed[ns["prefix"]] = ns
for namespace in self.identifiers_org_data["payload"]["namespaces"]:
self.id_org_indexed[namespace["prefix"]] = namespace

def generate_url_from_id_org_data(self, xref_acc_id, id_org_ns_prefix):
"""
Expand Down Expand Up @@ -204,9 +204,9 @@ def find_url_using_ens_xref_db_name(self, xref_acc_id, xref_db_name):
return xref_base + xref_acc_id

# Now get the URL from identifiers.org using the id_org_ns_prefix and xref_id
URL = self.generate_url_from_id_org_data(xref_acc_id, id_org_ns_prefix)
url = self.generate_url_from_id_org_data(xref_acc_id, id_org_ns_prefix)

return URL
return url

def annotate_crossref(self, xref):
"""
Expand Down
2 changes: 0 additions & 2 deletions common/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self, config):
Note that config here is a configparser object
"""
self.config = config
# self.mongo_db = MongoDbClient.connect_mongo(self.config)
self.mongo_client = MongoDbClient.connect_mongo(self.config)

def get_database_conn(self, grpc_model, uuid):
Expand Down Expand Up @@ -66,7 +65,6 @@ def connect_mongo(config):
port = int(config.get("mongo_port"))
user = config.get("mongo_user")
password = config.get("mongo_password")
# dbname = config.get("mongo_default_db")

client = pymongo.MongoClient(
host,
Expand Down
8 changes: 7 additions & 1 deletion common/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from ariadne.types import Extension, ContextValue

from common import utils


class QueryExecutionTimeExtension(Extension):
def __init__(self):
Expand All @@ -29,4 +31,8 @@ def format(self, context):
exec_time_in_secs = round(
(time.perf_counter_ns() - self.start_timestamp) / 1000000000, 2
)
return {"execution_time_in_seconds": exec_time_in_secs}
return {
"execution_time_in_seconds": exec_time_in_secs,
"metadata_api_version": utils.get_ensembl_metadata_api_version(),
}
return None
19 changes: 17 additions & 2 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def check_config_validity(config):
MANDATORY_FIELDS = [
mandatory_fields = [
"mongo_host",
"mongo_port",
"mongo_user",
Expand All @@ -23,8 +23,23 @@ def check_config_validity(config):
"grpc_host",
"grpc_port",
]
for mandatory_field in MANDATORY_FIELDS:
for mandatory_field in mandatory_fields:
if not config.get(mandatory_field):
raise KeyError(
f"Missing information in configuration file - '{mandatory_field}'"
)


def get_ensembl_metadata_api_version():
"""
Get the Metadata API tag from requirement.txt file
"""
version = "unknown" # default version
with open("requirements.txt", "r", encoding="UTF-8") as file:
lines = file.readlines()
for line in lines:
if "ensembl-metadata-api" in line:
# Extract the tag part from the line
version = line.strip().split("@")[-1]
break
return version
20 changes: 10 additions & 10 deletions graphql_service/resolver/gene_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
DatabaseNotFoundError,
)

from pymongo.collection import Collection

logger = logging.getLogger(__name__)

Expand All @@ -66,7 +65,7 @@
def resolve_gene(
_,
info: GraphQLResolveInfo,
byId: Optional[Dict[str, str]] = None,
byId: Optional[Dict[str, str]] = None, # pylint: disable=invalid-name
by_id: Optional[Dict[str, str]] = None,
) -> Dict:
"Load Gene via stable_id"
Expand Down Expand Up @@ -196,13 +195,14 @@ def insert_gene_name_urls(gene_metadata: Dict, info: GraphQLResolveInfo) -> Dict
def resolve_transcript(
_,
info: GraphQLResolveInfo,
bySymbol: Optional[Dict[str, str]] = None,
bySymbol: Optional[Dict[str, str]] = None, # pylint: disable=invalid-name
by_symbol: Optional[Dict[str, str]] = None,
byId: Optional[Dict[str, str]] = None,
byId: Optional[Dict[str, str]] = None, # pylint: disable=invalid-name
by_id: Optional[Dict[str, str]] = None,
) -> Dict:
"Load Transcripts by symbol or stable_id"


if by_symbol is None:
by_symbol = bySymbol
if by_id is None:
Expand Down Expand Up @@ -267,8 +267,8 @@ def resolve_api(
try:
version_details = get_version_details()
return {"api": version_details}
except Exception as e:
logging.error(f"Error resolving API version: {e}")
except Exception as exp:
logging.error(f"Error resolving API version: {exp}")
raise


Expand Down Expand Up @@ -385,8 +385,8 @@ async def resolve_transcript_gene(transcript: Dict, info: GraphQLResolveInfo) ->
def resolve_overlap(
_,
info: GraphQLResolveInfo,
genomeId: Optional[str] = None,
regionName: Optional[str] = None,
genomeId: Optional[str] = None, # pylint: disable=invalid-name
regionName: Optional[str] = None, # pylint: disable=invalid-name
start: Optional[int] = None,
end: Optional[int] = None,
by_slice: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -777,8 +777,8 @@ def get_version_details() -> Dict[str, str]:
logging.error(
"Version section or keys not found in INI file. Using default values."
)
except Exception as e:
logging.error(f"Error reading INI file: {e}. Using default values.")
except Exception as exp:
logging.error(f"Error reading INI file: {exp}. Using default values.")

return {"major": "0", "minor": "1", "patch": "0-beta"}

Expand Down
Loading

0 comments on commit e66cde5

Please sign in to comment.