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! 🥽