This is a packaged-up and sanely version-controlled version of the Python tools I wrote for my REPLs, divided up into a bunch of subordinate packages:
-
compilation
: Abstractions for command-line macro definitions and JSON compilation databases. -
constants
: Definitions of useful constants, as well as polyfills to allow certain dependencies from the Python standard library to work even when some of their moving parts are missing (i.e. Python 2, various PyPy implementations, etc). -
fs
: Filesystem-related things. Submodules include:fs.filesystem
: classes representing filesystem primitives likeDirectory
,TemporaryDirectory
,TemporaryName
; a version oftempfile.NamedTemporaryFile
that works with or without the leading dot in the provided suffix (a peeve of mine); functions for common filesystem operations likewhich(…)
,back_ticks(…)
,rm_rf(…)
(be careful with that one), and so forth.fs.appdirectories
: pretty much a wholesale duplication of the popularappdirs
package.fs.misc
: a bunch of miscellany – noteworthy standouts include a memoizedcurrent_umask(…)
and a correspondingmasked_permissions(…)
fs.pypath
: functions for safe manipulation ofsys.path
–append_paths(…)
andremove_paths(…)
, respectively
-
repl
: Tools useful in Python REPL environments – currently ANSI printing functions, for the most part. -
typespace
: Contains a submoduletypespace.namespace
definingSimpleNamespace
(á la Python 3’stypes.SimpleNamespace
) and a slightly more usefulNamespace
ancestor class; these are used to furnish atypespace.types
namespace that contains everything in the standard-librarytypes
module, but with all the typenames shortened so they no longer gratuitously end in “Type”. Like e.g.types.ModuleType
is to be found intypespace.types.Module
,types.FunctionType
istypespace.types.Function
, et cetera, ad nauseum, so you can just dofrom clu.typespace import types
to lose the redundant “Type” naming suffix – which I don’t know about you but that annoys me, I mean we all know that these things are types because they are in the fuckingtypes
module and don’t need those overly verbose extra four characters there at the end. -
dicts
: Functions for wranglingdict
s (and actuallyMapping
andMutableMapping
descendants in general) – tools for merging and whatnot. -
exporting
: Classes and enums for automatically exporting module members, naming and assigning docstrings to things that aren’t classes, functions, or modules (like e.g.lambda
functions orNamespace
instances), categorizing such things (using a kind of enum we call aClade
that formulates classification predicates from typelists), and APIs for all of these things. Currently a WIP – check out the first (working!) implementation in my dotfiles repo. -
keyvalue
: A module that offers a super-simple key/value store for use in REPLs, based on thezict
package – so you can stash data in one REPL instance and get it back in another separate REPL process, even those of different implementations running on disparate Python versions. -
math
: the future home for math-related stuff. All there is right now is aclamp(…)
function that works withnumpy
dtypes. -
naming
: functions for determining the names of things (even module constants and other random things that generally lack things like__name__
attributes) and for the importing and exporting of things by “qualified names” – for instance, you can usenaming.qualified_import(…)
to import a classCurveSet
from its packageinstakit.processors.curves
by doingqualified_import('instakit.processors.curves.CurveSet')
, which that may be handier for you than composing and hard-coding animport
statement. -
predicates
: tons and tons and tons of usefullambda
functions, which I call “predicates” even though that may not be totally accurate in many cases. A lot of them take the formisXXX(thing)
e.g.isiterable(thing)
orisclass(thing)
, in each case returning a boolean value. There are also:- Convenience accessor functions:
attr(thing, 'attributeone', 'attributetwo')
will returnthing.attributeone
if it exists,thing.attributetwo
if the first one does not exist but the second one does, and finallyNone
if neither can be found.attr(…)
and other similar accessors work with any amount of attribute names (as long as there is at least one). Shortcuts likepyattr(…)
do the same thing, only they automatically expand their attributes to__dunder__
names. - AND MORE!!! There really are a ton of useful things in here and one day I will list them (but not today). Have fun with it!!
- Convenience accessor functions:
-
sanitizer
: functions for cleaning up unicode. Right now there is just a list-basedsanitize(…)
function that tones down anything with high-value code points to the point where it can be safelyascii
-ified. -
typology
: This is likepredicates
but with more predicates, most of which are based on typelists. The module is full of typelists and it uses them extensively in its predicates, viaisinstance(…)
,issubclass(…)
and a custom version of same calledgraceful_issubclass(…)
which tries very hard to work with what you give it (instead of just crapping out with aFalse
return value). -
version
: This is basically my take on thesemver
package. I originally developed it for internal use in some of my Python projects, but it stands on its own decently enough.
Yes. Like I said, there is more to come. Do enjoy!