Skip to content

Commit 26daf4f

Browse files
committed
Use list and dict container type
1 parent 541a09a commit 26daf4f

File tree

7 files changed

+52
-70
lines changed

7 files changed

+52
-70
lines changed

src/ephemeris/_config_models.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from pathlib import Path
22
from typing import (
3-
Dict,
4-
List,
53
Optional,
64
Union,
75
)
@@ -22,7 +20,7 @@ class RepositoryInstallTarget(BaseModel):
2220
tool_shed_url: Optional[str] = None
2321
tool_panel_section_id: Optional[str] = None
2422
tool_panel_section_label: Optional[str] = None
25-
revisions: Optional[List[str]] = None
23+
revisions: Optional[list[str]] = None
2624
install_tool_dependencies: Optional[bool] = None
2725
install_repository_dependencies: Optional[bool] = None
2826
install_resolver_dependencies: Optional[bool] = None
@@ -33,16 +31,16 @@ class RepositoryInstallTargets(BaseModel):
3331

3432
api_key: Optional[str] = None
3533
galaxy_instance: Optional[str] = None
36-
tools: List[RepositoryInstallTarget]
34+
tools: list[RepositoryInstallTarget]
3735

3836

3937
class DataManager(BaseModel, extra=Extra.forbid):
40-
tags: List[str]
38+
tags: list[str]
4139
tool_id: str
4240

4341

4442
class DataManagers(RootModel):
45-
root: Dict[str, DataManager]
43+
root: dict[str, DataManager]
4644

4745

4846
class Genome(BaseModel):
@@ -62,15 +60,15 @@ class Genome(BaseModel):
6260

