glenn-jocher commited on
Commit
d833ab3
·
unverified ·
1 Parent(s): 4b52e19

Create `is_pip()` function (#3391)

Browse files

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
```

Files changed (1) hide show
  1. utils/general.py +7 -2
utils/general.py CHANGED
@@ -53,12 +53,12 @@ def get_latest_run(search_dir='.'):
53
 
54
 
55
  def is_docker():
56
- # Is environment a Docker container
57
  return Path('/workspace').exists() # or Path('/.dockerenv').exists()
58
 
59
 
60
  def is_colab():
61
- # Is environment a Google Colab instance
62
  try:
63
  import google.colab
64
  return True
@@ -66,6 +66,11 @@ def is_colab():
66
  return False
67
 
68
 
 
 
 
 
 
69
  def emojis(str=''):
70
  # Return platform-dependent emoji-safe version of string
71
  return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str
 
53
 
54
 
55
  def is_docker():
56
+ # Is environment a Docker container?
57
  return Path('/workspace').exists() # or Path('/.dockerenv').exists()
58
 
59
 
60
  def is_colab():
61
+ # Is environment a Google Colab instance?
62
  try:
63
  import google.colab
64
  return True
 
66
  return False
67
 
68
 
69
+ def is_pip():
70
+ # Is file in a pip package?
71
+ return 'site-packages' in Path(__file__).absolute().parts
72
+
73
+
74
  def emojis(str=''):
75
  # Return platform-dependent emoji-safe version of string
76
  return str.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else str