Passed
Push — dependabot/pip/pint-0.18 ( 0025b0...c70073 )
by
unknown
02:24 queued 43s
created

mandos.entry.misc_commands.MiscCommands.concat()   B

Complexity

Conditions 8

Size

Total Lines 56
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 42
nop 5
dl 0
loc 56
rs 7.0053
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
"""
2
Command-line interface for mandos.
3
"""
4
5
from __future__ import annotations
6
7
import os
8
from pathlib import Path
9
from typing import Optional
10
11
import decorateme
0 ignored issues
show
introduced by
Unable to import 'decorateme'
Loading history...
12
import pandas as pd
0 ignored issues
show
introduced by
Unable to import 'pandas'
Loading history...
13
import typer
0 ignored issues
show
introduced by
Unable to import 'typer'
Loading history...
14
from pocketutils.core.chars import Chars
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.chars'
Loading history...
15
from pocketutils.core.exceptions import XValueError
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.exceptions'
Loading history...
16
from pocketutils.tools.string_tools import StringTools
0 ignored issues
show
introduced by
Unable to import 'pocketutils.tools.string_tools'
Loading history...
17
from typeddfs import CompressionFormat, FileFormat
0 ignored issues
show
introduced by
Unable to import 'typeddfs'
Loading history...
18
from typeddfs.df_errors import InvalidDfError
0 ignored issues
show
introduced by
Unable to import 'typeddfs.df_errors'
Loading history...
19
from typeddfs.utils import Utils as TdfUtils
0 ignored issues
show
introduced by
Unable to import 'typeddfs.utils'
Loading history...
20
from typeddfs.utils.cli_help import DfCliHelp
0 ignored issues
show
introduced by
Unable to import 'typeddfs.utils.cli_help'
Loading history...
21
22
from mandos.analysis.filtration import Filtration
23
from mandos.analysis.reification import Reifier
24
from mandos.entry.tools.docs import Documenter
25
from mandos.entry.tools.fillers import CompoundIdFiller, IdMatchDf
26
from mandos.entry.tools.multi_searches import MultiSearch, SearchConfigDf
27
from mandos.entry.tools.searchers import InputCompoundsDf
28
from mandos.entry.utils._arg_utils import Arg, ArgUtils, EntryUtils, Opt
29
from mandos.entry.utils._common_args import CommonArgs
30
from mandos.entry.utils._common_args import CommonArgs as Ca
0 ignored issues
show
Unused Code introduced by
The import CommonArgs was already done on line 29. You should be able to
remove this line.
Loading history...
31
from mandos.model.apis.g2p_api import CachingG2pApi
32
from mandos.model.hit_dfs import HitDf
33
from mandos.model.settings import SETTINGS
34
from mandos.model.taxonomy import TaxonomyDf
35
from mandos.model.taxonomy_caches import TaxonomyFactories
36
from mandos.model.utils.globals import Globals
37
from mandos.model.utils.setup import LOG_SETUP, logger
38
39
DEF_SUFFIX = SETTINGS.table_suffix
40
nl = "\n\n"
0 ignored issues
show
Coding Style Naming introduced by
Constant name "nl" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
41
42
43
class _InsertedCommandListSingleton:
44
    commands = None
45
46
47
@decorateme.auto_utils()
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
48
class MiscCommands:
49
    @staticmethod
50
    def search(
0 ignored issues
show
best-practice introduced by
Too many arguments (8/5)
Loading history...
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
51
        path: Path = Ca.in_compound_table,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
52
        config: Path = Opt.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
53
            r"""
54
            TOML config file. See the docs.
55
            """,
56
            default=...,
57
        ),
58
        to: Path = Ca.out_wildcard,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
59
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
60
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
61
        replace: bool = Opt.flag(r"""Overwrite completed and partially completed searches."""),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
62
        proceed: bool = Opt.flag(r"""Continue partially completed searches."""),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
63
        check: bool = Opt.flag("Check and write docs file only; do not run"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
64
    ) -> None:
65
        r"""
66
        Run multiple searches.
67
        """
68
        LOG_SETUP(log, stderr)
69
        default = path.parent / ("search-" + Globals.start_time.strftime("%Y-%m-%d"))
70
        # TODO: , suffixes=FileFormat.from_path
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
71
        out_dir, suffix = EntryUtils.adjust_dir_name(to, default)
72
        logger.notice(f"Will write {suffix} to {out_dir}{os.sep}")
73
        config_fmt = FileFormat.from_path(config)
74
        if config_fmt is not FileFormat.toml:
75
            logger.caution(f"Config format is {config_fmt}, not toml; trying anyway")
76
        config = SearchConfigDf.read_file(config)
77
        search = MultiSearch(config, path, out_dir, suffix, replace, proceed, log)
78
        if not check:
79
            search.run()
80
81
    @staticmethod
82
    def init(
83
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
84
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
85
    ):
86
        """
87
        Initializes mandos, creating directories, etc.
88
        """
89
        LOG_SETUP(log, stderr)
90
        Globals.mandos_path.mkdir(exist_ok=True, parents=True)
91
        typer.echo(f"Mandos home dir is {Globals.mandos_path}")
92
        if Globals.settings_path.exists():
93
            typer.echo(f"Settings found at {Globals.settings_path}")
94
        else:
95
            typer.echo("No settings file found")
96
        typer.echo(f"Log level for stderr is level {logger.current_stderr_log_level}")
97
98
    @staticmethod
99
    def list_settings(
100
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
101
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
102
    ):
103
        r"""
104
        Write the settings to stdout.
105
        """
106
        LOG_SETUP(log, stderr)
107
        defaults = SETTINGS.defaults()
108
        width = max((len(k) + 2 + len(v) + 1 for k, v in SETTINGS.items()))
0 ignored issues
show
Bug introduced by
The Instance of Settings does not seem to have a member named items.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Comprehensibility Best Practice introduced by
The variable k does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable v does not seem to be defined.
Loading history...
109
        for k, v in SETTINGS.as_dict():
0 ignored issues
show
Coding Style Naming introduced by
Variable name "v" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Bug introduced by
SETTINGS.as_dict does not seem to be callable.
Loading history...
110
            msg = f"{k} = {v}".ljust(width)
111
            if v != defaults[k]:
112
                msg += f" (default: {defaults[k]})"
113
            typer.echo(msg)
114
115
    @staticmethod
116
    def document(
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
117
        to: Path = Opt.out_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
118
            rf"""
119
            The path to write command documentation to.
120
121
        `   For machine-readable output: {DfCliHelp.list_formats().get_short_text()}.
122
            For formatted output: .txt or .rst [{"/".join([str(c) for c in CompressionFormat.list_non_empty()])}
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
123
124
            [default: "commands-level<level>.rst"]
125
            """
126
        ),
127
        style: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
128
            rf"""
129
            The format for formatted text output.
130
131
            Use "table" for machine-readable output, "docs" for long-form reStructuredText,
132
            or {TdfUtils.join_to_str(TdfUtils.table_formats(), last="or")}
133
            """,
134
            "--style",
135
            default="docs",
136
        ),
137
        width: int = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
138
            r"""
139
            Max number of characters for a cell before wrap.
140
141
            [default: 0 (none) for machine-readable; 100 for formatted]
142
            """,
143
            default=None,
144
            show_default=False,
145
        ),
146
        level: int = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
147
            r"""
148
            The amount of detail to output.
149
            (1): 1-line description
150
            (2): + params
151
            (3) + full description
152
            (4) + param 1-line descriptions
153
            (5) + param full descriptions
154
            (6) + --hidden --common
155
            """,
156
            default=3,
157
            min=1,
158
            max=6,
159
        ),
160
        no_main: bool = Opt.flag(r"Exclude main commands."),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
161
        no_search: bool = Opt.flag(r"Exclude search commands."),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
162
        hidden: bool = Opt.flag(r"Show hidden commands."),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
163
        common: bool = Opt.flag(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
164
            r"""
165
            Show common arguments and options.
166
167
            Includes --log and --stderr, along with path, --key, --to, etc. for searches.
168
            """
169
        ),
170
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
171
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
172
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
173
    ):
174
        r"""
175
        Write documentation on commands to a file.
176
        """
177
        LOG_SETUP(log, stderr)
178
        if level == 5:
179
            hidden = common = True
180
        if width is None and style != "table":
181
            width = 100
182
        elif width == 0:
183
            width = None
