Skip to content

Commit

Permalink
Fixed GitPython import (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky authored Aug 9, 2021
1 parent 800aa41 commit caa6086
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions neptune/new/internal/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit caa6086

Please sign in to comment.