Skip to content

Commit

Permalink
Create is_pip() function (ultralytics#3391)
Browse files Browse the repository at this point in the history
Returns `True` if file is part of pip package. Useful for contextual behavior modification.

```python
def is_pip():
    # Is file in a pip package?
    return 'site-packages' in Path(__file__).absolute().parts
```
  • Loading branch information
glenn-jocher committed May 30, 2021
1 parent 3ab4248 commit c06ddeb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@ def get_latest_run(search_dir='.'):


def is_docker():
# Is environment a Docker container
# Is environment a Docker container?
return Path('/workspace').exists() # or Path('/.dockerenv').exists()


def is_colab():
# Is environment a Google Colab instance
# Is environment a Google Colab instance?
try:
import google.colab
return True
except Exception as e:
return False


def is_pip():
# Is file in a pip package?
return 'site-packages' in Path(__file__).absolute().parts


def emojis(str=''):
# Return platform-dependent emoji-safe version of string
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
Expand Down

0 comments on commit c06ddeb

Please sign in to comment.