Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit be3a7d6

Browse files
committed
use call binary helper
1 parent 476bb1c commit be3a7d6

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

subtensor-api/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.1
1+
0.2.2

subtensor-api/src/subtensorapi/__init__.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1616
# DEALINGS IN THE SOFTWARE.
1717

18-
__version__ = "0.2.1"
18+
__version__ = "0.2.2"
1919

2020
import enum
2121
import json
@@ -168,46 +168,57 @@ def get_path_to_fast_sync(cls) -> str:
168168
def sync_and_save(self, console: Console, block_hash: str, filename: Optional[str] = None) -> None:
169169
"""Runs the fast sync binary to sync all neurons at a given block hash"""
170170
FastSync.verify_fast_sync_support()
171-
path_to_bin = FastSync.get_path_to_fast_sync()
172171
console.print("Using subtensor-node-api for neuron retrieval...")
173-
args = [path_to_bin, "sync_and_save", "-u", self.endpoint_url, '-b', block_hash]
172+
args = ["sync_and_save", "-u", self.endpoint_url, '-b', block_hash]
174173
if filename is not None:
175174
args.extend(['-f', filename])
176175
# will write to ~/.bittensor/metagraph.json by default
176+
self.__call_binary(console, args)
177+
178+
def __call_binary(self, console: Console, args: List[str]) -> None:
179+
"""
180+
Calls the fast sync binary with the given args
181+
182+
Args:
183+
args: List of arguments to pass to the fast
184+
sync binary
185+
186+
Raises:
187+
FastSyncRuntimeException: If the fast sync binary fails
188+
"""
189+
FastSync.verify_fast_sync_support()
190+
path_to_bin = FastSync.get_path_to_fast_sync()
191+
args = [path_to_bin] + args
177192
try:
178-
subprocess.run(args, check=True, stdout=subprocess.PIPE)
179-
except subprocess.SubprocessError as e:
180-
raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e))
193+
subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
194+
except subprocess.CalledProcessError as e:
195+
stderr = e.stderr.decode(sys.getfilesystemencoding())
196+
raise FastSyncRuntimeException("Error running fast sync binary: {}\nSTDERR={}".format(e, stderr))
181197

182198
def sync_and_save_historical(self, console: Console, block_numbers: List[Union[int, str]] = ["latest"], uids: List[int] = [], filename: Optional[str] = None) -> None:
183199
"""Runs the fast sync binary to sync all uids at each block number"""
184200
FastSync.verify_fast_sync_support()
185-
path_to_bin = FastSync.get_path_to_fast_sync()
186201
console.print("Using subtensor-node-api for historical neuron retrieval...")
187202
args = (
188-
[path_to_bin, "sync_and_save_historical", "-u", self.endpoint_url] +
203+
["sync_and_save_historical", "-u", self.endpoint_url] +
189204
(['-b'] + [str(bn) for bn in block_numbers]) +
190-
(['-i'] + [str(uid) for uid in uids]) if len(uids) > 0 else [] + # uids are optional, default to all
205+
((['-i'] + [str(uid) for uid in uids]) if len(uids) > 0 else []) + # uids are optional, default to all
191206
(['-f', filename] if filename is not None else []) # will write to ~/.bittensor/metagraph_historical.json by default
192207
)
193-
try:
194-
subprocess.run(args, check=True, stdout=subprocess.PIPE)
195-
except subprocess.SubprocessError as e:
196-
raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e))
208+
209+
console.print("Running fast sync binary with args: {}".format(args))
210+
211+
self.__call_binary(console, args)
197212

198213
def get_blockAtRegistration_for_all_and_save(self, console: Console, block_hash: str, filename: Optional[str] = None) -> None:
199214
"""Runs the fast sync binary to get blockAtRegistration for all neurons at a given block hash"""
200215
FastSync.verify_fast_sync_support()
201-
path_to_bin = FastSync.get_path_to_fast_sync()
202216
console.print("Using subtensor-node-api for blockAtRegistration storage retrieval...")
203-
args = [path_to_bin, "block_at_reg_and_save", "-u", self.endpoint_url, '-b', block_hash]
217+
args = ["block_at_reg_and_save", "-u", self.endpoint_url, '-b', block_hash]
204218
if filename is not None:
205219
args.extend(['-f', filename])
206220
# will write to ~/.bittensor/blockAtRegistration_all.json by default
207-
try:
208-
subprocess.run(args, check=True, stdout=subprocess.PIPE)
209-
except subprocess.SubprocessError as e:
210-
raise FastSyncRuntimeException("Error running fast sync binary: {}".format(e))
221+
self.__call_binary(console, args)
211222

212223
@classmethod
213224
def load_blockAtRegistration_for_all(cls, json_file_location: Optional[str] = '~/.bittensor/blockAtRegistration_all.json') -> List[int]:
-704 Bytes
Binary file not shown.
997 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)