Miscellaneous Software

Non-scientific software I’ve published.

Python

module-hygiene

This is a super opinionated project! The gist is this β€” what if we cleaned up every unneccessary name from a Python module once it’s fully loaded? By using the pattern below, all of your namespaces will be kept clean and tidy.

"""
Pretend this is the contents of module.py!
"""

__export__ = {
    "MyType",
    "myfunc",
}


class MyType:
    ...

def myfunc(x): 
    ...


if __name__ == "__main__":
    ...

else:
    for _ in (*locals(), "_"):
        if not _.startswith("__") and _ not in __export__:
            del locals()[_]

I put the above pattern in a package called module-hygiene! With this new package, you could rewrite module.py as follows.

"""
Pretend this is the contents of module.py!
"""

__export__ = {
    "MyType",
    "myfunc",
}


class MyType:
    ...

def myfunc(x): 
    ...


if __name__ == "__main__":
    ...

else:
    from hygiene import cleanup
    exec(cleanup())

rich-admonitions

The rich Python package is excellent! I’ve added Julia-style in-terminal Markdown admonitions via the rich-admonitions package! Check out some simple usage below.

from rich import print
from admonitions import Admonition

message = Admonition.note(
    Admonition.info(
        Admonition.warning(
            Admonition.danger(
                Admonition(
                    "We're in too deep! πŸ₯½", 
                    header = "Oh jeez...", 
                    style = "purple"
                )
            )
        )
    )
)

print(message)
β”‚ Note  
β”‚
β”‚  β”‚ Info                                                                                                        
β”‚  β”‚                                                                                                             
β”‚  β”‚  β”‚ Warning                                                                                                  
β”‚  β”‚  β”‚                                                                                                          
β”‚  β”‚  β”‚  β”‚ Danger                                                                                                
β”‚  β”‚  β”‚  β”‚                                                                                                       
β”‚  β”‚  β”‚  β”‚  β”‚ Oh jeez...                                                                                         
β”‚  β”‚  β”‚  β”‚  β”‚                                                                                                    
β”‚  β”‚  β”‚  β”‚  β”‚  We're in too deep! πŸ₯½                                                                             
β”‚  β”‚  β”‚  β”‚                                                                                                       
β”‚  β”‚  β”‚                                                                                                          
β”‚  β”‚                                                                                                             
β”‚