Passed
Push — main ( f62a2c...b1b54a )
by Douglas
02:02
created

MiscCommands.export_copy()   B

Complexity

Conditions 3

Size

Total Lines 64
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 39
nop 6
dl 0
loc 64
rs 8.9439
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...
Unused Code introduced by
Unused pandas imported as pd
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...
Unused Code introduced by
Unused Chars imported from 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 Checksums, 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...
Unused Code introduced by
Unused InvalidDfError imported from typeddfs.df_errors
Loading history...
19
from typeddfs.typed_dfs import PlainTypedDf, TypedDf
0 ignored issues
show
introduced by
Unable to import 'typeddfs.typed_dfs'
Loading history...
20
from typeddfs.utils import Utils as TdfUtils
0 ignored issues
show
introduced by
Unable to import 'typeddfs.utils'
Loading history...
21
from typeddfs.utils.cli_help import DfCliHelp
0 ignored issues
show
introduced by
Unable to import 'typeddfs.utils.cli_help'
Loading history...
22
23
from mandos.analysis.filtration import Filtration
24
from mandos.analysis.io_defns import (
25
    ConcordanceDf,
26
    EnrichmentDf,
27
    PhiPsiSimilarityDfLongForm,
28
    PsiProjectedDf,
29
    ScoreDf,
30
    SimilarityDfLongForm,
31
)
32
from mandos.analysis.reification import Reifier
33
from mandos.entry import entry
34
from mandos.entry.tools.docs import Documenter
35
from mandos.entry.tools.fillers import CompoundIdFiller, IdMatchDf
36
from mandos.entry.tools.multi_searches import MultiSearch, SearchConfigDf
37
from mandos.entry.tools.searchers import InputCompoundsDf
38
from mandos.entry.utils._arg_utils import Arg, ArgUtils, EntryUtils, Opt
39
from mandos.entry.utils._common_args import CommonArgs
40
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 39. You should be able to
remove this line.
Loading history...
41
from mandos.model.apis.g2p_api import CachingG2pApi
42
from mandos.model.hit_dfs import HitDf
43
from mandos.model.settings import SETTINGS
44
from mandos.model.taxonomy import TaxonomyDf
45
from mandos.model.taxonomy_caches import TaxonomyFactories
46
from mandos.model.utils import unlink
47
from mandos.model.utils.globals import Globals
48
from mandos.model.utils.setup import LOG_SETUP, logger
49
50
DEF_SUFFIX = SETTINGS.table_suffix
51
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...
52
53
54
class _InsertedCommandListSingleton:
55
    commands = None
56
57
58
@decorateme.auto_utils()
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
59
class MiscCommands:
60
    @staticmethod
61
    @entry()
62
    def search(
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 (8/5)
Loading history...
63
        path: Path = Ca.in_compound_table,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
64
        config: Path = Opt.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
65
            r"""
66
            TOML config file. See the docs.
67
            """,
68
            default=...,
69
        ),
70
        to: Path = Ca.out_wildcard,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
71
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
72
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
73
        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...
74
        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...
75
        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...
76
    ) -> None:
77
        r"""
78
        Run multiple searches.
79
        """
80
        LOG_SETUP(log, stderr)
81
        default = path.parent / ("search-" + Globals.start_time.strftime("%Y-%m-%d"))
82
        # TODO: , suffixes=FileFormat.from_path
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
83
        out_dir, suffix = EntryUtils.adjust_dir_name(to, default)
84
        logger.notice(f"Will write {suffix} to {out_dir}{os.sep}")
85
        config_fmt = FileFormat.from_path(config)
86
        if config_fmt is not FileFormat.toml:
87
            logger.caution(f"Config format is {config_fmt}, not toml; trying anyway")
88
        config = SearchConfigDf.read_file(config)
89
        search = MultiSearch(config, path, out_dir, suffix, replace, proceed, log)
90
        if not check:
91
            search.run()
92
93
    @staticmethod
94
    @entry()
95
    def init(
96
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
97
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
98
    ):
99
        """
100
        Initializes mandos, creating directories, etc.
101
        """
102
        LOG_SETUP(log, stderr)
103
        Globals.mandos_path.mkdir(exist_ok=True, parents=True)
104
        typer.echo(f"Mandos home dir is {Globals.mandos_path}")
105
        if Globals.settings_path.exists():
106
            typer.echo(f"Settings found at {Globals.settings_path}")
107
        else:
108
            typer.echo("No settings file found")
109
        typer.echo(f"Log level for stderr is level {logger.current_stderr_log_level}")
110
111
    @staticmethod
112
    @entry()
113
    def list_settings(
114
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
115
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
116
    ):
117
        r"""
118
        Write the settings to stdout.
119
        """
120
        LOG_SETUP(log, stderr)
121
        defaults = SETTINGS.defaults()
122
        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...
123
        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...
124
            msg = f"{k} = {v}".ljust(width)
125
            if v != defaults[k]:
126
                msg += f" (default: {defaults[k]})"
127
            typer.echo(msg)
128
129
    @staticmethod
130
    @entry()
131
    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...
132
        to: Path = Opt.out_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
133
            rf"""
134
            The path to write command documentation to.
135
136
        `   For machine-readable output: {DfCliHelp.list_formats().get_short_text()}.
137
            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...
138
139
            [default: "commands-level<level>.rst"]
140
            """
141
        ),
142
        style: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
143
            rf"""
144
            The format for formatted text output.
145
146
            Use "table" for machine-readable output, "docs" for long-form reStructuredText,
147
            or {TdfUtils.join_to_str(TdfUtils.table_formats(), last="or")}
148
            """,
149
            "--style",
150
            default="docs",
151
        ),
152
        width: int = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
153
            r"""
154
            Max number of characters for a cell before wrap.
155
156
            [default: 0 (none) for machine-readable; 100 for formatted]
157
            """,
158
            default=None,
159
            show_default=False,
160
        ),
161
        level: int = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
162
            r"""
163
            The amount of detail to output.
164
            (1): 1-line description
165
            (2): + params
166
            (3) + full description
167
            (4) + param 1-line descriptions
168
            (5) + param full descriptions
169
            (6) + --hidden --common
170
            """,
171
            default=3,
172
            min=1,
173
            max=6,
174
        ),
175
        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...
176
        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...
177
        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...
178
        common: bool = Opt.flag(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
179
            r"""
180
            Show common arguments and options.
181
182
            Includes --log and --stderr, along with path, --key, --to, etc. for searches.
183
            """
184
        ),
185
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
186
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
187
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
188
    ):
189
        r"""
190
        Write documentation on commands to a file.
191
        """
192
        LOG_SETUP(log, stderr)
193
        if level == 5:
194
            hidden = common = True
195
        if width is None and style != "table":
196
            width = 100
197
        elif width == 0:
198
            width = None
199
        default = f"commands-level{level}.rst"
200
        to = EntryUtils.adjust_filename(to, default, replace=replace)
201
        Documenter(
202
            level=level,
203
            main=not no_main,
204
            search=not no_search,
205
            hidden=hidden,
206
            common=common,
207
            width=width,
208
        ).document(_InsertedCommandListSingleton.commands, to, style)
209
210
    @staticmethod
211
    @entry()
212
    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...
213
        path: Path = Arg.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
214
            rf"""
215
            {DfCliHelp.help(InputCompoundsDf).get_short_text(nl=nl)}
216
            """,
217
        ),
218
        to: Path = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
219
            rf"""
220
            {DfCliHelp.help(IdMatchDf).get_short_text(nl=nl)}
221
222
            [default: <path>-ids-<start-time>{DEF_SUFFIX}]
223
            """
224
        ),
225
        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...
226
        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...
227
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
228
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
229
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
230
    ) -> None:
231
        r"""
232
        Fill in missing IDs from existing compound data.
233
234
        The idea is to find a ChEMBL ID, a PubChem ID, and parent-compound InChI/InChI Key.
235
        Useful to check compound/ID associations before running a search.
236
237
        To be filled, each row must should have a non-null value for
238
        "inchikey", "chembl_id", and/or "pubchem_id".
239
        "inchi" will be used but not to match to PubChem and ChEMBL.
240
241
        No existing columns will be dropped or modified.
242
        Any conflicting column will be renamed to 'origin_<column>'.
243
        E.g. 'inchikey' will be renamed to 'origin_inchikey'.
244
        (Do not include a column beginning with 'origin_').
245
246
        Final columns (assuming --no-chembl and --no-pubchem) will include:
247
        inchikey, inchi, pubchem_id, chembl_id, pubchem_inch, chembl_inchi,
248
        pubchem_inchikey, and chembl_inchikey.
249
        The "inchikey" and "inchikey" columns will be the "best" available:
250
        chembl (preferred), then pubchem, then your source inchikey column.
251
        In cases where PubChem and ChEMBL differ, an error will be logged.
252
        You can always check the columns "origin_inchikey" (yours),
253
        chembl_inchikey, and pubchem_inchikey.
254
255
        The steps are:
256
257
        - If "chembl_id" or "pubchem_id" is non-null, uses that to find an InChI Key (for each).
258
259
        - Otherwise, if only "inchikey" is non-null, uses it to find ChEMBL and PubChem records.
260
261
        - Log an error if the inchikeys or inchis differ between PubChem and ChEMBL.
262
263
        - Set the final "inchi" and "inchikey" to the best choice,
264
          falling back to the input inchi and inchikey if they are missing.
265
        """
266
        LOG_SETUP(log, stderr)
267
        default = str(Path(path).with_suffix("")) + "-filled" + "".join(path.suffixes)
268
        to = EntryUtils.adjust_filename(to, default, replace=replace)
269
        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...
270
        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...
271
        df.write_file(to)
272
273
    @staticmethod
274
    @entry()
275
    def cache_data(
276
        path: Path = Ca.in_compound_table,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
277
        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...
278
        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...
279
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
280
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
281
    ) -> None:
282
        r"""
283
        Fetch and cache compound data.
284
285
        Useful to freeze data before running a search.
286
        """
287
        LOG_SETUP(log, stderr)
288
        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...
289
        CompoundIdFiller(chembl=not no_chembl, pubchem=not no_pubchem).fill(df)
290
        logger.notice(f"Done caching")
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
291
292
    @staticmethod
293
    @entry()
294
    def export_taxa(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/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...
295
        taxa: str = Ca.taxa,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
296
        to: Path = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
297
            rf"""
298
            {DfCliHelp.help(TaxonomyDf).get_short_text(nl=nl)}
299
300
            [default: ./<taxa>-<datetime>{DEF_SUFFIX}]
301
            """
302
        ),
303
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
304
        in_cache: bool = CommonArgs.in_cache,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
305
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
306
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
307
    ):
308
        """
309
        Export a taxonomic tree to a table.
310
311
        Writes a taxonomy of given taxa and their descendants to a table.
312
        """
313
        LOG_SETUP(log, stderr)
314
        default = taxa + "-" + Globals.start_timestamp_filesys + DEF_SUFFIX
315
        to = EntryUtils.adjust_filename(to, default, replace=replace)
316
        tax = ArgUtils.get_taxonomy(taxa, local_only=in_cache, allow_forbid=False).get
317
        tax.to_df().write_file(to, mkdirs=True, file_hash=True)
0 ignored issues
show
Bug introduced by
The Method get does not seem to have a member named to_df.

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...
318
319
    @staticmethod
320
    @entry()
321
    def cache_taxa(
322
        taxa: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
323
            r"""
324
            Either "@all" or a comma-separated list of UniProt taxon IDs.
325
326
            "@all" is only valid when --replace is passed;
327
            this will regenerate all taxonomy files that are found in the cache.
328
            Aliases "vertebrata", "cellular", and "viral" are permitted.
329
            """,
330
            default="",
331
        ),
332
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
333
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
334
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
335
    ) -> None:
336
        """
337
        Prep a new taxonomy file for use in mandos.
338
339
        With --replace set, will delete any existing file.
340
        This can be useful to make sure your cached taxonomy is up-to-date before running.
341
342
        Downloads and converts a tab-separated file from UniProt.
343
        (To find manually, follow the ``All lower taxonomy nodes`` link and click ``Download``.)
344
        Then applies fixes and reduces the file size, creating a new file alongside.
345
        Puts both the raw data and fixed data in the cache under ``~/.mandos/taxonomy/``.
346
        """
347
        LOG_SETUP(log, stderr)
348
        if taxa == "@all" and not replace:
349
            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...
350
        # we're good to go:
351
        factory = TaxonomyFactories.main()
352
        if taxa == "@all":
353
            taxa = TaxonomyFactories.list_cached_files().keys()
354
        else:
355
            taxa = ArgUtils.parse_taxa_ids(taxa)
356
        factory.rebuild(taxa, replace=replace)
357
358
    @staticmethod
359
    @entry()
360
    def cache_g2p(
361
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
362
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
363
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
364
    ) -> None:
365
        """
366
        Caches GuideToPharmacology data.
367
368
        With --replace set, will overwrite existing cached data.
369
        Data will generally be stored under``~/.mandos/g2p/``.
370
        """
371
        LOG_SETUP(log, stderr)
372
        api = CachingG2pApi(SETTINGS.g2p_cache_path)
373
        api.download(force=replace)
374
375
    @staticmethod
376
    @entry()
377
    def cache_clear(
378
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
379
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
380
    ) -> None:
381
        """
382
        Deletes all cached data.
383
        """
384
        LOG_SETUP(log, stderr)
385
        paths = ", ".join(
386
            [str(p.relative_to(SETTINGS.cache_path)) for p in SETTINGS.all_cache_paths]
387
        )
