Skip to content

Commit 240dc21

Browse files
authored
Merge pull request #683 from deadmanoz/add-version-fix-stop-all-bug
Adds version, fixes stop all bug, extra feedback when user select "n" for custom network
2 parents 296e0ba + 0193078 commit 240dc21

File tree

5 files changed

+82
-9
lines changed

5 files changed

+82
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ warnet.egg-info
77
dist/
88
build/
99
**/kubeconfigs/
10+
src/warnet/_version.py

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "warnet"
3-
version = "1.1.11"
3+
dynamic = ["version"]
44
description = "Monitor and analyze the emergent behaviours of bitcoin networks"
55
readme = "README.md"
66
requires-python = ">=3.9"
@@ -34,7 +34,7 @@ warcli = "warnet.main:cli"
3434

3535
[project.urls]
3636
Homepage = "https://warnet.dev"
37-
GitHub = "https://github.com/bitcoindevproject/warnet"
37+
GitHub = "https://github.com/bitcoin-dev-project/warnet"
3838
Pypi = "https://pypi.org/project/warnet/"
3939

4040
[project.optional-dependencies]
@@ -56,3 +56,8 @@ include = ["warnet*", "test_framework*", "resources*"]
5656

5757
[tool.setuptools.package-data]
5858
"resources" = ["**/*"]
59+
60+
[tool.setuptools_scm]
61+
write_to = "src/warnet/_version.py"
62+
version_scheme = "no-guess-dev"
63+
local_scheme = "node-and-date"

src/warnet/control.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,33 @@ def stop_scenario(scenario_name):
112112
)
113113

114114

115-
def stop_all_scenarios(scenarios):
116-
"""Stop all active scenarios in parallel using multiprocessing"""
115+
def _stop_single(scenario: str) -> str:
116+
"""
117+
Stop a single scenario
118+
119+
Args:
120+
scenario: Name of the scenario to stop
121+
122+
Returns:
123+
str: Message indicating the scenario has been stopped
124+
"""
125+
stop_scenario(scenario)
126+
return f"Stopped scenario: {scenario}"
127+
117128

118-
def stop_single(scenario):
119-
stop_scenario(scenario)
120-
return f"Stopped scenario: {scenario}"
129+
def stop_all_scenarios(scenarios) -> None:
130+
"""
131+
Stop all active scenarios in parallel using multiprocessing
132+
133+
Args:
134+
scenarios: List of scenario names to stop
135+
136+
Returns:
137+
None
138+
"""
121139

122140
with console.status("[bold yellow]Stopping all scenarios...[/bold yellow]"), Pool() as pool:
123-
results = pool.map(stop_single, scenarios)
141+
results = pool.map(_stop_single, scenarios)
124142

125143
for result in results:
126144
console.print(f"[bold green]{result}[/bold green]")

src/warnet/main.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,49 @@ def cli():
1818
pass
1919

2020

21+
@click.command()
22+
def version() -> None:
23+
"""Display the installed version of warnet"""
24+
try:
25+
from warnet._version import __version__
26+
27+
# For PyPI releases, this will be the exact tag (e.g. "1.1.11")
28+
# For dev installs, it will be something like "1.1.11.post1.dev17+g27af3a7.d20250309"
29+
# Which is <tag>.post<postN>.dev<devN>+g<git commit hash>.d<YYYYMMDD>
30+
# <postN> is the number of local commits since the checkout commit
31+
# <devN> is the number of commits since the last tag
32+
raw_version = __version__
33+
34+
# Format the version string to our desired format
35+
if "+" in raw_version:
36+
version_part, git_date_part = raw_version.split("+", 1)
37+
38+
# Get just the git commit hash
39+
commit_hash = (
40+
git_date_part[1:].split(".", 1)[0]
41+
if git_date_part.startswith("g")
42+
else git_date_part.split(".", 1)[0]
43+
)
44+
45+
# Remove .dev component (from "no-guess-dev" scheme)
46+
clean_version = version_part
47+
if ".dev" in clean_version:
48+
clean_version = clean_version.split(".dev")[0]
49+
50+
# Apply dirty status (from "no-guess-dev" scheme)
51+
if ".post" in clean_version:
52+
base = clean_version.split(".post")[0]
53+
version_str = f"{base}-{commit_hash}-dirty"
54+
else:
55+
version_str = f"{clean_version}-{commit_hash}"
56+
else:
57+
version_str = raw_version
58+
59+
click.echo(f"warnet version {version_str}")
60+
except ImportError:
61+
click.echo("warnet version unknown")
62+
63+
2164
cli.add_command(admin)
2265
cli.add_command(auth)
2366
cli.add_command(bitcoin)
@@ -37,7 +80,7 @@ def cli():
3780
cli.add_command(status)
3881
cli.add_command(stop)
3982
cli.add_command(create)
40-
83+
cli.add_command(version)
4184

4285
if __name__ == "__main__":
4386
cli()

src/warnet/project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ def new_internal(directory: Path, from_init=False):
431431
if proj_answers["custom_network"]:
432432
click.secho("\nGenerating custom network...", fg="yellow", bold=True)
433433
custom_network_path = inquirer_create_network(directory)
434+
else:
435+
click.echo(
436+
f"No custom network specified, see example network files in {project_path}/networks/"
437+
)
438+
click.echo("Deploy any of these networks by running:")
439+
click.echo(f" warnet deploy {project_path}/networks/<example-network-name>")
434440

435441
if custom_network_path:
436442
click.echo(

0 commit comments

Comments
 (0)