Skip to content

Commit f3bd4b0

Browse files
authored
Merge pull request #56 from aCLImatise/reanalyse
Reanalyse
2 parents 5004121 + 251e2b5 commit f3bd4b0

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ jobs:
114114
publish_dir: docs/_build/html
115115
publish_branch: gh-pages
116116
enable_jekyll: false
117+
118+
- name: Update Basecamp
119+
uses: peter-evans/repository-dispatch@v1
120+
with:
121+
token: ${{ secrets.REPOACCESSTOKEN }}
122+
event-type: aclimatise-update

aclimatise/model.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from spacy import tokens
1919
from word2number import w2n
2020

21+
import aclimatise
2122
from aclimatise import cli_types
2223
from aclimatise.cli_types import CliFileSystemType, CliString
2324
from aclimatise.name_generation import generate_name, segment_string
@@ -82,6 +83,37 @@ def __post_init__(self):
8283
self.usage_flag = flag
8384
self.named.remove(flag)
8485

86+
def __getitem__(self, item: str) -> "Command":
87+
"""
88+
If present, returns a subcommand with the following name. For example, samtools_cmd['sort'] will return the
89+
"samtools sort" command
90+
"""
91+
for sub in self.subcommands:
92+
if sub.command == [*self.command, item]:
93+
return sub
94+
raise KeyError(
95+
"{} does not have a subcommand {}".format(" ".join(self.command), item)
96+
)
97+
98+
def reanalyse(self, parent: "Command" = None) -> "Command":
99+
"""
100+
Re-analyses the entire command tree using the existing help text but the current parser, and returns the new tree
101+
"""
102+
if len(self.subcommands) > 0:
103+
return Command(
104+
generated_using=self.generated_using,
105+
help_text=self.help_text,
106+
command=self.command,
107+
subcommands=[cmd.reanalyse(self) for cmd in self.subcommands],
108+
parent=parent,
109+
)
110+
else:
111+
replacement = aclimatise.parse_help(cmd=self.command, text=self.help_text)
112+
replacement.parent = parent
113+
replacement.help_text = self.help_text
114+
replacement.generated_using = self.generated_using
115+
return replacement
116+
85117
@property
86118
def outputs(self) -> typing.List["CliArgument"]:
87119
"""

docs/changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Changelog
22
=========
3+
2.2.0 (2020-09-26)
4+
------------------
5+
* Add ``command.reanalyse()``, which re-analyses the help text stored in the command, using the current parser
6+
* Add ``command['sort']`` which lets you access subcommands by name
7+
38
2.1.0 (2020-09-22)
49
----------------
510
* Add `bedtools random` as a test case

test/test_model.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from aclimatise.model import Command
2+
3+
4+
def test_reanalyse(samtools_cmd: Command):
5+
"""
6+
Test the command.reanalyse() method
7+
"""
8+
reanalysed = samtools_cmd.reanalyse()
9+
assert reanalysed.help_text == samtools_cmd.help_text
10+
assert len(reanalysed.subcommands) == len(samtools_cmd.subcommands)
11+
12+
re_sort = reanalysed["sort"]
13+
assert len(re_sort.positional) > 0
14+
assert len(re_sort.named) > 0

0 commit comments

Comments
 (0)