388
        logger.notice(f"Will recursively delete: {paths}")
389
        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...
390
            unlink(p, missing_ok=True)
391
        logger.notice("Deleted all cached data")
392
393
    @staticmethod
394
    @entry()
395
    def concat(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
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...
396
        path: Path = Arg.in_dir(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
397
            rf"""
398
            Directory containing results from a mandos search.
399
400
            {DfCliHelp.list_formats().get_short_text()}
401
            """
402
        ),
403
        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...
404
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
405
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
406
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
407
    ) -> None:
408
        r"""
409
        Concatenate Mandos annotation files into one.
410
411
        Note that ``:search`` automatically performs this;
412
        this is needed only if you want to combine results from multiple independent searches.
413
        """
414
        LOG_SETUP(log, stderr)
415
        files_ = []
416
        for file in path.iterdir():
417
            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...
418
            if ff not in [None, FileFormat.json, FileFormat.ini, FileFormat.toml]:
419
                files_.append(file)
420
        logger.notice(f"Looking under {path} (NOT recursive)")
421
        logger.info(f"Found {len(files_):,} potential input files: {[f.name for f in files_]}")
422
        files, names, dfs = [], [], []
423
        for file in files_:
424
            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...
425
            files.append(file)
426
            names.append(FileFormat.strip(file).name)
427
            dfs.append(df)
428
        default = path / (",".join(names) + DEF_SUFFIX)
429
        to = EntryUtils.adjust_filename(to, default, replace)
430
        df = HitDf.of(dfs, keys=names)
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...
431
        logger.notice(f"Concatenated {len(files):,} files")
432
        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...
433
            logger.success(f"Included: {f_.name} with {len(df_):,} rows")
434
        counts = {k: v for k, v in df.group_by("universal_id").count().to_dict() if v > 0}
435
        if len(counts) > 0:
436
            logger.error(
437
                f"There are {len(counts):,} universal IDs with duplicates!"
438
                + f": {StringTools.join_kv(counts)}"
439
            )
440
        logger.notice(f"Wrote {len(df):,} rows to {to}")
441
        df.write_file(to, mkdirs=True, attrs=True, file_hash=True)
442
443
    @staticmethod
444
    @entry()
445
    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...
446
        path: Path = Ca.out_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
447
        by: Optional[Path] = Arg.in_file(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
448
            r"""
449
            Path to a file containing filters.
450
451
            See the docs for more info.
452
            """
453
        ),
454
        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...
455
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
457
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
458
    ) -> None:
459
        """
460
        Filters by simple expressions.
461
        """
462
        LOG_SETUP(log, stderr)
463
        default = str(path) + "-filter-" + by.stem + DEF_SUFFIX
464
        to = EntryUtils.adjust_filename(to, default, replace)
465
        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...
466
        Filtration.from_file(by).apply(df).write_file(to)
467
468
    @staticmethod
469
    @entry()
470
    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...
471
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
            """
474
            Path to the output file.
475
476
            Valid formats and filename suffixes are .nt and .txt with an optional .gz, .zip, or .xz.
477
            If only a filename suffix is provided, will use that suffix with the default directory.
478
            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...
479
            Will fail if the file exists and ``--replace`` is not set.
480
481
            [default: <path>-statements.nt]
482
        """
483
        ),
484
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
485
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
486
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
487
    ) -> None:
488
        """
489
        Output simple N-triples statements.
490
491
        Each statement is of this form, where the InChI Key refers to the input data:
492
493
        `"InChI Key" "predicate" "object" .`
494
        """
495
        LOG_SETUP(log, stderr)
496
        default = f"{path}-statements.nt"
497
        to = EntryUtils.adjust_filename(to, default, replace)
498
        hits = HitDf.read_file(path).to_hits()
499
        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...
500
            for hit in hits:
501
                f.write(hit.to_triple.n_triples)
502
503
    @staticmethod
504
    @entry()
505
    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...
506
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
507
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
508
            r"""
509
            Path to the output file.
510
511
            The filename suffix should be either .nt (N-triples) or .ttl (Turtle),
512
            with an optional .gz, .zip, or .xz.
513
            If only a filename suffix is provided, will use that suffix with the default directory.
514
            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...
515
            Will fail if the file exists and ``--replace`` is not set.
516
517
            [default: <path>-reified.nt]
518
            """
519
        ),
520
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
521
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
522
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
523
    ) -> None:
524
        """
525
        Outputs reified semantic triples.
526
        """
527
        LOG_SETUP(log, stderr)
