瀏覽代碼

Create `is_pip()` function (#3391)

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
```
modifyDataloader
Glenn Jocher GitHub 3 年之前
父節點
當前提交
d833ab3d25
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. +7
    -2
      utils/general.py

+ 7
- 2
utils/general.py 查看文件

@@ -53,12 +53,12 @@ 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
@@ -66,6 +66,11 @@ def is_colab():
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

Loading…
取消
儲存