Skip to content

Conversation

@deadmanoz
Copy link
Contributor

@deadmanoz deadmanoz commented Feb 18, 2025

Adds version:

warnet version
warnet version 1.1.11

Stop all bug - multiprocessing doesn't like local functions

warnet stop

Screenshot 2025-02-18 at 11 33 05 AM

Fixed:

warnet stop
Screenshot 2025-02-18 at 11 32 26 AM

Output from "n" on warnet new:

warnet new tester
Screenshot 2025-02-18 at 11 37 19 AM

Copy link
Contributor

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concept ACK, see docs/developer-notes.md for instructions on passing lint test

docs/warnet.md Outdated
Comment on lines 14 to 15
Check the version of warnet using `warnet version`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2f365ee

The API docs are autogenerated by resources/scripts/apidocs.py which you can run locally to make sure the output looks correct. The CI will run this automatically on merged PRs so docs on main should always be up to date ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

I had messed up my trunk setup so I was getting no linting being done locally

@pinheadmz
Copy link
Contributor

Yeah, its annoying ...

--> ruff format .
2 files reformatted, 59 files left unchanged

--> git diff

diff --git a/src/warnet/main.py b/src/warnet/main.py
index 08d46809..b6250732 100644
--- a/src/warnet/main.py
+++ b/src/warnet/main.py
@@ -19,6 +19,7 @@ from .users import auth
 def cli():
     pass
 
+
 @click.command()
 def version() -> None:
     """Display the installed version of warnet"""
@@ -28,6 +29,7 @@ def version() -> None:
     except importlib.metadata.PackageNotFoundError:
         click.echo("warnet version unknown (package not installed)")
 
+
 cli.add_command(admin)
 cli.add_command(auth)
 cli.add_command(bitcoin)
diff --git a/src/warnet/project.py b/src/warnet/project.py
index cddbab6a..badc5aa8 100644
--- a/src/warnet/project.py
+++ b/src/warnet/project.py
@@ -432,7 +432,9 @@ def new_internal(directory: Path, from_init=False):
         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(
+            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/<example-network-name>")
 

@deadmanoz
Copy link
Contributor Author

deadmanoz commented Feb 19, 2025

Oh man, thanks for your patience.

2 learnings:

  • Use the indicated tools and versions, and familiarise properly with any contributors guide
  • Make sure you're running the tools from the right directory

Copy link
Contributor

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2aab33c

Happy to merge this as-is, but wondering if we can squeeze in one more detail about version ...

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK 2aab33c53d14bf005b7583ef21f75d0c2c47c123
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAme18ysACgkQ5+KYS2KJ
yTqbTw//fG4zKng7x0dMjnfqZibTRqy4q3VqC9uKmhJYRh1CmwqkvNfQwOiND2Wi
kl17B/y+3U4dwNzNaOFnYcHx7bPWmEKNVuy30Jo4Zk3Rzus495Zn5Uj+cmpwJvch
R3phZQ2uWQiOStYsKPGglJFKw9nUXV7rQcO28q6CKOr+3GU/Etcp8/GJnm9ZE/XK
VmpfIjFcozDBS4J0dQ8RyVfQko6anVoiJk6D7c+XoPCzh0rcLkYihtzTZzRoq0nV
xhC+G9D0t2Tnm20cjKWZ3Y7+snP9gkEEnKrL0F0WfsUece2SBc31lz4jJ4ms7wL3
JL+A13HXvLMhlbNRQ7ULDGhrwOoFqSxDKLXLNjrSe3SvwvHcXR3DkSNnDMavWlDy
4OUNHvadpdsMFRo/FCoVPrhUs6PyLHXPAh71OwxEqkcYkE5IkRC4O+HCYU9GS6Kz
8zFDrkfYFZREkXKBImebbAs3OCtCA3FbIokQx/lQyaomc3HluObdEYgYmTNJ5MGX
m+kCxQ7KrCU9a9o7Fg5PpMETnXV9DpNOY2eG94QNJwG+BDC9WdbCnU39UB0thNtv
6QQSL9NYzmr7NSFZUHr+0oc9i1aUciUrSDPe+F8Uu+q8tCbfCmD6LprydSthiH3w
8pYb0uY6ehPO/xq8LShIKuW9STMJzL2yeCQ10JCfoKZkVFVtX6k=
=0Ngg
-----END PGP SIGNATURE-----

pinheadmz's public key is on openpgp.org

"""Display the installed version of warnet"""
try:
version = importlib.metadata.version("warnet")
click.echo(f"warnet version {version}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to indicate if the code is modified from release, like
Bitcoin Core daemon version v28.99.0-78c19ddd7c56-dirty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll look into how this is done 💪

Copy link
Contributor Author

@deadmanoz deadmanoz Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok there are a few options here so I'll need your guidance.

Using setuptools_scm seems to be the way to go for a Python-based project like this.

We have 2 ways to install Warnet, from source and from pypi.

If the user is installing from source, then the basic (default) setuptools_scm configuration I've added will yield versions like follows:
warnet version 1.1.11.dev8+dirty. I've confirmed this locally. This is using the "guess-next-dev" version-scheme.

If the user is installing from pypi then the reported version should report the tagged version: warnet version 1.1.11. I haven't been able to confirm this but this is basically what setuptools_scm is intended to do.

Now the "dirty" version suffix of the current configuration doesn't have the git commit details like Bitcoin Core, e.g. --short=12 HEAD, instead it has dev<number-of-commits-from-tag>:
warnet version 1.1.11.dev8+dirty
rather than
warnet version 1.1.11.e24df9e566fd-dirty

To instead use the git short commit in some way we would have to use a custom local version which can absolutely be done, my concern is that it might make things a bit more fragile without providing much additional utility.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pinheadmz I fixed the Ruff issues 🫠

@deadmanoz
Copy link
Contributor Author

deadmanoz commented Feb 28, 2025

Ok @pinheadmz I have a potential solution that is now pushed to the branch/PR.

The situation is a bit more complex than originally anticipated as the following indicates, but we get the following outcome:

  • Warnet pulled from PyPI will report the current version, as it does now, but it no longer requires manually updating the pyproject.toml and instead uses the git tags via setuptools_scm from build time, e.g. 1.1.11. That is, references the _version.py that is created during build.
  • Warnet installed from source in editable mode will report a version that is based on the most recent git tag (as above), the most recent local git (short) commit, and whether there are uncommited local changes, e.g. 1.1.11.63fe5aa1-dirty. As in, won't reference the _version.py file, instead reports on the current repo/working directory state.

"one thing i notice about this is that since the _version file is written during setup, if youre editing the code and adding new commits it doesnt show up until you pip install -e . again"
"which IMO kinda defeats the purpose of this"

The complexity in implementation is related to the package build sequence, and what is possible with setuptools_scm & pyproject.toml: https://setuptools-scm.readthedocs.io/en/latest/customizing/

pyproject.toml is effectively a static configuration file that doesn't allow "arbitrary" code during installation which is great for security but not for customisation. You can only use the versioning format on offer (e.g. 1.1.11.dev6-dirty) and this won't change as local changes are made.

We need a setup.py where we implement the function for custom version - the above docs say "setuptools-scm has to piggyback on setuptools for passing functions over" when using custom functions.

So we have a hybrid approach:

  1. Use pyproject.toml for static configuration
  2. Use setup.py specifically for the custom version function

Copy link
Contributor

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sorry this had gotten bike shedded 😬

here's what im thinking:

  1. try to get git commit
  2. always get scm_version
  3. if we got a commit, append it to whatever we got from scm_version

so, installing from release:
warnet 1.0.11

installing from github but checking out the exact 1.0.11 tag:
warnet 1.0.11-296e0ba2

.gitignore Outdated
@@ -1,4 +1,5 @@
.vscode
.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, but FYI you can add this to your own ~/.gitignore and it'll apply to everything ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A global .gitignore, who woulda thought 😝

@deadmanoz deadmanoz force-pushed the add-version-fix-stop-all-bug branch 2 times, most recently from 1fb68aa to a5bf800 Compare March 6, 2025 08:35
@deadmanoz deadmanoz force-pushed the add-version-fix-stop-all-bug branch from a5bf800 to 27af3a7 Compare March 6, 2025 14:56
@deadmanoz
Copy link
Contributor Author

deadmanoz commented Mar 6, 2025

Hey @pinheadmz it now does the below. No longer a need for setup.py.

I've been testing with test PyPI as you recommended (e.g. pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ warnet-deadmanoz==100.0.0)

ok sorry this had gotten bike shedded 😬

here's what im thinking:

  1. try to get git commit
  2. always get scm_version
  3. if we got a commit, append it to whatever we got from scm_version

so, installing from release: warnet 1.0.11

installing from github but checking out the exact 1.0.11 tag: warnet 1.0.11-296e0ba2

@pinheadmz
Copy link
Contributor

Ok we're so close ;-)

Issue now is that the commit hash appended to the version string is from whatever repo you are currently working in.

For example cd to any git repo on your computer, create venv, install your test-pypi warnet and execute warnet version

(.venv) --> warnet version
warnet version 100.0.0-50426516
(.venv) --> git rev-parse HEAD
50426516511bfdac552d90026c80cde2ba359c43
(.venv) --> pwd
/Users/matthewzipkin/Desktop/work/battle-of-galen-erso

@pinheadmz
Copy link
Contributor

at this point I am ok with just dropping all the commit hash stuff and just merging this so we at least have something.

@deadmanoz
Copy link
Contributor Author

Ok we're so close ;-)

Issue now is that the commit hash appended to the version string is from whatever repo you are currently working in.

For example cd to any git repo on your computer, create venv, install your test-pypi warnet and execute warnet version

(.venv) --> warnet version
warnet version 100.0.0-50426516
(.venv) --> git rev-parse HEAD
50426516511bfdac552d90026c80cde2ba359c43
(.venv) --> pwd
/Users/matthewzipkin/Desktop/work/battle-of-galen-erso

Ahh frick, yeah we can't have that 😓

@deadmanoz
Copy link
Contributor Author

Ok take #12123721347

No subprocess & wrong git repo, no complexity with setuptools_scm setup.py.

Just use the metadata setuptools_scm provides, which includes node (the shortened commit id) and identification of "dirtyness", to generate version strings like:

  • 1.1.11-932aaa5-dirty for source/editable installs: This is most recent tag plus the short commit hash, with dirty appended if the local working copy has uncommitted changes.
  • 1.1.11 for PyPI releases. Just the semantic version from the git tag.

The main limitation is that it won't automatically update the commit hash when a user makes a local commit without reinstalling, because setuptools_scm only writes the version info to _version.py at install time.

P.S. We use local_scheme = "node-and-date" to get the node/shortened commit id information and version_scheme = "no-guess-dev" to ensure the patch component is not incremented (which is the default behaviour) and know when the working copy is dirty.

@pinheadmz
Copy link
Contributor

GREAT thank, sorry for all the hassle. <3

@pinheadmz pinheadmz merged commit 240dc21 into bitcoin-dev-project:main Mar 10, 2025
15 checks passed
@deadmanoz deadmanoz deleted the add-version-fix-stop-all-bug branch March 10, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants