From e58624894db38cbd41c53550a20faac87143f970 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:30:06 -0800 Subject: [PATCH 1/6] added version checker and requirements change --- fastlane_bot/events/version_utils.py | 43 ++++++++++++++++++++++++++++ main.py | 12 ++++---- requirements.txt | 2 +- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 fastlane_bot/events/version_utils.py diff --git a/fastlane_bot/events/version_utils.py b/fastlane_bot/events/version_utils.py new file mode 100644 index 000000000..89ce15f58 --- /dev/null +++ b/fastlane_bot/events/version_utils.py @@ -0,0 +1,43 @@ +from packaging import version as pkg_version +from importlib.metadata import version + + +class VersionRequirementError(Exception): + """ + A custom exception class for version requirement errors. + + Args: + installed_version (str): The installed version of web3.py. + required_version (str): The required version of web3.py. + + Raises: + None + """ + + def __init__(self, installed_version, required_version): + super().__init__( + f"" + f"\n\n************** Version Requirement Error **************\n\n" + f"Your current web3.py version is {installed_version}, which does not meet the requirement of >= {required_version}.\n" + f"Please upgrade your web3.py version to {required_version} or higher.\n" + f"We recommend using the latest requirements.txt file to install the latest versions of all " + f"dependencies.\n\n" + f"Run `pip install -r requirements.txt` from the project directory of the fastlane-bot repo.\n" + f"\n\n************** Version Requirement Error **************\n\n" + f"" + ) + + +def check_version_requirements(): + with open("requirements.txt", "r") as f: + requirements = f.read().splitlines() + + web3_version = [r for r in requirements if "web3" in r][0] + required_version = web3_version.split("~=")[1] + + # Get the installed version of web3 + installed_version = version("web3") + + # Check the version and raise an exception if the requirement is not met + if not pkg_version.parse(installed_version) >= pkg_version.parse(required_version): + raise VersionRequirementError(installed_version, required_version) diff --git a/main.py b/main.py index 6b3a1d9b9..087a07163 100644 --- a/main.py +++ b/main.py @@ -54,6 +54,11 @@ load_dotenv() +from fastlane_bot.events.version_utils import check_version_requirements + +check_version_requirements() + + @click.command() @click.option( "--cache_latest_only", @@ -216,12 +221,7 @@ "--blockchain", default="ethereum", help="Select a blockchain from the list. Blockchains not in this list do not have a deployed Fast Lane contract and are not supported.", - type=click.Choice( - [ - "ethereum", - "coinbase_base" - ] - ), + type=click.Choice(["ethereum", "coinbase_base"]), ) @click.option( "--pool_data_update_frequency", diff --git a/requirements.txt b/requirements.txt index 092ebda41..f044f26b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ click~=8.1.3 setuptools~=67.6.1 protobuf==3.19.5 tqdm~=4.64.1 - +web3~=5.31.3 From df2a149c8c9a9516b283201c9fb7c7da8621ff09 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:41:45 -0800 Subject: [PATCH 2/6] bugfix --- fastlane_bot/events/version_utils.py | 6 +++--- main.py | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fastlane_bot/events/version_utils.py b/fastlane_bot/events/version_utils.py index 89ce15f58..aa857af6d 100644 --- a/fastlane_bot/events/version_utils.py +++ b/fastlane_bot/events/version_utils.py @@ -18,8 +18,8 @@ def __init__(self, installed_version, required_version): super().__init__( f"" f"\n\n************** Version Requirement Error **************\n\n" - f"Your current web3.py version is {installed_version}, which does not meet the requirement of >= {required_version}.\n" - f"Please upgrade your web3.py version to {required_version} or higher.\n" + f"Your current web3.py version is {installed_version}, which does not meet the requirement of ~= {required_version}.\n" + f"Please upgrade your web3.py version to {required_version}.\n" f"We recommend using the latest requirements.txt file to install the latest versions of all " f"dependencies.\n\n" f"Run `pip install -r requirements.txt` from the project directory of the fastlane-bot repo.\n" @@ -39,5 +39,5 @@ def check_version_requirements(): installed_version = version("web3") # Check the version and raise an exception if the requirement is not met - if not pkg_version.parse(installed_version) >= pkg_version.parse(required_version): + if not pkg_version.parse(installed_version) < pkg_version.parse(required_version): raise VersionRequirementError(installed_version, required_version) diff --git a/main.py b/main.py index 087a07163..51f8ae5f7 100644 --- a/main.py +++ b/main.py @@ -5,9 +5,13 @@ (c) Copyright Bprotocol foundation 2023. Licensed under MIT """ + +from fastlane_bot.events.version_utils import check_version_requirements + +check_version_requirements() + import os import time -from glob import glob from typing import List import click @@ -15,7 +19,6 @@ from dotenv import load_dotenv from web3 import Web3, HTTPProvider -from fastlane_bot.events.interface import QueryInterface from fastlane_bot.events.managers.manager import Manager from fastlane_bot.events.multicall_utils import multicall_every_iteration from fastlane_bot.events.utils import ( @@ -47,18 +50,12 @@ read_csv_file, handle_tokens_csv, ) -from fastlane_bot.tools.cpc import T from fastlane_bot.utils import find_latest_timestamped_folder from run_blockchain_terraformer import terraform_blockchain load_dotenv() -from fastlane_bot.events.version_utils import check_version_requirements - -check_version_requirements() - - @click.command() @click.option( "--cache_latest_only", From f40bd8278321feba0d2a9aa996a7b0cbdfa97351 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:16:05 -0800 Subject: [PATCH 3/6] Update main.py --- main.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/main.py b/main.py index 6b3a1d9b9..e6029c634 100644 --- a/main.py +++ b/main.py @@ -216,12 +216,7 @@ "--blockchain", default="ethereum", help="Select a blockchain from the list. Blockchains not in this list do not have a deployed Fast Lane contract and are not supported.", - type=click.Choice( - [ - "ethereum", - "coinbase_base" - ] - ), + type=click.Choice(["ethereum", "coinbase_base"]), ) @click.option( "--pool_data_update_frequency", From df57d099253bcfbffad7665b57367eb081924cdd Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:48:24 -0800 Subject: [PATCH 4/6] Create requirements.txt --- resources/NBTest/requirements.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 resources/NBTest/requirements.txt diff --git a/resources/NBTest/requirements.txt b/resources/NBTest/requirements.txt new file mode 100644 index 000000000..f044f26b5 --- /dev/null +++ b/resources/NBTest/requirements.txt @@ -0,0 +1,20 @@ +psutil==5.9.2 +packaging==21.3 +requests==2.28.1 +python-dateutil==2.8.1 +typing-extensions~=4.4.0 +python-dotenv~=0.16.0 +joblib~=1.2.0 +pandas~=1.5.2 +alchemy-sdk~=0.1.1 +pyarrow~=11.0.0 +networkx~=3.0 +cvxpy~=1.3.1 +matplotlib~=3.7.1 +dataclass_wizard~=0.22.2 +hexbytes~=0.2.3 +click~=8.1.3 +setuptools~=67.6.1 +protobuf==3.19.5 +tqdm~=4.64.1 +web3~=5.31.3 From 44cf184652746952d318ad35ff9d01586c223610 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:38:56 -0800 Subject: [PATCH 5/6] Update version_utils.py --- fastlane_bot/events/version_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane_bot/events/version_utils.py b/fastlane_bot/events/version_utils.py index aa857af6d..46709f571 100644 --- a/fastlane_bot/events/version_utils.py +++ b/fastlane_bot/events/version_utils.py @@ -39,5 +39,5 @@ def check_version_requirements(): installed_version = version("web3") # Check the version and raise an exception if the requirement is not met - if not pkg_version.parse(installed_version) < pkg_version.parse(required_version): + if not pkg_version.parse(installed_version) <= pkg_version.parse(required_version): raise VersionRequirementError(installed_version, required_version) From 8924b7ce11de32c2b9eac74025de8f0413b53807 Mon Sep 17 00:00:00 2001 From: Mike Casale <46603283+mikewcasale@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:15:54 -0800 Subject: [PATCH 6/6] Update version_utils.py --- fastlane_bot/events/version_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane_bot/events/version_utils.py b/fastlane_bot/events/version_utils.py index 46709f571..13cebef17 100644 --- a/fastlane_bot/events/version_utils.py +++ b/fastlane_bot/events/version_utils.py @@ -39,5 +39,5 @@ def check_version_requirements(): installed_version = version("web3") # Check the version and raise an exception if the requirement is not met - if not pkg_version.parse(installed_version) <= pkg_version.parse(required_version): + if not pkg_version.parse(installed_version) <= pkg_version.parse("5.32.0"): raise VersionRequirementError(installed_version, required_version)