Skip to content

Commit 9f6d545

Browse files
committed
modernized phase 4
1 parent c25cb4f commit 9f6d545

21 files changed

+162
-168
lines changed

peppy/eido/cli.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
from logging import CRITICAL, DEBUG, ERROR, INFO, WARN, Logger
3-
from typing import Dict, List, Optional
43

54
import typer
65
from logmuse import init_logger
@@ -23,8 +22,8 @@
2322

2423

2524
def _configure_logging(
26-
verbosity: Optional[int],
27-
logging_level: Optional[str],
25+
verbosity: int | None,
26+
logging_level: str | None,
2827
dbg: bool,
2928
) -> str:
3029
"""Mimic old verbosity / logging-level behavior."""
@@ -38,7 +37,7 @@ def _configure_logging(
3837
return level
3938

4039

41-
def _parse_filter_args_str(input: Optional[List[str]]) -> Dict[str, str]:
40+
def _parse_filter_args_str(input: list[str] | None) -> dict[str, str]:
4241
"""
4342
Parse user input specification.
4443
@@ -57,7 +56,7 @@ def _parse_filter_args_str(input: Optional[List[str]]) -> Dict[str, str]:
5756

5857

5958
def print_error_summary(
60-
errors_by_type: Dict[str, List[Dict[str, str]]], _LOGGER: Logger
59+
errors_by_type: dict[str, list[dict[str, str]]], _LOGGER: Logger
6160
):
6261
"""Print a summary of errors, organized by error type"""
6362
n_error_types = len(errors_by_type)
@@ -80,14 +79,14 @@ def print_error_summary(
8079
@app.callback()
8180
def common(
8281
ctx: typer.Context,
83-
verbosity: Optional[int] = typer.Option(
82+
verbosity: int | None = typer.Option(
8483
None,
8584
"--verbosity",
8685
min=0,
8786
max=len(LEVEL_BY_VERBOSITY) - 1,
8887
help=f"Choose level of verbosity (default: {None})",
8988
),
90-
logging_level: Optional[str] = typer.Option(
89+
logging_level: str | None = typer.Option(
9190
None,
9291
"--logging-level",
9392
help="logging level",
@@ -114,18 +113,18 @@ def common(
114113
@app.command(name=CONVERT_CMD, help=SUBPARSER_MSGS[CONVERT_CMD])
115114
def convert(
116115
ctx: typer.Context,
117-
pep: Optional[str] = typer.Argument(
116+
pep: str | None = typer.Argument(
118117
None,
119118
metavar="PEP",
120119
help="Path to a PEP configuration file in yaml format.",
121120
),
122-
st_index: Optional[str] = typer.Option(
121+
st_index: str | None = typer.Option(
123122
None, "--st-index", help="Sample table index to use"
124123
),
125-
sst_index: Optional[str] = typer.Option(
124+
sst_index: str | None = typer.Option(
126125
None, "--sst-index", help="Subsample table index to use"
127126
),
128-
amendments: Optional[List[str]] = typer.Option(
127+
amendments: list[str] | None = typer.Option(
129128
None,
130129
"--amendments",
131130
help="Names of the amendments to activate.",
@@ -136,13 +135,13 @@ def convert(
136135
"--format",
137136
help="Output format (name of filter; use -l to see available).",
138137
),
139-
sample_name: Optional[List[str]] = typer.Option(
138+
sample_name: list[str] | None = typer.Option(
140139
None,
141140
"-n",
142141
"--sample-name",
143142
help="Name of the samples to inspect.",
144143
),
145-
args: Optional[List[str]] = typer.Option(
144+
args: list[str] | None = typer.Option(
146145
None,
147146
"-a",
148147
"--args",
@@ -162,7 +161,7 @@ def convert(
162161
"--describe",
163162
help="Show description for a given filter.",
164163
),
165-
paths_: Optional[List[str]] = typer.Option(
164+
paths_: list[str] | None = typer.Option(
166165
None,
167166
"-p",
168167
"--paths",
@@ -226,28 +225,28 @@ def validate(
226225
metavar="S",
227226
help="Path to a PEP schema file in yaml format.",
228227
),
229-
st_index: Optional[str] = typer.Option(
228+
st_index: str | None = typer.Option(
230229
None,
231230
"--st-index",
232231
help=(
233232
f"Sample table index to use; samples are identified by "
234233
f"'{SAMPLE_NAME_ATTR}' by default."
235234
),
236235
),
237-
sst_index: Optional[str] = typer.Option(
236+
sst_index: str | None = typer.Option(
238237
None,
239238
"--sst-index",
240239
help=(
241240
f"Subsample table index to use; samples are identified by "
242241
f"'{SAMPLE_NAME_ATTR}' by default."
243242
),
244243
),
245-
amendments: Optional[List[str]] = typer.Option(
244+
amendments: list[str] | None = typer.Option(
246245
None,
247246
"--amendments",
248247
help="Names of the amendments to activate.",
249248
),
250-
sample_name: Optional[str] = typer.Option(
249+
sample_name: str | None = typer.Option(
251250
None,
252251
"-n",
253252
"--sample-name",
@@ -311,28 +310,28 @@ def inspect(
311310
metavar="PEP",
312311
help="Path to a PEP configuration file in yaml format.",
313312
),
314-
st_index: Optional[str] = typer.Option(
313+
st_index: str | None = typer.Option(
315314
None,
316315
"--st-index",
317316
help=(
318317
f"Sample table index to use; samples are identified by "
319318
f"'{SAMPLE_NAME_ATTR}' by default."
320319
),
321320
),
322-
sst_index: Optional[str] = typer.Option(
321+
sst_index: str | None = typer.Option(
323322
None,
324323
"--sst-index",
325324
help=(
326325
f"Subsample table index to use; samples are identified by "
327326
f"'{SAMPLE_NAME_ATTR}' by default."
328327
),
329328
),
330-
amendments: Optional[List[str]] = typer.Option(
329+
amendments: list[str] | None = typer.Option(
331330
None,
332331
"--amendments",
333332
help="Names of the amendments to activate.",
334333
),
335-
sample_name: Optional[List[str]] = typer.Option(
334+
sample_name: list[str] | None = typer.Option(
336335
None,
337336
"-n",
338337
"--sample-name",

peppy/eido/conversion.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import os
55
import sys
66
from logging import getLogger
7-
from typing import Callable, Dict, List, NoReturn, Optional
7+
from collections.abc import Callable
88

99
from ..project import Project
1010
from .exceptions import EidoFilterError
1111

1212
_LOGGER = getLogger(__name__)
1313

1414

15-
def pep_conversion_plugins() -> Dict[str, Callable]:
15+
def pep_conversion_plugins() -> dict[str, Callable]:
1616
"""Plugins registered by entry points in the current Python env.
1717
1818
Returns:
@@ -35,8 +35,8 @@ def pep_conversion_plugins() -> Dict[str, Callable]:
3535

3636

3737
def convert_project(
38-
prj: Project, target_format: str, plugin_kwargs: Optional[Dict] = None
39-
) -> Dict[str, str]:
38+
prj: Project, target_format: str, plugin_kwargs: dict | None = None
39+
) -> dict[str, str]:
4040
"""Convert a `peppy.Project` object to a selected format.
4141
4242
Args:
@@ -57,8 +57,8 @@ def run_filter(
5757
prj: Project,
5858
filter_name: str,
5959
verbose: bool = True,
60-
plugin_kwargs: Optional[Dict] = None,
61-
) -> Dict[str, str]:
60+
plugin_kwargs: dict | None = None,
61+
) -> dict[str, str]:
6262
"""Run a selected filter on a peppy.Project object.
6363
6464
Args:
@@ -124,12 +124,12 @@ def run_filter(
124124
return conv_result
125125

126126

127-
def save_result(result_path: str, content: str) -> NoReturn:
127+
def save_result(result_path: str, content: str) -> None:
128128
with open(result_path, "w") as f:
129129
f.write(content)
130130

131131

132-
def get_available_pep_filters() -> List[str]:
132+
def get_available_pep_filters() -> list[str]:
133133
"""Get a list of available target formats.
134134
135135
Returns:

peppy/eido/conversion_plugins.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""built-in PEP filters"""
22

3-
from typing import Dict
43

54
from .output_formatters import MultilineOutputFormatter
65

76

8-
def basic_pep_filter(p, **kwargs) -> Dict[str, str]:
7+
def basic_pep_filter(p, **kwargs) -> dict[str, str]:
98
"""
109
Basic PEP filter, that does not convert the Project object.
1110
@@ -16,7 +15,7 @@ def basic_pep_filter(p, **kwargs) -> Dict[str, str]:
1615
return {"project": str(p)}
1716

1817

19-
def yaml_samples_pep_filter(p, **kwargs) -> Dict[str, str]:
18+
def yaml_samples_pep_filter(p, **kwargs) -> dict[str, str]:
2019
"""
2120
YAML samples PEP filter, that returns only Sample object representations.
2221
@@ -33,7 +32,7 @@ def yaml_samples_pep_filter(p, **kwargs) -> Dict[str, str]:
3332
return {"samples": dump(samples_yaml, default_flow_style=False)}
3433

3534

36-
def yaml_pep_filter(p, **kwargs) -> Dict[str, str]:
35+
def yaml_pep_filter(p, **kwargs) -> dict[str, str]:
3736
"""
3837
YAML PEP filter, that returns Project object representation.
3938
@@ -46,7 +45,7 @@ def yaml_pep_filter(p, **kwargs) -> Dict[str, str]:
4645
return {"project": dump(p.config, default_flow_style=False)}
4746

4847

49-
def csv_pep_filter(p, **kwargs) -> Dict[str, str]:
48+
def csv_pep_filter(p, **kwargs) -> dict[str, str]:
5049
"""
5150
CSV PEP filter, that returns Sample object representations
5251
@@ -58,7 +57,7 @@ def csv_pep_filter(p, **kwargs) -> Dict[str, str]:
5857
return {"samples": MultilineOutputFormatter.format(p.samples)}
5958

6059

61-
def processed_pep_filter(p, **kwargs) -> Dict[str, str]:
60+
def processed_pep_filter(p, **kwargs) -> dict[str, str]:
6261
"""
6362
Processed PEP filter, that returns the converted sample and subsample tables.
6463
This filter can return the tables as a table or a document.

peppy/eido/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Exceptions for specific eido issues."""
22

33
from abc import ABCMeta
4-
from typing import Dict, List
54

65
__all__ = [
76
"EidoFilterError",
@@ -41,7 +40,7 @@ def __init__(self, key):
4140
class EidoValidationError(EidoException):
4241
"""Object was not validated successfully according to schema."""
4342

44-
def __init__(self, message: str, errors_by_type: Dict[str, List[Dict[str, str]]]):
43+
def __init__(self, message: str, errors_by_type: dict[str, list[dict[str, str]]]):
4544
super().__init__(message)
4645
self.errors_by_type = errors_by_type
4746
self.message = message

peppy/eido/inspection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from logging import getLogger
3-
from typing import Dict, Iterable, List, Set, Union
3+
from collections.abc import Iterable
44
from warnings import catch_warnings
55

66
from ubiquerg import size
@@ -23,7 +23,7 @@
2323

2424

2525
def inspect_project(
26-
p: Project, sample_names: Union[None, List[str]] = None, max_attr: int = 10
26+
p: Project, sample_names: list[str] | None = None, max_attr: int = 10
2727
) -> None:
2828
"""Print inspection info: Project or, if sample_names argument is provided, matched samples.
2929
@@ -46,8 +46,8 @@ def inspect_project(
4646

4747

4848
def get_input_files_size(
49-
sample: Sample, schema: Union[str, List[Dict]]
50-
) -> Dict[str, Union[List[str], Set[str], float]]:
49+
sample: Sample, schema: str | list[dict]
50+
) -> dict[str, list[str] | set[str] | float]:
5151
"""Determine which of this Sample's required attributes/files are missing and calculate sizes.
5252
5353
The names of the attributes that are required and/or deemed as inputs

peppy/eido/output_formatters.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from abc import ABC, abstractmethod
2-
from typing import Iterable, List, Union
2+
from collections.abc import Iterable
33

44
from ..sample import Sample
55

66

77
class BaseOutputFormatter(ABC):
88
@staticmethod
99
@abstractmethod
10-
def format(samples: List[Sample]) -> str:
10+
def format(samples: list[Sample]) -> str:
1111
"""
1212
Convert the samples to correct format.
1313
"""
@@ -16,7 +16,7 @@ def format(samples: List[Sample]) -> str:
1616

1717
class MultilineOutputFormatter(BaseOutputFormatter):
1818
@staticmethod
19-
def format(samples: List[Sample]) -> str:
19+
def format(samples: list[Sample]) -> str:
2020
output_rows = []
2121
sample_attributes = [
2222
attribute
@@ -43,20 +43,20 @@ def format(samples: List[Sample]) -> str:
4343
return "\n".join(header + output_rows) + "\n"
4444

4545
@staticmethod
46-
def _get_header(header_column_names: List[str]) -> List[str]:
46+
def _get_header(header_column_names: list[str]) -> list[str]:
4747
return [",".join(header_column_names)]
4848

4949
@staticmethod
5050
def _get_the_name_of_the_first_attribute_with_multiple_properties(
51-
sample: Sample, sample_attributes: List[str]
52-
) -> Union[str, None]:
51+
sample: Sample, sample_attributes: list[str]
52+
) -> str | None:
5353
for attribute in sample_attributes:
5454
if MultilineOutputFormatter._sample_attribute_is_list(sample, attribute):
5555
return attribute
5656

5757
@staticmethod
5858
def _split_sample_to_multiple_rows(
59-
sample: Sample, sample_attributes: List, attribute_with_multiple_properties: str
59+
sample: Sample, sample_attributes: list, attribute_with_multiple_properties: str
6060
) -> Iterable[str]:
6161
"""
6262
If one sample object contains array properties instead of single value, then it will be converted
@@ -84,7 +84,7 @@ def _split_sample_to_multiple_rows(
8484

8585
@staticmethod
8686
def _convert_sample_to_row(
87-
sample: Sample, sample_attributes: List, sample_index: int = 0
87+
sample: Sample, sample_attributes: list, sample_index: int = 0
8888
) -> str:
8989
"""
9090
Converts single sample object to CSV row.
@@ -122,5 +122,5 @@ def _sample_attribute_is_list(sample: Sample, attribute: str) -> bool:
122122

123123

124124
class SampleSubsampleOutputFormatter(BaseOutputFormatter):
125-
def format(self, samples: List[Sample]) -> str:
125+
def format(self, samples: list[Sample]) -> str:
126126
pass

0 commit comments

Comments
 (0)