Last active
January 5, 2018 19:47
-
-
Save marnix/2f4efc1154547103bcec3783e6015bfc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python2 | |
## !!! WARNING: THIS CODE COULD VERY WELL REMOVE YOUR SYSTEM-WIDE | |
## plaitpy AND bda.basen PACKAGES !!! | |
# verify that we start with a clean slate: no plaitpy, no bda.basen | |
import os | |
assert not os.path.isfile('/usr/local/lib/python2.7/dist-packages/plaitpy/__init__.py') | |
try: | |
import plaitpy # this fails, as expected | |
assert False | |
except: pass | |
assert not os.path.isfile('/usr/local/lib/python2.7/dist-packages/bda/basen/__init__.py') | |
try: | |
import bda.basen # this fails, as expected | |
assert False | |
except: pass | |
try: | |
#======================================================================================= | |
import sys | |
import os | |
# The following code successfully installs bda.basen, then fails to import it. | |
# However, it works for plaitpy (a random recently updated package). | |
assert '/usr/local/lib/python2.7/dist-packages' in sys.path | |
import pip | |
pip.main(['install', 'plaitpy', 'bda.basen']) | |
assert '/usr/local/lib/python2.7/dist-packages' in sys.path | |
assert os.path.isfile('/usr/local/lib/python2.7/dist-packages/plaitpy/__init__.py') | |
import plaitpy # this succeeds, as expected | |
print plaitpy | |
assert os.path.isfile('/usr/local/lib/python2.7/dist-packages/bda/basen/__init__.py') | |
import bda.basen # THIS FAILS WITH 'ImportError: No module named bda.basen' | |
print bda.basen | |
#======================================================================================= | |
finally: | |
# go back to our clean slate | |
print '--------------' | |
print 'BEGIN CLEAN-UP' | |
try: | |
import pip | |
pip.main(['uninstall', '-y', 'bda.basen']) | |
pip.main(['uninstall', '-y', 'plaitpy']) | |
finally: | |
print 'END CLEAN-UP' | |
print '------------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment