Skip to content

Commit

Permalink
More ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Jan 23, 2025
1 parent c946244 commit 1dafe78
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 62 deletions.
7 changes: 1 addition & 6 deletions libraries/client/biomodels_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
Script to get Biomodels project info
"""

import sys
import json

import osb
import operator
import pprint
from loadbiomodels import get_model_identifiers, get_model_info

verbose = True #
verbose = False

info_all = {}

from loadbiomodels import get_model_identifiers, get_model_info


if __name__ == "__main__":
min_index = 0
Expand Down
16 changes: 8 additions & 8 deletions libraries/client/cached_info/osb_gh.json
Original file line number Diff line number Diff line change
Expand Up @@ -209517,8 +209517,8 @@
"name": "OSBv2",
"node_id": "MDEwOlJlcG9zaXRvcnkyNDMzMTY0MTM=",
"notifications_url": "https://api.github.com/repos/OpenSourceBrain/OSBv2/notifications{?since,all,participating}",
"open_issues": 130,
"open_issues_count": 130,
"open_issues": 129,
"open_issues_count": 129,
"owner": {
"avatar_url": "https://avatars.githubusercontent.com/u/1565478?v=4",
"events_url": "https://api.github.com/users/OpenSourceBrain/events{/privacy}",
Expand Down Expand Up @@ -209549,9 +209549,9 @@
},
"private": false,
"pulls_url": "https://api.github.com/repos/OpenSourceBrain/OSBv2/pulls{/number}",
"pushed_at": "2025-01-09T14:17:02Z",
"pushed_at": "2025-01-22T10:32:09Z",
"releases_url": "https://api.github.com/repos/OpenSourceBrain/OSBv2/releases{/id}",
"size": 47905,
"size": 48835,
"ssh_url": "[email protected]:OpenSourceBrain/OSBv2.git",
"stargazers_count": 12,
"stargazers_url": "https://api.github.com/repos/OpenSourceBrain/OSBv2/stargazers",
Expand Down Expand Up @@ -211069,8 +211069,8 @@
"name": "SBMLShowcase",
"node_id": "MDEwOlJlcG9zaXRvcnk5ODMzNTU3",
"notifications_url": "https://api.github.com/repos/OpenSourceBrain/SBMLShowcase/notifications{?since,all,participating}",
"open_issues": 11,
"open_issues_count": 11,
"open_issues": 10,
"open_issues_count": 10,
"owner": {
"avatar_url": "https://avatars.githubusercontent.com/u/1565478?v=4",
"events_url": "https://api.github.com/users/OpenSourceBrain/events{/privacy}",
Expand Down Expand Up @@ -211101,9 +211101,9 @@
},
"private": false,
"pulls_url": "https://api.github.com/repos/OpenSourceBrain/SBMLShowcase/pulls{/number}",
"pushed_at": "2025-01-21T16:15:51Z",
"pushed_at": "2025-01-22T10:44:21Z",
"releases_url": "https://api.github.com/repos/OpenSourceBrain/SBMLShowcase/releases{/id}",
"size": 2048,
"size": 2049,
"ssh_url": "[email protected]:OpenSourceBrain/SBMLShowcase.git",
"stargazers_count": 1,
"stargazers_url": "https://api.github.com/repos/OpenSourceBrain/SBMLShowcase/stargazers",
Expand Down
3 changes: 3 additions & 0 deletions libraries/client/info_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -ex

## A script to refresh all the cached info json files

ruff format *.py
ruff check *.py

python osbv1_info.py

python osb_info.py
Expand Down
6 changes: 4 additions & 2 deletions libraries/client/loadbiomodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def main():
if "BIOMD" in model_id:
model_link = f"[{model_id}](https://www.ebi.ac.uk/biomodels/{model_id})"
info = get_model_info(model_id)
model_name = info["name"]
# model_name = info["name"]
print("\n===============================================")
print(f" {model_id}: \n{pprint.pprint(info['name'])}--")
print(
f" {model_id} ({model_link}): \n{pprint.pformat(info['name'])}--"
)
count += 1


Expand Down
10 changes: 4 additions & 6 deletions libraries/client/loadddandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import logging
import json
import sys
import csv

from utils import get_tags_info
from utils import known_users, lookup_user

from workspaces_cli.models import (
OSBRepository,
RepositoryType,
Tag,
RepositoryContentType,
)
# Defining the host is optional and defaults to http://localhost/api
Expand Down Expand Up @@ -76,7 +75,6 @@
dandishowcase_csv_url = "https://raw.githubusercontent.com/OpenSourceBrain/DANDIArchiveShowcase/main/validation_folder/dandiset_summary.csv"
response = urlopen(dandishowcase_csv_url)

import csv

dandishowcase_info_reader = csv.DictReader(codecs.iterdecode(response, "utf-8"))
dandishowcase_info = list(dandishowcase_info_reader)
Expand Down Expand Up @@ -104,7 +102,7 @@ def add_dandiset(dandishowcase_entry, index):
dandi_api_info = api_instance.get_info(
uri=dandiset_url, repository_type="dandi"
)
except:
except Exception:
but_ok = (
" (known to be missing...)"
if dandiset_url in known_missing_dandisets
Expand Down Expand Up @@ -159,7 +157,7 @@ def add_dandiset(dandishowcase_entry, index):
" %s already exists (owner: %s); updating..."
% (dandiset_url, lookup_user(r.user_id, url_info))
)
except:
except Exception:
exit(-1)
print(url_info)
all_updated.append(url_info)
Expand Down Expand Up @@ -236,7 +234,7 @@ def add_dandiset(dandishowcase_entry, index):
continue
try:
added = add_dandiset(dandishowcase_entry, index)
except Exception as e:
except Exception:
logging.exception(
"Error adding/updating %s" % dandishowcase_entry["url"]
)
Expand Down
10 changes: 3 additions & 7 deletions libraries/client/loadmodeldb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from urllib.request import urlopen
import codecs
import workspaces_cli
from pprint import pprint
from workspaces_cli.api import rest_api, k8s_api
Expand All @@ -12,8 +10,6 @@

from workspaces_cli.models import (
OSBRepository,
RepositoryType,
Tag,
RepositoryContentType,
)
# Defining the host is optional and defaults to http://localhost/api
Expand Down Expand Up @@ -82,7 +78,7 @@

def add_modeldb_model(modeldb_model, index):
modeldb_model_id = modeldb_model["id"]
if not "osbv2_gh_repo" in modeldb_model or not modeldb_model["osbv2_gh_repo"]:
if "osbv2_gh_repo" not in modeldb_model or not modeldb_model["osbv2_gh_repo"]:
all_errors.append(
" %i, %s (%s) doesn't have a Github repo..."
% (index, modeldb_model["name"], modeldb_model_id)
Expand Down Expand Up @@ -149,7 +145,7 @@ def add_modeldb_model(modeldb_model, index):
" %s already exists (owner: %s); updating..."
% (modeldb_model_id, lookup_user(existing_repo.user_id, url_info))
)
except:
except Exception:
exit(-1)
print(url_info)
all_updated.append(url_info)
Expand Down Expand Up @@ -239,7 +235,7 @@ def add_modeldb_model(modeldb_model, index):
print("----------")
print("Error: %s" % str(e))
print("----------")
if not "context_resources" in str(e):
if "context_resources" not in str(e):
print("Exiting due to unknown error...")
exit()
else:
Expand Down
19 changes: 8 additions & 11 deletions libraries/client/loadosbv1.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from urllib.request import urlopen
import codecs
import workspaces_cli
from pprint import pprint
from workspaces_cli.api import rest_api, k8s_api
import logging
import json
import sys
from workspaces_cli.models import (
OSBRepository,
RepositoryContentType,
)

from utils import get_tags_info
from utils import known_users, lookup_user

known_ignores = ["dentate", "nc_superdeep", "tvb_neuroml"]

from workspaces_cli.models import (
OSBRepository,
RepositoryType,
Tag,
RepositoryContentType,
)

# Defining the host is optional and defaults to http://localhost/api
# See configuration.py for a list of all supported configuration parameters.

Expand Down Expand Up @@ -84,7 +81,7 @@

def add_osbv1_project(osbv1_proj, index):
osbv1_proj_id = osbv1_proj["identifier"]
if not "GitHub repository" in osbv1_proj:
if "GitHub repository" not in osbv1_proj:
but_ok = (
" (but it is in the list of known projects to ignore)"
if osbv1_proj_id in known_ignores
Expand Down Expand Up @@ -150,7 +147,7 @@ def add_osbv1_project(osbv1_proj, index):
" %s already exists (owner: %s); updating..."
% (osbv1_proj_id, lookup_user(r.user_id, url_info))
)
except:
except Exception:
exit(-1)
print(url_info)
all_updated.append(url_info)
Expand Down Expand Up @@ -230,7 +227,7 @@ def add_osbv1_project(osbv1_proj, index):
print("----------")
print("Error: %s" % str(e))
print("----------")
if not "context_resources" in str(e):
if "context_resources" not in str(e):
print("Exiting due to unknown error...")
exit()
else:
Expand Down
8 changes: 3 additions & 5 deletions libraries/client/modeldb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import sys
import json

import osb
import operator
import pprint

from utils import get_github
Expand Down Expand Up @@ -87,7 +85,7 @@

info[model]["osbv2_gh_repo"] = repo_to_use.html_url
info[model]["osbv2_gh_branch"] = repo_to_use.default_branch
except:
except Exception:
print(
" Missing fork: %s, forking now: %s"
% (possible_osbgh_repo, fork_if_missing)
Expand All @@ -110,7 +108,7 @@
to_be_forked.append(msg)

if (not mdb_repo.forks == expected_forks) and (
not (info[model]["id"] in known_to_have_other_forks)
info[model]["id"] not in known_to_have_other_forks
):
msg = " Unexpected forks for %i (%s != %s)..." % (
info[model]["id"],
Expand All @@ -120,7 +118,7 @@
print(msg)
many_forks.append(msg)

except:
except Exception:
msg = " Problem locating repo for: %i (%i/%i) %s" % (
info[model]["id"],
index,
Expand Down
14 changes: 2 additions & 12 deletions libraries/client/osb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@
# the current contents. Makes it easier to track (small) changes following API calls
######################################################################################

from urllib.request import urlopen
import codecs
import workspaces_cli
from pprint import pprint
from workspaces_cli.api import rest_api, k8s_api
import logging
import datetime
import json
import sys

from workspaces_cli.models import (
OSBRepository,
RepositoryType,
Tag,
RepositoryContentType,
)
# Defining the host is optional and defaults to http://localhost/api
# See configuration.py for a list of all supported configuration parameters.

Expand Down Expand Up @@ -70,14 +60,14 @@
try:
print("Checking page %i" % page)
found = api_instance.osbrepository_get(
q=f"uri__like=/", per_page=500, page=page
q="uri__like=/", per_page=500, page=page
)
for f in found.osbrepositories:
all_found.append(f)
print("Found so far: %i" % len(all_found))
page += 1
# if page>3: break
except:
except Exception:
print("All done")
break

Expand Down
2 changes: 1 addition & 1 deletion libraries/client/osbv1_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
print(" Project has tags: %s" % (project.tags))
with_tags += 1
for tag in project.tags:
if not tag in tags:
if tag not in tags:
tags[tag] = 0
tags[tag] += 1

Expand Down
6 changes: 3 additions & 3 deletions libraries/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def lookup_user(uid, url):
if not uid in known_users.values():
if uid not in known_users.values():
raise Exception("Unknown user: %s;%s" % (uid, url))
for user in known_users:
if uid == known_users[user]:
Expand Down Expand Up @@ -51,10 +51,10 @@ def get_tags_info(
for field in ["Original format", "Cell type", "Brain region", "Specie"]:
if field in osbv1_info:
val = osbv1_info[field]
if not val in ["None", "Other", ""]:
if val not in ["None", "Other", ""]:
val = val.replace("PV+", "PV")
val = val.replace("C++", "Cplusplus")
if not val in tags:
if val not in tags:
tags.append(val)

if dandi_api_info is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def __init__(self, name, repository_type, content_types, uri, *args, **kwargs):
continue
try:
setattr(self, var_name, var_value)
except:
except Exception:

pass
if var_name in self.read_only_vars:
Expand Down

0 comments on commit 1dafe78

Please sign in to comment.