6361
# Description of actions (data managers) to run on target genome.
6462
indexers: Optional[
65-
List[str]
63+
list[str]
6664
] # indexers to run - keyed on repository name - see data_managers.yml for how to resolve these to tools
67-
skiplist: Optional[List[str]] = (
65+
skiplist: Optional[list[str]] = (
6866
None # unimplemented: but if we implement classes of indexers, these will be ones to skip
6967
)
7068

7169

7270
class Genomes(BaseModel):
73-
genomes: List[Genome]
71+
genomes: list[Genome]
7472

7573

7674
def _read_yaml(path: StrOrPath):

src/ephemeris/_idc_data_managers_to_tools.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
"""
88
import argparse
99
import logging
10-
from typing import (
11-
Dict,
12-
List,
13-
NamedTuple,
14-
)
10+
from typing import NamedTuple
1511

1612
import yaml
1713

@@ -32,12 +28,12 @@
3228
class DataManager(NamedTuple):
3329
tool_id: str
3430
repository_name: str
35-
tags: List[str]
31+
tags: list[str]
3632

3733

38-
def read_data_managers_configuration(path: str) -> Dict[str, DataManager]:
34+
def read_data_managers_configuration(path: str) -> dict[str, DataManager]:
3935
raw_data_managers = read_data_managers(path)
40-
data_managers: Dict[str, DataManager] = {}
36+
data_managers: dict[str, DataManager] = {}
4137
for repository_name, data_manager_configuration in raw_data_managers.root.items():
4238
data_manager = DataManager(
4339
tool_id=data_manager_configuration.tool_id,

src/ephemeris/_idc_split_data_manager_genomes.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from typing import (
1515
Any,
1616
Callable,
17-
Dict,
18-
List,
1917
Optional,
2018
)
2119

@@ -71,7 +69,7 @@ class SplitOptions:
7169
filters: Filters = Filters()
7270

7371

74-
def tool_id_for(indexer: str, data_managers: Dict[str, DataManager], mode: str) -> str:
72+
def tool_id_for(indexer: str, data_managers: dict[str, DataManager], mode: str) -> str:
7573
data_manager = data_managers[indexer]
7674
assert data_manager, f"Could not find a target data manager for indexer name {indexer}"
7775
tool_shed_guid = data_manager.tool_id
@@ -88,30 +86,30 @@ def tool_id_for(indexer: str, data_managers: Dict[str, DataManager], mode: str)
8886

8987
class RunDataManager(BaseModel):
9088
id: str
91-
items: Optional[List[Any]] = None
92-
params: Optional[List[Any]] = None
93-
data_table_reload: Optional[List[str]] = None
89+
items: Optional[list[Any]] = None
90+
params: Optional[list[Any]] = None
91+
data_table_reload: Optional[list[str]] = None
9492

9593

9694
class RunDataManagers(BaseModel):
97-
data_managers: List[RunDataManager]
95+
data_managers: list[RunDataManager]
9896

9997

10098
class DataManager(BaseModel, extra=Extra.forbid):
101-
tags: List[str]
99+
tags: list[str]
102100
tool_id: str
103101

104102

105103
class DataManagers(RootModel):
106-
root: Dict[str, DataManager]
104+
root: dict[str, DataManager]
107105

108106

109107
class Genome(BaseModel):
110108
pass
111109

112110

113111
class Genomes(BaseModel):
114-
genomes: List[Genome]
112+
genomes: list[Genome]
115113

116114

117115
def ucsc_description_for_build(requested_build: str) -> str:
@@ -258,7 +256,7 @@ def write_task_file(build_id: str, indexer: str, run_data_manager: RunDataManage
258256

259257

260258
class GalaxyHistoryIsBuildComplete:
261-
def __init__(self, history_names: List[str]):
259+
def __init__(self, history_names: list[str]):
262260
self._history_names = history_names
263261

264262
def __call__(self, build_id: str, indexer_name: str) -> bool:
@@ -267,7 +265,7 @@ def __call__(self, build_id: str, indexer_name: str) -> bool:
267265

268266

269267
class CVMFSPublishIsComplete:
270-
def __init__(self, records: Dict[str, List[str]]):
268+
def __init__(self, records: dict[str, list[str]]):
271269
self.records = records
272270

273271
def __call__(self, build_id: str, indexer_name: str) -> bool:
@@ -294,16 +292,16 @@ def _parser():
294292
return parser
295293

296294

297-
def get_galaxy_history_names(args) -> List[str]:
295+
def get_galaxy_history_names(args) -> list[str]:
298296
gi = get_galaxy_connection(args, login_required=True)
299297
return [h["name"] for h in gi.histories.get_histories()]
300298

301299

302-
def get_regular_files(dirname: str) -> List[str]:
300+
def get_regular_files(dirname: str) -> list[str]:
303301
return [f for f in os.listdir(dirname) if not f.startswith(".")]
304302

305303

306-
def get_cvmfs_publish_records(args) -> Dict[str, List[str]]:
304+
def get_cvmfs_publish_records(args) -> dict[str, list[str]]:
307305
records = {}
308306
records_dir = os.path.join(args.cvmfs_root, "record")
309307
for build_id in get_regular_files(records_dir):

src/ephemeris/generate_tool_list_from_ga_workflow_files.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"""Tool to generate tools from workflows"""
33
import json
44
from argparse import ArgumentParser
5-
from typing import (
6-
Iterable,
7-
List,
8-
)
5+
from collections.abc import Iterable
96

107
import yaml
118

@@ -60,9 +57,9 @@ def get_workflow_dictionary(json_file):
6057
return mydict
6158

6259

63-
def translate_workflow_dictionary_to_tool_list(workflow_dictionary, panel_label: str) -> List[InstallRepoDict]:
60+
def translate_workflow_dictionary_to_tool_list(workflow_dictionary, panel_label: str) -> list[InstallRepoDict]:
6461
starting_tool_list = extract_tool_shed_repositories_from_workflow_dict(workflow_dictionary)
65-
tool_list: List[InstallRepoDict] = []
62+
tool_list: list[InstallRepoDict] = []
6663
for tool in starting_tool_list:
6764
sub_dic: InstallRepoDict = {
6865
"name": tool["name"],
@@ -104,7 +101,7 @@ def print_yaml_tool_list(tool_dictionary, output_file):
104101
return
105102

106103

107-
def reduce_tool_list(tool_list: List[InstallRepoDict]) -> List[InstallRepoDict]:
104+
def reduce_tool_list(tool_list: list[InstallRepoDict]) -> list[InstallRepoDict]:
108105
for current_tool in tool_list:
109106
for tool in tool_list:
110107
if current_tool is tool:
@@ -121,8 +118,8 @@ def reduce_tool_list(tool_list: List[InstallRepoDict]) -> List[InstallRepoDict]:
121118
return tool_list
122119

123120

124-
def generate_repo_list_from_workflow(workflow_files: Iterable[str], panel_label: str) -> List[InstallRepoDict]:
125-
intermediate_tool_list: List[InstallRepoDict] = []
121+
def generate_repo_list_from_workflow(workflow_files: Iterable[str], panel_label: str) -> list[InstallRepoDict]:
122+
intermediate_tool_list: list[InstallRepoDict] = []
126123
for workflow in workflow_files:
127124
workflow_dictionary = get_workflow_dictionary(workflow)
128125
intermediate_tool_list += translate_workflow_dictionary_to_tool_list(workflow_dictionary, panel_label)

src/ephemeris/set_library_permissions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import argparse
55
import logging as log
66
import sys
7-
from typing import List
87

98
from bioblend import galaxy
109
from rich.progress import Progress
@@ -17,7 +16,7 @@
1716
# Print iterations progress
1817

1918

20-
def get_datasets(gi, library_id) -> List[str]:
19+
def get_datasets(gi, library_id) -> list[str]:
2120
objects = gi.libraries.show_dataset(library_id=library_id, dataset_id="")
2221
datasets = []
2322
for index in range(len(objects)):

src/ephemeris/shed_tools.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@
4141
import re
4242
import time
4343
from collections import namedtuple
44+
from collections.abc import Iterable
4445
from concurrent.futures import (
4546
thread,
4647
ThreadPoolExecutor,
4748
)
48-
from typing import (
49-
Iterable,
50-
List,
51-
Optional,
52-
)
49+
from typing import Optional
5350

5451
import requests
5552
import yaml
@@ -106,21 +103,21 @@ class InstallRepoDict(TypedDict):
106103
tool_panel_section_id: NotRequired[Optional[str]]
107104
tool_panel_section_label: NotRequired[Optional[str]]
108105
tool_shed_url: NotRequired[str]
109-
revisions: NotRequired[List[str]]
106+
revisions: NotRequired[list[str]]
110107
install_repository_dependencies: NotRequired[bool]
111108
install_resolver_dependencies: NotRequired[bool]
112109
install_tool_dependencies: NotRequired[bool]
113110

114111

115112
class FilterResults(NamedTuple):
116-
already_installed_repos: List[InstallRepoDict]
117-
not_installed_repos: List[InstallRepoDict]
113+
already_installed_repos: list[InstallRepoDict]
114+
not_installed_repos: list[InstallRepoDict]
118115

119116

120117
class InstallResults(NamedTuple):
121-
installed_repositories: List[InstallRepoDict]
122-
skipped_repositories: List[InstallRepoDict]
123-
errored_repositories: List[InstallRepoDict]
118+
installed_repositories: list[InstallRepoDict]
119+
skipped_repositories: list[InstallRepoDict]
120+
errored_repositories: list[InstallRepoDict]
124121

125122

126123
class InstallRepositoryManager:
@@ -131,7 +128,7 @@ def __init__(self, galaxy_instance):
131128
self.gi = galaxy_instance
132129
self.tool_shed_client = ToolShedClient(self.gi)
133130

134-
def installed_repositories(self) -> List[InstallRepoDict]:
131+
def installed_repositories(self) -> list[InstallRepoDict]:
135132
"""Get currently installed tools"""
136133
return GiToToolYaml(
137134
gi=self.gi,
@@ -142,8 +139,8 @@ def installed_repositories(self) -> List[InstallRepoDict]:
142139

143140
def filter_installed_repos(self, repos: Iterable[InstallRepoDict], check_revision: bool = True) -> FilterResults:
144141
"""This filters a list of repositories"""
145-
not_installed_repos: List[InstallRepoDict] = []
146-
already_installed_repos: List[InstallRepoDict] = []
142+
not_installed_repos: list[InstallRepoDict] = []
143+
already_installed_repos: list[InstallRepoDict] = []
147144
if check_revision:
148145
# If we want to check if revisions are equal, flatten the list,
149146
# so each repository - revision combination has its own entry
@@ -167,7 +164,7 @@ def filter_installed_repos(self, repos: Iterable[InstallRepoDict], check_revisio
167164

168165
def install_repositories(
169166
self,
170-
repositories: List[InstallRepoDict],
167+
repositories: list[InstallRepoDict],
171168
log=log,
172169
force_latest_revision: bool = False,
173170
default_toolshed: str = "https://toolshed.g2.bx.psu.edu/",
@@ -177,9 +174,9 @@ def install_repositories(
177174
):
178175
"""Install a list of tools on the current galaxy"""
179176
installation_start = dt.datetime.now()
180-
installed_repositories: List[InstallRepoDict] = []
181-
skipped_repositories: List[InstallRepoDict] = []
182-
errored_repositories: List[InstallRepoDict] = []
177+
installed_repositories: list[InstallRepoDict] = []
178+
skipped_repositories: list[InstallRepoDict] = []
179+
errored_repositories: list[InstallRepoDict] = []
183180
counter = 0
184181

185182
# Check repos for invalid keys
@@ -194,7 +191,7 @@ def install_repositories(
194191
total_num_repositories = len(flattened_repos)
195192

196193
# Complete the repo information, and make sure each repository has a revision
197-
repository_list: List[InstallRepoDict] = []
194+
repository_list: list[InstallRepoDict] = []
198195
for repository in flattened_repos:
199196
start = dt.datetime.now()
200197
try:
@@ -651,7 +648,7 @@ def log_repository_install_start(
651648
)
652649

653650

654-
def args_to_repos(args) -> List[InstallRepoDict]:
651+
def args_to_repos(args) -> list[InstallRepoDict]:
655652
if args.tool_list_file:
656653
tool_list = load_yaml_file(args.tool_list_file)
657654
repos = tool_list["tools"]

src/ephemeris/shed_tools_methods.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import (
2-
Iterable,
3-
List,
4-
TYPE_CHECKING,
5-
)
1+
from collections.abc import Iterable
2+
from typing import TYPE_CHECKING
63

74
from bioblend.toolshed import ToolShedInstance
85

@@ -86,7 +83,7 @@ def get_changeset_revisions(repository: "InstallRepoDict", force_latest_revision
8683

8784
def flatten_repo_info(
8885
repositories: Iterable["InstallRepoDict"],
89-
) -> List["InstallRepoDict"]:
86+
) -> list["InstallRepoDict"]:
9087
"""
9188
Flatten the dict containing info about what tools to install.
9289
The tool definition YAML file allows multiple revisions to be listed for
@@ -101,7 +98,7 @@ def flatten_repo_info(
10198
values, those will be returned as separate list items.
10299
"""
103100

104-
flattened_list: List[InstallRepoDict] = []
101+
flattened_list: list[InstallRepoDict] = []
105102
for repo_info in repositories:
106103
new_repo_info = repo_info.copy()
107104
if "revisions" in new_repo_info:

0 commit comments

Comments
 (0)