-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
65 lines (51 loc) · 1.49 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pathlib
import runpy
import subprocess
import sys
from typing_extensions import Annotated
import typer
from coherent.build import bootstrap
from jaraco.vcs import Repo
from jaraco.versioning import Versioned, semver
app = typer.Typer()
passthrough_command = app.command(
context_settings={
'allow_extra_args': True,
'ignore_unknown_options': True,
},
)
@app.command()
def install(target: pathlib.Path) -> None:
with bootstrap.write_pyproject(target):
subprocess.run([sys.executable, '-m', 'pip', 'install', target])
@passthrough_command
def test() -> None:
del sys.argv[1]
runpy.run_module('coherent.test', run_name='__main__')
@passthrough_command
def build() -> None:
del sys.argv[1]
runpy.run_module('coherent.build', run_name='__main__')
@app.command(context_settings=dict(allow_extra_args=True))
def tag(
kind_or_name: str,
context: typer.Context,
repository: Annotated[
Repo,
typer.Option(
'-R', '--repository',
help='Path to repository.',
parser=Repo.detect,
),
] = '.',
) -> None:
if kind_or_name in Versioned.semantic_increment:
name = repository.get_next_version(kind_or_name)
else:
name = kind_or_name
final_name = semver(name)
args = ['-a', final_name, '-m', '', *context.args]
subprocess.run(['git', '-C', repository.location, 'tag', *args], check=True)
print(f"Created tag {final_name}")
if __name__ == '__main__':
app()