From 08748dd0214b0368f73aa8e82931d9487cca54dd Mon Sep 17 00:00:00 2001 From: Joe Schr <8218910+TheJoeSchr@users.noreply.github.com> Date: Wed, 11 Jan 2023 21:07:03 +0100 Subject: [PATCH 1/2] fix "--version": needs to change working directory before calling `git`. otherwise it would display git commit id from the directory where you are calling `freqtrade` from instead of freqtrade's current commit id --- freqtrade/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index 5430cd2d0..09bfaab20 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -3,11 +3,13 @@ __version__ = '2023.1.dev' if 'dev' in __version__: try: + import os import subprocess + freqtrade_basedir = os.path.dirname(os.path.abspath(__file__)) __version__ = __version__ + '-' + subprocess.check_output( ['git', 'log', '--format="%h"', '-n 1'], - stderr=subprocess.DEVNULL).decode("utf-8").rstrip().strip('"') + stderr=subprocess.DEVNULL, cwd=freqtrade_basedir).decode("utf-8").rstrip().strip('"') except Exception: # pragma: no cover # git not available, ignore From 1cf69f139c23ef37cb3258bc2c8ab6fd844b6cae Mon Sep 17 00:00:00 2001 From: Joe Schr <8218910+TheJoeSchr@users.noreply.github.com> Date: Thu, 12 Jan 2023 19:27:41 +0100 Subject: [PATCH 2/2] refactor "--version" to use "pathlib" instead of "os" --- freqtrade/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/freqtrade/__init__.py b/freqtrade/__init__.py index 09bfaab20..18b6c9130 100644 --- a/freqtrade/__init__.py +++ b/freqtrade/__init__.py @@ -2,10 +2,10 @@ __version__ = '2023.1.dev' if 'dev' in __version__: + from pathlib import Path try: - import os import subprocess - freqtrade_basedir = os.path.dirname(os.path.abspath(__file__)) + freqtrade_basedir = Path(__file__).parent __version__ = __version__ + '-' + subprocess.check_output( ['git', 'log', '--format="%h"', '-n 1'], @@ -15,7 +15,6 @@ if 'dev' in __version__: # git not available, ignore try: # Try Fallback to freqtrade_commit file (created by CI while building docker image) - from pathlib import Path versionfile = Path('./freqtrade_commit') if versionfile.is_file(): __version__ = f"docker-{__version__}-{versionfile.read_text()[:8]}"