184
        default = f"commands-level{level}.rst"
185
        to = EntryUtils.adjust_filename(to, default, replace=replace)
186
        Documenter(
187
            level=level,
188
            main=not no_main,
189
            search=not no_search,
190
            hidden=hidden,
191
            common=common,
192
            width=width,
193
        ).document(_InsertedCommandListSingleton.commands, to, style)
194
195
    @staticmethod
196
    def fill(
0 ignored issues
show
best-practice introduced by
Too many arguments (7/5)
Loading history...
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
197
        path: Path = Arg.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
198
            rf"""
199
            {DfCliHelp.help(InputCompoundsDf).get_short_text(nl=nl)}
200
            """,
201
        ),
202
        to: Path = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
203
            rf"""
204
            {DfCliHelp.help(IdMatchDf).get_short_text(nl=nl)}
205
206
            [default: <path>-ids-<start-time>{DEF_SUFFIX}]
207
            """
208
        ),
209
        no_pubchem: bool = Opt.flag("Do not use PubChem.", "--no-pubchem"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
210
        no_chembl: bool = Opt.flag("Do not use ChEMBL.", "--no-chembl"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
211
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
212
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
213
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
214
    ) -> None:
215
        r"""
216
        Fill in missing IDs from existing compound data.
217
218
        The idea is to find a ChEMBL ID, a PubChem ID, and parent-compound InChI/InChI Key.
219
        Useful to check compound/ID associations before running a search.
220
221
        To be filled, each row must should have a non-null value for
222
        "inchikey", "chembl_id", and/or "pubchem_id".
223
        "inchi" will be used but not to match to PubChem and ChEMBL.
224
225
        No existing columns will be dropped or modified.
226
        Any conflicting column will be renamed to 'origin_<column>'.
227
        E.g. 'inchikey' will be renamed to 'origin_inchikey'.
228
        (Do not include a column beginning with 'origin_').
229
230
        Final columns (assuming --no-chembl and --no-pubchem) will include:
231
        inchikey, inchi, pubchem_id, chembl_id, pubchem_inch, chembl_inchi,
232
        pubchem_inchikey, and chembl_inchikey.
233
        The "inchikey" and "inchikey" columns will be the "best" available:
234
        chembl (preferred), then pubchem, then your source inchikey column.
235
        In cases where PubChem and ChEMBL differ, an error will be logged.
236
        You can always check the columns "origin_inchikey" (yours),
237
        chembl_inchikey, and pubchem_inchikey.
238
239
        The steps are:
240
241
        - If "chembl_id" or "pubchem_id" is non-null, uses that to find an InChI Key (for each).
242
243
        - Otherwise, if only "inchikey" is non-null, uses it to find ChEMBL and PubChem records.
244
245
        - Log an error if the inchikeys or inchis differ between PubChem and ChEMBL.
246
247
        - Set the final "inchi" and "inchikey" to the best choice,
248
          falling back to the input inchi and inchikey if they are missing.
249
        """
250
        LOG_SETUP(log, stderr)
251
        default = str(Path(path).with_suffix("")) + "-filled" + "".join(path.suffixes)
252
        to = EntryUtils.adjust_filename(to, default, replace=replace)
253
        df = IdMatchDf.read_file(path)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
254
        df = CompoundIdFiller(chembl=not no_chembl, pubchem=not no_pubchem).fill(df)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
255
        df.write_file(to)
256
257
    @staticmethod
258
    def cache_data(
259
        path: Path = Ca.in_compound_table,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
260
        no_pubchem: bool = Opt.flag(r"Do not download data from PubChem", "--no-pubchem"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
261
        no_chembl: bool = Opt.flag(r"Do not fetch IDs from ChEMBL", "--no_chembl"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
262
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
263
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
264
    ) -> None:
265
        r"""
266
        Fetch and cache compound data.
267
268
        Useful to freeze data before running a search.
269
        """
270
        LOG_SETUP(log, stderr)
271
        df = IdMatchDf.read_file(path)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
272
        CompoundIdFiller(chembl=not no_chembl, pubchem=not no_pubchem).fill(df)
273
        logger.notice(f"Done caching")
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
274
275
    @staticmethod
276
    def export_taxa(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
best-practice introduced by
Too many arguments (6/5)
Loading history...
277
        taxa: str = Ca.taxa,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
278
        to: Path = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
279
            rf"""
280
            {DfCliHelp.help(TaxonomyDf).get_short_text(nl=nl)}
281
282
            [default: ./<taxa>-<datetime>{DEF_SUFFIX}]
283
            """
284
        ),
285
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
286
        in_cache: bool = CommonArgs.in_cache,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
287
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
288
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
289
    ):
290
        """
291
        Export a taxonomic tree to a table.
292
293
        Writes a taxonomy of given taxa and their descendants to a table.
294
        """
295
        LOG_SETUP(log, stderr)
296
        default = taxa + "-" + Globals.start_timestamp_filesys + DEF_SUFFIX
297
        to = EntryUtils.adjust_filename(to, default, replace=replace)
298
        tax = ArgUtils.get_taxonomy(taxa, local_only=in_cache, allow_forbid=False)
299
        tax.to_df().write_file(to, mkdirs=True, file_hash=True)
300
301
    @staticmethod
302
    def cache_taxa(
303
        taxa: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
304
            r"""
305
            Either "@all" or a comma-separated list of UniProt taxon IDs.
306
307
            "@all" is only valid when --replace is passed;
308
            this will regenerate all taxonomy files that are found in the cache.
309
            Aliases "vertebrata", "cellular", and "viral" are permitted.
310
            """,
311
            default="",
312
        ),
313
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
314
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
315
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
316
    ) -> None:
317
        """
318
        Prep a new taxonomy file for use in mandos.
319
320
        With --replace set, will delete any existing file.
321
        This can be useful to make sure your cached taxonomy is up-to-date before running.
322
323
        Downloads and converts a tab-separated file from UniProt.
324
        (To find manually, follow the ``All lower taxonomy nodes`` link and click ``Download``.)
325
        Then applies fixes and reduces the file size, creating a new file alongside.
326
        Puts both the raw data and fixed data in the cache under ``~/.mandos/taxonomy/``.
327
        """
328
        LOG_SETUP(log, stderr)
329
        if taxa == "@all" and not replace:
330
            raise XValueError(f"Use --replace with '@all'")
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
331
        # we're good to go:
332
        factory = TaxonomyFactories.main()
333
        if taxa == "@all":
334
            taxa = TaxonomyFactories.list_cached_files().keys()
335
        else:
336
            taxa = ArgUtils.parse_taxa_ids(taxa)
337
        factory.rebuild(taxa, replace=replace)
338
339
    @staticmethod
340
    def cache_g2p(
341
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
342
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
343
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
344
    ) -> None:
345
        """
346
        Caches GuideToPharmacology data.
347
348
        With --replace set, will overwrite existing cached data.
349
        Data will generally be stored under``~/.mandos/g2p/``.
350
        """
351
        LOG_SETUP(log, stderr)
352
        api = CachingG2pApi(SETTINGS.g2p_cache_path)
353
        api.download(force=replace)
354
355
    @staticmethod
356
    def cache_clear(
357
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
358
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
359
        yes: bool = CommonArgs.yes,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
360
    ) -> None:
361
        """
362
        Deletes all cached data.
363
        """
364
        LOG_SETUP(log, stderr)
365
        typer.echo(f"Will recursively delete all of these paths:")
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
366
        for p in SETTINGS.all_cache_paths:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "p" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
367
            typer.echo(f"    {p}")
368
        if not yes:
369
            typer.confirm("Delete?", abort=True)
370
        for p in SETTINGS.all_cache_paths:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "p" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
371
            p.unlink(missing_ok=True)
372
        logger.notice("Deleted all cached data")
373
374
    @staticmethod
375
    def concat(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
376
        path: Path = Arg.in_dir(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
377
            rf"""
378
            Directory containing results from a mandos search.
379
380
            {DfCliHelp.list_formats().get_short_text()}
381
            """
382
        ),
383
        to: Optional[Path] = Ca.out_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
384
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
385
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
386
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
387
    ) -> None:
388
        r"""
389
        Concatenate Mandos annotation files into one.
390
391
        Note that ``:search`` automatically performs this;
392
        this is needed only if you want to combine results from multiple independent searches.
393
        """
394
        LOG_SETUP(log, stderr)
395
        files_ = []
396
        for file in path.iterdir():
397
            ff = FileFormat.from_path_or_none(file)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "ff" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
398
            if ff not in [None, FileFormat.json, FileFormat.toml] and not ff.name.endswith(
399
                ".doc.tsv"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
400
            ):
401
                files_.append(file)
402
        logger.info(f"Looking under {path} (NOT recursive)")
403
        logger.debug(f"Found {len(files_)} potential input files: {[f.name for f in files_]}")
404
        files, dfs = [], []
405
        for file in files_:
406
            try:
407
                df: HitDf = HitDf.read_file(file, attrs=True)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
408
            except InvalidDfError:
409
                logger.warning(f"Skipping {file} {Chars.en} not a valid hit list")
410
                logger.debug(f"Error reading {file}", exc_info=True)
411
                continue
412
            df = df.set_attrs({file.name: df.attrs})
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
413
            dfs.append(df)
414
            files.append(file)
415
        names = [CompressionFormat.strip_suffix(f).name for f in files]
416
        default = path / (",".join(names) + DEF_SUFFIX)
417
        to = EntryUtils.adjust_filename(to, default, replace)
418
        logger.notice(f"Concatenated {len(files)} files")
419
        for f_, df_ in zip(files, dfs):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f_" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
420
            logger.success(f"Included: {f_.name} with {len(df_)} rows")
421
        df = HitDf.of(pd.concat(dfs))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
422
        counts = {k: v for k, v in df.group_by("universal_id").count().to_dict() if v > 0}
423
        if len(counts) > 0:
424
            logger.error(
425
                f"There are {len(counts)} universal IDs with duplicates!"
426
                + f": {StringTools.join_kv(counts)}"
427
            )
428
        logger.notice(f"Wrote {len(df)} rows to {to}")
429
        df.write_file(to)
430
431
    @staticmethod
432
    def filter(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
Coding Style Naming introduced by
Argument name "by" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
433
        path: Path = Ca.out_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
434
        by: Optional[Path] = Arg.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
435
            r"""
436
            Path to a file containing filters.
437
438
            See the docs for more info.
439
            """
440
        ),
441
        to: Optional[Path] = Ca.out_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
442
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
443
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
444
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
445
    ) -> None:
446
        """
447
        Filters by simple expressions.
448
        """
449
        LOG_SETUP(log, stderr)
450
        default = str(path) + "-filter-" + by.stem + DEF_SUFFIX
451
        to = EntryUtils.adjust_filename(to, default, replace)
452
        df = HitDf.read_file(path)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
453
        Filtration.from_file(by).apply(df).write_file(to)
454
455
    @staticmethod
456
    def export_state(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
457
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
458
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
459
            """
460
            Path to the output file.
461
462
            Valid formats and filename suffixes are .nt and .txt with an optional .gz, .zip, or .xz.
463
            If only a filename suffix is provided, will use that suffix with the default directory.
464
            If no suffix is provided, will interpret the path as a directory and use the default filename.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
465
            Will fail if the file exists and ``--replace`` is not set.
466
467
            [default: <path>-statements.nt]
468
        """
469
        ),
470
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
471
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
    ) -> None:
474
        """
475
        Output simple N-triples statements.
476
477
        Each statement is of this form, where the InChI Key refers to the input data:
478
479
        `"InChI Key" "predicate" "object" .`
480
        """
481
        LOG_SETUP(log, stderr)
482
        default = f"{path}-statements.nt"
483
        to = EntryUtils.adjust_filename(to, default, replace)
484
        hits = HitDf.read_file(path).to_hits()
485
        with to.open() as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
486
            for hit in hits:
487
                f.write(hit.to_triple.n_triples)
488
489
    @staticmethod
490
    def export_reify(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
491
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
492
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
493
            r"""
494
            Path to the output file.
495
496
            The filename suffix should be either .nt (N-triples) or .ttl (Turtle),
497
            with an optional .gz, .zip, or .xz.
498
            If only a filename suffix is provided, will use that suffix with the default directory.
499
            If no suffix is provided, will interpret the path as a directory but use the default filename.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
500
            Will fail if the file exists and ``--replace`` is not set.
501
502
            [default: <path>-reified.nt]
503
            """
504
        ),
505
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
506
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
507
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
508
    ) -> None:
509
        """
510
        Outputs reified semantic triples.
511
        """
512
        LOG_SETUP(log, stderr)
513
        default = f"{path}-reified.nt"
514
        to = EntryUtils.adjust_filename(to, default, replace)
515
        hits = HitDf.read_file(path).to_hits()
516
        with to.open() as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
517
            for triple in Reifier().reify(hits):
518
                f.write(triple.n_triples)
519
520
    @staticmethod
521
    def export_copy(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
522
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
523
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
524
            rf"""
525
            Path to the output file.
526
527
            {DfCliHelp.list_formats().get_short_text()}
528
529
            [default: <path.parent>/export{DEF_SUFFIX}]
530
            """
531
        ),
