Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] develop from freqtrade:develop #1223

Merged
merged 6 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion freqtrade/commands/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _build_subcommands(self) -> None:
self.parser = ArgumentParser(
prog="freqtrade", description="Free, open source crypto trading bot"
)
self._build_args(optionlist=["version"], parser=self.parser)
self._build_args(optionlist=["version_main"], parser=self.parser)

from freqtrade.commands import (
start_analysis_entries_exits,
Expand Down
13 changes: 10 additions & 3 deletions freqtrade/commands/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from argparse import SUPPRESS, ArgumentTypeError

from freqtrade import __version__, constants
from freqtrade import constants
from freqtrade.constants import HYPEROPT_LOSS_BUILTIN
from freqtrade.enums import CandleType

Expand Down Expand Up @@ -59,8 +59,15 @@ def __init__(self, *args, **kwargs):
"version": Arg(
"-V",
"--version",
action="version",
version=f"%(prog)s {__version__}",
help="show program's version number and exit",
action="store_true",
),
"version_main": Arg(
# Copy of version - used to have -V available with and without subcommand.
"-V",
"--version",
help="show program's version number and exit",
action="store_true",
),
"config": Arg(
"-c",
Expand Down
7 changes: 5 additions & 2 deletions freqtrade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from freqtrade.constants import DOCS_LINK
from freqtrade.exceptions import ConfigurationError, FreqtradeException, OperationalException
from freqtrade.loggers import setup_logging_pre
from freqtrade.system import asyncio_setup, gc_set_threshold
from freqtrade.system import asyncio_setup, gc_set_threshold, print_version_info


logger = logging.getLogger("freqtrade")
Expand All @@ -38,7 +38,10 @@ def main(sysargv: list[str] | None = None) -> None:
args = arguments.get_parsed_arg()

# Call subcommand.
if "func" in args:
if args.get("version") or args.get("version_main"):
print_version_info()
return_code = 0
elif "func" in args:
logger.info(f"freqtrade {__version__}")
gc_set_threshold()
return_code = args["func"](args)
Expand Down
3 changes: 2 additions & 1 deletion freqtrade/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from freqtrade.system.asyncio_config import asyncio_setup
from freqtrade.system.gc_setup import gc_set_threshold
from freqtrade.system.version_info import print_version_info


__all__ = ["asyncio_setup", "gc_set_threshold"]
__all__ = ["asyncio_setup", "gc_set_threshold", "print_version_info"]
15 changes: 15 additions & 0 deletions freqtrade/system/version_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from freqtrade import __version__


def print_version_info():
"""Print version information for freqtrade and its key dependencies."""
import platform
import sys

import ccxt

print(f"Operating System:\t{platform.platform()}")
print(f"Python Version:\t\tPython {sys.version.split(' ')[0]}")
print(f"CCXT Version:\t\t{ccxt.__version__}")
print()
print(f"Freqtrade Version:\tfreqtrade {__version__}")
4 changes: 2 additions & 2 deletions tests/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def test_common_scripts_options() -> None:


def test_parse_args_version() -> None:
with pytest.raises(SystemExit, match=r"0"):
Arguments(["--version"]).get_parsed_arg()
args = Arguments(["--version"]).get_parsed_arg()
assert args["version_main"] is True


def test_parse_args_invalid() -> None:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pragma pylint: disable=missing-docstring

import re
from copy import deepcopy
from pathlib import Path
from unittest.mock import MagicMock, PropertyMock
Expand All @@ -26,6 +27,14 @@ def test_parse_args_None(caplog) -> None:
assert log_has_re(r"Usage of Freqtrade requires a subcommand.*", caplog)


def test_parse_args_version(capsys) -> None:
with pytest.raises(SystemExit):
main(["-V"])
captured = capsys.readouterr()
assert re.search(r"CCXT Version:\s.*", captured.out, re.MULTILINE)
assert re.search(r"Freqtrade Version:\s+freqtrade\s.*", captured.out, re.MULTILINE)


def test_parse_args_backtesting(mocker) -> None:
"""
Test that main() can start backtesting and also ensure we can pass some specific arguments
Expand Down
Loading