Skip to content

Instantly share code, notes, and snippets.

@marnix
Last active January 5, 2018 19:47
Show Gist options
  • Save marnix/2f4efc1154547103bcec3783e6015bfc to your computer and use it in GitHub Desktop.
Save marnix/2f4efc1154547103bcec3783e6015bfc to your computer and use it in GitHub Desktop.
#!/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