Created
November 7, 2017 06:38
-
-
Save csaez/7d14cde642eb11b3d3c8d367fc96b9f1 to your computer and use it in GitHub Desktop.
Command line to extract __all__ from python files
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/python | |
import imp | |
import sys | |
def main(filepath): | |
module = imp.load_source('foo', filepath) | |
entities = [repr(x) for x in dir(module) if not x.startswith('__')] | |
if entities: | |
text = ', '.join(entities) | |
return '__all__ = [{0}]'.format(text) | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
for f in sys.argv[1:]: | |
print main(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment