diff --git a/.gitignore b/.gitignore index f4b5d0076..35e704c67 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ warnet.egg-info dist/ build/ **/kubeconfigs/ +src/warnet/_version.py diff --git a/pyproject.toml b/pyproject.toml index b89ab783f..48d5d37f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "warnet" -version = "1.1.11" +dynamic = ["version"] description = "Monitor and analyze the emergent behaviours of bitcoin networks" readme = "README.md" requires-python = ">=3.9" @@ -34,7 +34,7 @@ warcli = "warnet.main:cli" [project.urls] Homepage = "https://warnet.dev" -GitHub = "https://github.com/bitcoindevproject/warnet" +GitHub = "https://github.com/bitcoin-dev-project/warnet" Pypi = "https://pypi.org/project/warnet/" [project.optional-dependencies] @@ -56,3 +56,8 @@ include = ["warnet*", "test_framework*", "resources*"] [tool.setuptools.package-data] "resources" = ["**/*"] + +[tool.setuptools_scm] +write_to = "src/warnet/_version.py" +version_scheme = "no-guess-dev" +local_scheme = "node-and-date" diff --git a/src/warnet/control.py b/src/warnet/control.py index 0296b6abf..b907f7449 100644 --- a/src/warnet/control.py +++ b/src/warnet/control.py @@ -112,15 +112,33 @@ def stop_scenario(scenario_name): ) -def stop_all_scenarios(scenarios): - """Stop all active scenarios in parallel using multiprocessing""" +def _stop_single(scenario: str) -> str: + """ + Stop a single scenario + + Args: + scenario: Name of the scenario to stop + + Returns: + str: Message indicating the scenario has been stopped + """ + stop_scenario(scenario) + return f"Stopped scenario: {scenario}" + - def stop_single(scenario): - stop_scenario(scenario) - return f"Stopped scenario: {scenario}" +def stop_all_scenarios(scenarios) -> None: + """ + Stop all active scenarios in parallel using multiprocessing + + Args: + scenarios: List of scenario names to stop + + Returns: + None + """ with console.status("[bold yellow]Stopping all scenarios...[/bold yellow]"), Pool() as pool: - results = pool.map(stop_single, scenarios) + results = pool.map(_stop_single, scenarios) for result in results: console.print(f"[bold green]{result}[/bold green]") diff --git a/src/warnet/main.py b/src/warnet/main.py index 868147748..768a82f96 100644 --- a/src/warnet/main.py +++ b/src/warnet/main.py @@ -18,6 +18,49 @@ def cli(): pass +@click.command() +def version() -> None: + """Display the installed version of warnet""" + try: + from warnet._version import __version__ + + # For PyPI releases, this will be the exact tag (e.g. "1.1.11") + # For dev installs, it will be something like "1.1.11.post1.dev17+g27af3a7.d20250309" + # Which is .post.dev+g.d + # is the number of local commits since the checkout commit + # is the number of commits since the last tag + raw_version = __version__ + + # Format the version string to our desired format + if "+" in raw_version: + version_part, git_date_part = raw_version.split("+", 1) + + # Get just the git commit hash + commit_hash = ( + git_date_part[1:].split(".", 1)[0] + if git_date_part.startswith("g") + else git_date_part.split(".", 1)[0] + ) + + # Remove .dev component (from "no-guess-dev" scheme) + clean_version = version_part + if ".dev" in clean_version: + clean_version = clean_version.split(".dev")[0] + + # Apply dirty status (from "no-guess-dev" scheme) + if ".post" in clean_version: + base = clean_version.split(".post")[0] + version_str = f"{base}-{commit_hash}-dirty" + else: + version_str = f"{clean_version}-{commit_hash}" + else: + version_str = raw_version + + click.echo(f"warnet version {version_str}") + except ImportError: + click.echo("warnet version unknown") + + cli.add_command(admin) cli.add_command(auth) cli.add_command(bitcoin) @@ -37,7 +80,7 @@ def cli(): cli.add_command(status) cli.add_command(stop) cli.add_command(create) - +cli.add_command(version) if __name__ == "__main__": cli() diff --git a/src/warnet/project.py b/src/warnet/project.py index c4122d916..badc5aa83 100644 --- a/src/warnet/project.py +++ b/src/warnet/project.py @@ -431,6 +431,12 @@ def new_internal(directory: Path, from_init=False): if proj_answers["custom_network"]: click.secho("\nGenerating custom network...", fg="yellow", bold=True) custom_network_path = inquirer_create_network(directory) + else: + click.echo( + f"No custom network specified, see example network files in {project_path}/networks/" + ) + click.echo("Deploy any of these networks by running:") + click.echo(f" warnet deploy {project_path}/networks/") if custom_network_path: click.echo(