-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable automatically using import hook and env variable (#26)
- Loading branch information
1 parent
334401d
commit b3aff0c
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import _lovely_tensors_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
This file should never be imported or executed by the user. | ||
It gets called by the site hook `_lovely_tensors_hook.pth` which in turn gets | ||
called automatically by python upon startup (https://docs.python.org/3/library/site.html) | ||
if the package lovely-tensors is installed. | ||
If the LOVEY_TENSORS environment variable is set to a "truthy" value, import and monkey patch. | ||
""" | ||
import os | ||
import sys | ||
|
||
|
||
if os.environ.get("LOVELY_TENSORS", "").lower() in {"1", "true", "yes"}: | ||
try: | ||
import lovely_tensors | ||
lovely_tensors.monkey_patch() | ||
except Exception as e: | ||
ERROR_MESSAGE = """\ | ||
Error: lovely_tensors.monkey_patch() failed with: | ||
{} | ||
If you uninstalled lovely_tensors, you should delete any '_lovely_tensors_hook.pth' | ||
file on your system and unset your 'LOVELY_TENSORS' environment variable. | ||
""" | ||
print(ERROR_MESSAGE.format(e), file=sys.stderr) | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters