Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix __version_as_int__ for >10 minor/patch release vers (resolves #1982) #1993

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@
# Bittensor code and protocol version.
__version__ = "7.0.0"

version_split = __version__.split(".")
__version_as_int__: int = (
(100 * int(version_split[0]))
+ (10 * int(version_split[1]))
+ (1 * int(version_split[2]))
_version_split = __version__.split(".")
__version_info__ = tuple(map(int, _version_split))
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use

__version_info__ = tuple(int(part) for part in _version_split)

instead of

__version_info__ = tuple(map(int, _version_split))

in this example it is the same in terms of optimization, but code readability is much better

Copy link
Contributor

@ibraheem-opentensor ibraheem-opentensor Jun 10, 2024

Choose a reason for hiding this comment

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

@RomanCh-OT I can make this change when this gets merged. Just waiting for confirmation from subtensor side

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied;

as for version being u32, AFAIK, that was needed to be checked was in
https://github.com/opentensor/subtensor/blob/0c77062a10cadfbab8507b7dccb2e1ea49848e58/pallets/subtensor/src/serving.rs#L57C9-L57C16
even with prometheus is u32 , but that version number is arbitrary set by node so it doesn't even matter in our context
https://github.com/opentensor/subtensor/blob/0c77062a10cadfbab8507b7dccb2e1ea49848e58/pallets/subtensor/src/serving.rs#L160

So it should be safe.

_version_int_base = 1000
assert max(__version_info__) < _version_int_base

__version_as_int__: int = sum(
e * (_version_int_base**i) for i, e in enumerate(reversed(__version_info__))
)
assert __version_as_int__ < 2**31 # fits in int32
__new_signature_version__ = 360

# Rich console.
Expand All @@ -58,6 +61,16 @@
install(show_locals=False)


def __getattr__(name):
if name == "version_split":
warnings.warn(
"version_split is deprecated and will be removed in future versions. Use __version__ instead.",
DeprecationWarning,
)
return _version_split
raise AttributeError(f"module {__name__} has no attribute {name}")


def turn_console_off():
global __use_console__
global __console__
Expand Down
Loading