Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 27b0554

Browse files
authored
Release/0.0.2 (#4)
* Fix packaging (#1) * use find packages * bump version * add test mocks to package * bump version * gsed -> sed * fix scripts * add mock utils * add changelog notes
1 parent 14c89ec commit 27b0554

File tree

14 files changed

+316
-12
lines changed

14 files changed

+316
-12
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.0.2 / 2023-07-05
4+
5+
## What's Changed
6+
* Add mock module to package by @camfairchild in 60eec82d
7+
* Fix packaging by @camfairchild in https://github.com/opentensor/bittensor-wallet/pull/1
8+
9+
10+
**Full Changelog**: https://github.com/opentensor/bittensor-wallet/compare/v0.0.0...v0.0.2
11+
12+
313
## 0.0.1 / 2023-06-27
414

515
## What's Changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# BittensorWallet - v0.0.1
1+
# BittensorWallet - v0.0.2
22

33
BittensorWallet is a library for managing wallet keypairs, keyfiles, etc. for the [Bittensor Python API](https://github.com/opentensor/bittensor).
44

@@ -7,7 +7,7 @@ The purpose of this repo is to separate the concern of keyfile management from t
77
# Installation
88
This package can be installed from [PyPi.org](https://pypi.org/project/bittensor-wallet/):
99
```bash
10-
pip install bittensor-wallet==0.0.1
10+
pip install bittensor-wallet==0.0.2
1111
```
1212
or via this repo (using [gh-cli](https://cli.github.com/)):
1313
```bash

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.1
1+
v0.0.2

bittensor_wallet/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1818
# DEALINGS IN THE SOFTWARE.
1919

20-
__version__ = "0.0.1"
20+
__version__ = "0.0.2"
2121
__ss58_format__ = 42 # Bittensor ss58 format
2222

2323
import argparse

bittensor_wallet/mock/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The MIT License (MIT)
2+
# Copyright © 2023 Opentensor Technologies
3+
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
6+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
10+
# the Software.
11+
12+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
13+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
16+
# DEALINGS IN THE SOFTWARE.
17+
18+
from .wallet_mock import MockWallet as MockWallet
19+
from .keyfile_mock import MockKeyfile as MockKeyfile
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# The MIT License (MIT)
2+
3+
# Copyright © 2021 Yuma Rao
4+
# Copyright © 2022 Opentensor Foundation
5+
# Copyright © 2023 Opentensor Technologies
6+
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
9+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
10+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
13+
# the Software.
14+
15+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
# DEALINGS IN THE SOFTWARE.
20+
21+
from bittensor_wallet import serialized_keypair_to_keyfile_data, Keyfile
22+
from bittensor_wallet import Keypair
23+
24+
class MockKeyfile( Keyfile ):
25+
""" Defines an interface to a mocked keyfile object (nothing is created on device) keypair is treated as non encrypted and the data is just the string version.
26+
"""
27+
def __init__( self, path: str ):
28+
super().__init__( path )
29+
30+
self._mock_keypair = Keypair.create_from_mnemonic( mnemonic = 'arrive produce someone view end scout bargain coil slight festival excess struggle' )
31+
self._mock_data = serialized_keypair_to_keyfile_data( self._mock_keypair )
32+
33+
def __str__(self):
34+
if not self.exists_on_device():
35+
return "Keyfile (empty, {})>".format( self.path )
36+
if self.is_encrypted():
37+
return "Keyfile (encrypted, {})>".format( self.path )
38+
else:
39+
return "Keyfile (decrypted, {})>".format( self.path )
40+
41+
def __repr__(self):
42+
return self.__str__()
43+
44+
@property
45+
def keypair( self ) -> 'Keypair':
46+
return self._mock_keypair
47+
48+
@property
49+
def data( self ) -> bytes:
50+
return bytes(self._mock_data)
51+
52+
@property
53+
def keyfile_data( self ) -> bytes:
54+
return bytes( self._mock_data)
55+
56+
def set_keypair ( self, keypair: 'Keypair', encrypt: bool = True, overwrite: bool = False, password:str = None):
57+
self._mock_keypair = keypair
58+
self._mock_data = serialized_keypair_to_keyfile_data( self._mock_keypair )
59+
60+
def get_keypair(self, password: str = None) -> 'Keypair':
61+
return self._mock_keypair
62+
63+
def make_dirs( self ):
64+
return
65+
66+
def exists_on_device( self ) -> bool:
67+
return True
68+
69+
def is_readable( self ) -> bool:
70+
return True
71+
72+
def is_writable( self ) -> bool:
73+
return True
74+
75+
def is_encrypted ( self ) -> bool:
76+
return False
77+
78+
def encrypt( self, password: str = None):
79+
raise ValueError('Cannot encrypt a mock keyfile')
80+
81+
def decrypt( self, password: str = None):
82+
return
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The MIT License (MIT)
2+
# Copyright © 2023 Opentensor Technologies
3+
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
6+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
10+
# the Software.
11+
12+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
13+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
14+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
16+
# DEALINGS IN THE SOFTWARE.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from typing import Optional
2+
3+
from Crypto.Hash import keccak
4+
5+
6+
from bittensor_wallet import __ss58_format__
7+
8+
from .. import MockWallet
9+
from ...keypair_impl import Keypair
10+
11+
12+
def get_mock_wallet(coldkey: "Keypair" = None, hotkey: "Keypair" = None):
13+
wallet = MockWallet(
14+
name = 'mock_wallet',
15+
hotkey = 'mock',
16+
path = '/tmp/mock_wallet',
17+
)
18+
19+
if not coldkey:
20+
coldkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
21+
if not hotkey:
22+
hotkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
23+
24+
wallet.set_coldkey(coldkey, encrypt=False, overwrite=True)
25+
wallet.set_coldkeypub(coldkey, encrypt=False, overwrite=True)
26+
wallet.set_hotkey(hotkey, encrypt=False, overwrite=True)
27+
28+
return wallet
29+
30+
def get_mock_keypair( uid: int, test_name: Optional[str] = None ) -> Keypair:
31+
"""
32+
Returns a mock keypair from a uid and optional test_name.
33+
If test_name is not provided, the uid is the only seed.
34+
If test_name is provided, the uid is hashed with the test_name to create a unique seed for the test.
35+
"""
36+
if test_name is not None:
37+
hashed_test_name: bytes = keccak.new(digest_bits=256, data=test_name.encode('utf-8')).digest()
38+
hashed_test_name_as_int: int = int.from_bytes(hashed_test_name, byteorder='big', signed=False)
39+
uid = uid + hashed_test_name_as_int
40+
41+
return Keypair.create_from_seed( seed_hex = int.to_bytes(uid, 32, 'big', signed=False), ss58_format = __ss58_format__)
42+
43+
def get_mock_hotkey( uid: int ) -> str:
44+
return get_mock_keypair(uid).ss58_address
45+
46+
def get_mock_coldkey( uid: int ) -> str:
47+
return get_mock_keypair(uid).ss58_address
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# The MIT License (MIT)
2+
3+
# Copyright © 2021 Yuma Rao
4+
# Copyright © 2022 Opentensor Foundation
5+
# Copyright © 2023 Opentensor Technologies
6+
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8+
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
9+
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
10+
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of
13+
# the Software.
14+
15+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16+
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
# DEALINGS IN THE SOFTWARE.
20+
21+
import os
22+
import bittensor
23+
import bittensor_wallet
24+
25+
from .keyfile_mock import MockKeyfile
26+
27+
class MockWallet(bittensor_wallet.Wallet):
28+
"""
29+
Mocked Version of the bittensor wallet class, meant to be used for testing
30+
"""
31+
def __init__(
32+
self,
33+
**kwargs,
34+
):
35+
r""" Init bittensor wallet object containing a hot and coldkey.
36+
Args:
37+
_mock (required=True, default=False):
38+
If true creates a mock wallet with random keys.
39+
"""
40+
super().__init__(**kwargs)
41+
# For mocking.
42+
self._is_mock = True
43+
self._mocked_coldkey_keyfile = None
44+
self._mocked_hotkey_keyfile = None
45+
46+
print("---- MOCKED WALLET INITIALIZED- ---")
47+
48+
@property
49+
def hotkey_file(self) -> 'bittensor_wallet.Keyfile':
50+
if self._is_mock:
51+
if self._mocked_hotkey_keyfile == None:
52+
self._mocked_hotkey_keyfile = MockKeyfile(path='MockedHotkey')
53+
return self._mocked_hotkey_keyfile
54+
else:
55+
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
56+
hotkey_path = os.path.join(wallet_path, "hotkeys", self.hotkey_str)
57+
return bittensor.keyfile( path = hotkey_path )
58+
59+
@property
60+
def coldkey_file(self) -> 'bittensor_wallet.Keyfile':
61+
if self._is_mock:
62+
if self._mocked_coldkey_keyfile == None:
63+
self._mocked_coldkey_keyfile = MockKeyfile(path='MockedColdkey')
64+
return self._mocked_coldkey_keyfile
65+
else:
66+
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
67+
coldkey_path = os.path.join(wallet_path, "coldkey")
68+
return bittensor.keyfile( path = coldkey_path )
69+
70+
@property
71+
def coldkeypub_file(self) -> 'bittensor_wallet.Keyfile':
72+
if self._is_mock:
73+
if self._mocked_coldkey_keyfile == None:
74+
self._mocked_coldkey_keyfile = MockKeyfile(path='MockedColdkeyPub')
75+
return self._mocked_coldkey_keyfile
76+
else:
77+
wallet_path = os.path.expanduser(os.path.join(self.path, self.name))
78+
coldkeypub_path = os.path.join(wallet_path, "coldkeypub.txt")
79+
return bittensor_wallet.Keyfile( path = coldkeypub_path )

scripts/release/add_notes_changelog.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ while [[ $# -gt 0 ]]; do
3333
shift # past argument
3434
shift # past value
3535
;;
36+
-B|--release-branch)
37+
RELEASE_BRANCH="$2"
38+
shift # past argument
39+
shift # past value
40+
;;
3641
-*|--*)
3742
echo "Unknown option $1"
3843
exit 1
@@ -59,6 +64,11 @@ if [[ -z $VERSION ]]; then
5964
exit 1
6065
fi
6166

67+
if [[ -z $RELEASE_BRANCH ]]; then
68+
echo_warning "Release branch not specified with (-B, --release-branch) assuming: release/$VERSION"
69+
RELEASE_BRANCH=release/$VERSION
70+
fi
71+
6272
DATE=$(date +"%Y-%m-%d")
6373
RELEASE_NAME="$VERSION / $DATE"
6474
TAG_NAME=v$VERSION
@@ -67,8 +77,8 @@ PREV_TAG_NAME=v$PREV_TAG_VERSION
6777
# 2.2. Generate release notes
6878
if [[ $APPLY == "true" ]]; then
6979
echo_info "Generating Github release notes"
70-
RESPONSE=$(generate_github_release_notes $GITHUB_TOKEN)
71-
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | gsed "s/\"//g")
80+
RESPONSE=$(generate_github_release_notes_for_changelog $GITHUB_TOKEN)
81+
DESCRIPTION=$(echo $RESPONSE | jq '.body' | tail -1 | sed "s/\"//g")
7282

7383
if [ $(echo $RESPONSE | jq '.body' | wc -l) -eq 1 ]; then
7484
if [ $(echo $RESPONSE | jq '.' | grep 'documentation_url' | wc -l) -gt 0 ]; then
@@ -89,8 +99,8 @@ fi
8999

90100
if [[ $APPLY == "true" ]]; then
91101
echo_info "Adding release notes to CHANGELOG.md"
92-
gsed -i "2 i\\\n## $RELEASE_NAME" CHANGELOG.md
93-
gsed -i "4 i\\\n$DESCRIPTION\n" CHANGELOG.md
102+
sed -i "2 i\\\n## $RELEASE_NAME" CHANGELOG.md
103+
sed -i "4 i\\\n$DESCRIPTION\n" CHANGELOG.md
94104
else
95105
echo_warning "Dry run execution. Not adding release notes to CHANGELOG.md"
96106
fi

0 commit comments

Comments
 (0)