532
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
533
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
534
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
535
    ) -> None:
536
        """
537
        Copies and/or converts annotation files.
538
539
        Example: ``:export:copy --to .snappy`` to highly compress a data set.
540
        """
541
        LOG_SETUP(log, stderr)
542
        default = path.parent / DEF_SUFFIX
543
        to = EntryUtils.adjust_filename(to, default, replace)
544
        df = HitDf.read_file(path)
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
545
        df.write_file(to)
546
547
    @staticmethod
548
    def serve(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "db" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
549
        port: int = Opt.val(r"Port to serve on", default=1540),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument port seems to be unused.
Loading history...
550
        db: str = Opt.val("Name of the MySQL database", default="mandos"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument db seems to be unused.
Loading history...
551
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
552
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
553
    ) -> None:
554
        r"""
555
        Start a REST server.
556
557
        The connection information is stored in your global settings file.
558
        """
559
        LOG_SETUP(log, stderr)
560
561
    @staticmethod
562
    def export_db(
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
Coding Style Naming introduced by
Argument name "db" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
563
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument path seems to be unused.
Loading history...
564
        db: str = Opt.val(r"Name of the MySQL database", default="mandos"),
0 ignored issues
show
Unused Code introduced by
The argument db seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
565
        host: str = Opt.val(
0 ignored issues
show
Unused Code introduced by
The argument host seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
566
            r"Database hostname (ignored if ``--socket`` is passed", default="127.0.0.1"
567
        ),
568
        socket: Optional[str] = Opt.val("Path to a Unix socket (if set, ``--host`` is ignored)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument socket seems to be unused.
Loading history...
569
        user: Optional[str] = Opt.val("Database username (empty if not set)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument user seems to be unused.
Loading history...
570
        password: Optional[str] = Opt.val("Database password (empty if not set)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument password seems to be unused.
Loading history...
571
        as_of: Optional[str] = CommonArgs.as_of,
0 ignored issues
show
Unused Code introduced by
The argument as_of seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
572
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
573
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
574
    ) -> None:
575
        r"""
576
        Export to a relational database.
577
578
        Saves data from Mandos search commands to a database for serving via REST.
579
580
        See also: ``:serve``.
581
        """
582
        LOG_SETUP(log, stderr)
583
584
    @staticmethod
585
    def init_db(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "db" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
best-practice introduced by
Too many arguments (9/5)
Loading history...
586
        db: str = Opt.val(r"Name of the MySQL database", default="mandos"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument db seems to be unused.
Loading history...
587
        host: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument host seems to be unused.
Loading history...
588
            r"Database hostname (ignored if ``--socket`` is passed", default="127.0.0.1"
589
        ),
590
        socket: Optional[str] = Opt.val("Path to a Unix socket (if set, ``--host`` is ignored)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument socket seems to be unused.
Loading history...
591
        user: Optional[str] = Opt.val("Database username (empty if not set)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument user seems to be unused.
Loading history...
592
        password: Optional[str] = Opt.val("Database password (empty if not set)"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument password seems to be unused.
Loading history...
593
        overwrite: bool = Opt.flag(r"Delete the database if it exists"),
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument overwrite seems to be unused.
Loading history...
594
        yes: bool = Ca.yes,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument yes seems to be unused.
Loading history...
595
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
596
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
597
    ) -> None:
598
        r"""
599
        Initialize an empty database.
600
        """
601
        LOG_SETUP(log, stderr)
602
603
604
__all__ = ["MiscCommands"]
605