From caa60863b5f18ea8cafd3bfa8cb55541d4897e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Jankowski?= Date: Mon, 9 Aug 2021 10:52:52 +0200 Subject: [PATCH] Fixed GitPython import (#647) --- CHANGELOG.md | 3 +++ neptune/new/internal/utils/git.py | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce558d8b4..f4dd02d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### Features - Added long description for PyPI ([#642](https://github.com/neptune-ai/neptune-client/pull/642)) +### Fixes +- Fixed GitPython importing during package preparation ([#647](https://github.com/neptune-ai/neptune-client/pull/647)) + ## neptune-client 0.10.3 ### Features diff --git a/neptune/new/internal/utils/git.py b/neptune/new/internal/utils/git.py index 196da55b0..72bdaf539 100644 --- a/neptune/new/internal/utils/git.py +++ b/neptune/new/internal/utils/git.py @@ -15,20 +15,30 @@ # import os import logging +import warnings from typing import Optional -import git - from neptune.new.types.atoms import GitRef _logger = logging.getLogger(__name__) +def get_git_repo(repo_path): + # WARN: GitPython asserts the existence of `git` executable + # which consists in failure during the preparation of conda package + try: + # pylint:disable=import-outside-toplevel + import git + return git.Repo(repo_path, search_parent_directories=True) + except ImportError: + warnings.warn("GitPython could not be initialized") + + def get_git_info(repo_path=None): try: # pylint:disable=bad-option-value - repo = git.Repo(repo_path, search_parent_directories=True) + repo = get_git_repo(repo_path) commit = repo.head.commit @@ -58,7 +68,7 @@ def get_git_info(repo_path=None): def get_git_repo_path(initial_path: str) -> Optional[str]: try: - return git.Repo(initial_path, search_parent_directories=True).git_dir + return get_git_repo(initial_path).git_dir except: # pylint: disable=bare-except pass