import inspect
import hashlib


def hash_strategy(strategy):
    """
    Hash the source code of a strategy
    """
    try:
        source_code = "".join(inspect.getsourcelines(strategy)[0])
    except OSError:  # Some classes are dynamically created
        source_code = "".join(inspect.getsourcelines(strategy.strategy)[0])
    hash_object = hashlib.md5(source_code.encode("utf-8"))
    hashed_source = hash_object.hexdigest()
    return hashed_source