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
```
This commit is contained in:
1 parent
4b52e19a61
commit
d833ab3d25
1 file changed
+7
-2
+7
-2
@@ -53,12 +53,12 @@ def get_latest_run(search_dir='.'):
|
|||||||
|
|
||||||
|
|
||||||
def is_docker():
|
def is_docker():
|
||||||
# Is environment a Docker container
|
# Is environment a Docker container?
|
||||||
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
||||||
|
|
||||||
|
|
||||||
def is_colab():
|
def is_colab():
|
||||||
# Is environment a Google Colab instance
|
# Is environment a Google Colab instance?
|
||||||
try:
|
try:
|
||||||
import google.colab
|
import google.colab
|
||||||
return True
|
return True
|
||||||
@@ -66,6 +66,11 @@ def is_colab():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_pip():
|
||||||
|
# Is file in a pip package?
|
||||||
|
return 'site-packages' in Path(__file__).absolute().parts
|
||||||
|
|
||||||
|
|
||||||
def emojis(str=''):
|
def emojis(str=''):
|
||||||
# Return platform-dependent emoji-safe version of string
|
# Return platform-dependent emoji-safe version of string
|
||||||
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
|
return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
|
||||||
|
|||||||
Reference in new issue
Block a user