Conditions | 2 |
Total Lines | 54 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | """ |
||
19 | @classmethod |
||
20 | def make(cls) -> CmdNamespace: |
||
21 | from mandos.entry.calc_commands import CalcCommands |
||
22 | from mandos.entry.entry_commands import Entries |
||
23 | from mandos.entry.misc_commands import ( |
||
24 | MiscCommands, |
||
25 | _InsertedCommandListSingleton, |
||
26 | ) |
||
27 | from mandos.entry.plot_commands import PlotCommands |
||
28 | |||
29 | cli.registered_commands += [ |
||
30 | CommandInfo(":document", callback=MiscCommands.document), |
||
31 | CommandInfo(":search", callback=MiscCommands.search), |
||
32 | CommandInfo(":init", callback=MiscCommands.init, hidden=True), |
||
33 | CommandInfo(":settings", callback=MiscCommands.list_settings, hidden=True), |
||
34 | CommandInfo(":fill", callback=MiscCommands.fill), |
||
35 | CommandInfo(":cache:data", callback=MiscCommands.cache_data), |
||
36 | CommandInfo(":cache:taxa", callback=MiscCommands.cache_taxa), |
||
37 | CommandInfo(":cache:g2p", callback=MiscCommands.cache_g2p), |
||
38 | CommandInfo(":cache:clear", callback=MiscCommands.cache_clear), |
||
39 | CommandInfo(":export:taxa", callback=MiscCommands.export_taxa), |
||
40 | CommandInfo(":concat", callback=MiscCommands.concat), |
||
41 | CommandInfo(":filter", callback=MiscCommands.filter), |
||
42 | CommandInfo(":export:copy", callback=MiscCommands.export_copy), |
||
43 | CommandInfo(":export:state", callback=MiscCommands.export_state), |
||
44 | CommandInfo(":export:reify", callback=MiscCommands.export_reify), |
||
45 | CommandInfo(":export:db", callback=MiscCommands.export_db, hidden=True), |
||
46 | CommandInfo(":init-db", callback=MiscCommands.init_db, hidden=True), |
||
47 | CommandInfo(":serve", callback=MiscCommands.serve, hidden=True), |
||
48 | CommandInfo(":calc:enrichment", callback=CalcCommands.calc_enrichment), |
||
49 | CommandInfo(":calc:phi", callback=CalcCommands.calc_phi), |
||
50 | CommandInfo(":calc:psi", callback=CalcCommands.calc_psi), |
||
51 | CommandInfo(":calc:ecfp", callback=CalcCommands.calc_ecfp, hidden=True), |
||
52 | CommandInfo(":calc:psi-projection", callback=CalcCommands.calc_projection), |
||
53 | CommandInfo(":calc:tau", callback=CalcCommands.calc_tau), |
||
54 | CommandInfo(":plot:enrichment", callback=PlotCommands.plot_enrichment), |
||
55 | CommandInfo(":plot:psi-projection", callback=PlotCommands.plot_projection), |
||
56 | CommandInfo(":plot:psi-heatmap", callback=PlotCommands.plot_heatmap), |
||
57 | CommandInfo(":plot:phi-vs-psi", callback=PlotCommands.plot_phi_psi), |
||
58 | CommandInfo(":plot:tau", callback=PlotCommands.plot_tau), |
||
59 | ] |
||
60 | commands = {c.name: c for c in cli.registered_commands} |
||
61 | # Oh dear this is a nightmare |
||
62 | # it's really hard to create typer commands with dynamically configured params -- |
||
63 | # we really need to rely on its inferring of params |
||
64 | # that makes this really hard to do well |
||
65 | for entry in Entries: |
||
66 | cmd = entry.cmd() |
||
67 | info = CommandInfo(cmd, callback=entry.run) |
||
68 | cli.registered_commands.append(info) |
||
69 | # print(f"Registered {entry.cmd()} to {entry}") |
||
70 | commands[cmd] = entry.run |
||
71 | _InsertedCommandListSingleton.commands = cli.registered_commands |
||
72 | return cls(**commands) |
||
73 | |||
145 |