528
        default = f"{path}-reified.nt"
529
        to = EntryUtils.adjust_filename(to, default, replace)
530
        hits = HitDf.read_file(path).to_hits()
531
        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...
532
            for triple in Reifier().reify(hits):
533
                f.write(triple.n_triples)
534
535
    @staticmethod
536
    @entry()
537
    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...
best-practice introduced by
Too many arguments (6/5)
Loading history...
538
        path: Path = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
539
            rf"""
540
            Path to a CSV-like file corresponding to --what.
541
542
            {DfCliHelp.list_formats().get_short_text()}
543
            """
544
        ),
545
        what: str = Opt.val(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
546
            r"""
547
            The type of data.
548
549
            Options: "hits", "compounds", "score", "enrichment",
550
            "matrix" (long-form similarity), "concordance", "phi-psi",
551
            "projection", or "data" (arbitrary data).
552
            """,
553
            default="hits",
554
        ),
555
        to: Optional[Path] = Opt.out_path(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
556
            rf"""
557
            Path to the output file.
558
559
            {DfCliHelp.list_formats().get_short_text()}
560
561
            [default: <path.parent>/export{DEF_SUFFIX}]
562
            """
563
        ),
564
        replace: bool = Ca.replace,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
565
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
566
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
567
    ) -> None:
568
        """
569
        Copies and/or converts annotation files.
570
571
        Example: ``:export:copy --to .snappy`` to highly compress a data set.
572
        """
573
        LOG_SETUP(log, stderr)
574
        default = path.parent / DEF_SUFFIX
575
        what = dict(
576
            compounds=InputCompoundsDf,
577
            hits=HitDf,
578
            matrix=SimilarityDfLongForm,
579
            scores=ScoreDf,
580
            enrichment=EnrichmentDf,
581
            phi_psi=PhiPsiSimilarityDfLongForm,
582
            concordance=ConcordanceDf,
583
            projection=PsiProjectedDf,
584
            data=PlainTypedDf,
585
        )[what.lower().strip().replace("-", "_")]
586
        to = EntryUtils.adjust_filename(to, default, replace)
587
        attrs_path = path.parent / (path.name + ".attrs.json")
588
        hash_path = Checksums().get_filesum_of_file(path)
589
        attrs, file_hash = attrs_path.exists(), hash_path.exists()
590
        logger.info(f"Reading attributes: {attrs}")
591
        logger.info(f"Reading checksum file: {file_hash}")
592
        df: TypedDf = what.read_file(path, attrs=attrs, file_hash=file_hash)
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...
593
        df.write_file(to, mkdirs=True, attrs=attrs, file_hash=file_hash)
594
        logger.notice(f"Exported {path} to {path} ({len(df):,} rows")
595
        if attrs:
596
            logger.info(f"Wrote attributes to {attrs_path}")
597
        if file_hash:
598
            logger.info(f"Wrote single-file checksum to {hash_path}")
599
600
    @staticmethod
601
    @entry()
602
    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...
603
        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...
604
        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...
605
        log: Optional[Path] = Ca.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
606
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
607
    ) -> None:
608
        r"""
609
        Start a REST server.
610
611
        The connection information is stored in your global settings file.
612
        """
613
        LOG_SETUP(log, stderr)
614
615
    @staticmethod
616
    @entry()
617
    def export_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...
618
        path: Path = Ca.in_annotations_file,
0 ignored issues
show
Unused Code introduced by
The argument path seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
619
        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...
620
        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...
621
            r"Database hostname (ignored if ``--socket`` is passed", default="127.0.0.1"
622
        ),
623
        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...
624
        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...
625
        password: Optional[str] = Opt.val("Database password (empty if not set)"),
0 ignored issues
show
Unused Code introduced by
The argument password seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
626
        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...
627
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
628
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
629
    ) -> None:
630
        r"""
631
        Export to a relational database.
632
633
        Saves data from Mandos search commands to a database for serving via REST.
634
635
        See also: ``:serve``.
636
        """
637
        LOG_SETUP(log, stderr)
638
639
    @staticmethod
640
    @entry()
641
    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...
642
        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...
643
        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...
644
            r"Database hostname (ignored if ``--socket`` is passed", default="127.0.0.1"
645
        ),
646
        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...
647
        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...
648
        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...
649
        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...
650
        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...
651
        log: Optional[Path] = CommonArgs.log,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
652
        stderr: str = CommonArgs.stderr,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
653
    ) -> None:
654
        r"""
655
        Initialize an empty database.
656
        """
657
        LOG_SETUP(log, stderr)
658
659
660
__all__ = ["MiscCommands"]
661