Skip to content

Commit

Permalink
Merge pull request #208 from bancorprotocol/207-fix-current-version-r…
Browse files Browse the repository at this point in the history
…equirementstxt-file

added version checker and requirements change
  • Loading branch information
mikewcasale authored Nov 16, 2023
2 parents b354e4a + abf9d26 commit 5efbc21
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
43 changes: 43 additions & 0 deletions fastlane_bot/events/version_utils.py
Original file line number Diff line number Diff line change
@@ -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}.\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("5.32.0"):
raise VersionRequirementError(installed_version, required_version)
15 changes: 6 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
(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
import pandas as pd
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 (
Expand Down Expand Up @@ -47,7 +50,6 @@
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

Expand Down Expand Up @@ -216,12 +218,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",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ click~=8.1.3
setuptools~=67.6.1
protobuf==3.19.5
tqdm~=4.64.1

web3~=5.31.3
20 changes: 20 additions & 0 deletions resources/NBTest/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5efbc21

Please sign in to comment.