[Python-CLU][clu] – Common Lightweight Utilities
========================================================
[](https://codecov.io/gh/fish2000/CLU/)
Install it right now! [Download][download-link] or type: `$ pip install -U python-clu`
------------------------------------------------------------------------------
The deal with CLU is, it is a bunch of stuff. Like, a junk drawer… but a junk drawer
full of building sets: [Legos][lego-link], [Robotix][robotix-link], [Capsela][capsela-link]
– and also magic interfaces that let somehow you plug Legos into Capselas and all
that. It’s a la carte: you can use one part of CLU (say the [inline testing stuff][clu.testing.utils])
and ignore the rest. Or just the [`exporter`][clu.exporting], or just the [`predicates`][clu.predicates]
collection. Naturally, these things taste great and also taste great together, too.
[](https://www.reddit.com/r/Xennials/comments/1aixaq7/construx_and_capsela_anyone_else_have_any/)
CLU started out as a packaged-up and sanely written version of
[the Python tools I wrote for my REPLs][homage-replutilities-link], divided up into
a bunch of subordinate packages. It’s grown magnificently since then (if I do say so myself).
And if you are wondering if “CLU” is a Tron reference, [you are correct][clu-tron-link].
“CLU” stands for “Common Lightweight Utilities” – it started out as an acronym for
“Command-Line Utilities” but it has grown useful beyond that scope, indeed.
The subordinate packages are pretty well-divided: [`clu.config`][clu.config] contains
things to help with configuration, like [config-file loading and saving][clu.config.filebase],
and data structures like [our famous namespaced keymaps][clu.config.keymap].
[`clu.exporting`][clu.exporting] has the `@export` decorator, a utility to easily label module
members for export by adding them to a modules’ `__all__` and `__dir__` members,
plus other stuff like real-name determination. Which, speaking of which, [`clu.naming`][clu.naming]
has additional easy functions for dealing with the names of your things and other peoples’,
and [`clu.repr`][clu.repr] has stuff for easily printing, getting, and specifying an objects’
string representation.
You’ll like [`clu.abstract`][clu.abstract] if you like building class towers – we have ABCs
for all types of things. If you like [`dict`s][dicts], check out the aforementioned [`clu.config.keymap`][clu.config.keymap]
and [`clu.dicts`][clu.dicts] modules – you’ll find things to build dictionary types, represent
them, and deal with them later. [`clu.dispatch`][clu.dispatch] will help you manage
subprocesses easily, [`clu.version`][clu.version] is better then [`semver`][semver-link]
(I promise), [`clu.testing`][clu.testing] is great for inlining some quick unit tests, and
[`clu.scripts`][clu.scripts] and [`clu.repl`][clu.repl] are what you want for whatever your
REPL environment may be… [`bpython`][bpython-link], [`ipython`][ipython-link],
[`ptpython`][ptpython-link], and many others I am sure!
So do have a look around. Here’s an abridged breakdown of some things within:
* [`config`][clu.config]: Tons of useful things for dealing with your app’s configuration. These are centered
around lexically namespaced dictionaries called “KeyMaps”, which basic examples of which can be
found in [`clu.config.keymap`][clu.config.keymap]. If your nested data looks like:
```python
data = {
'yo' : {
'dogg' : {
'i-heard' : {
'you-like' : "nested data"
}
}
}
}
```
… and you assign it to a keymap, like e.g. `keyed = keymap.Nested(data).flatten()`, then you can
use `keyed` like so:
```python
assert keyed["yo:dogg:i-heard:you-like"] == "nested data"
```
… The `Flat` and `Nested` classes are cheap to construct and lightweight, and generally act like most
[`dict`][dicts] instances in most of the expected ways. There is also an environment-variable [`keymap`][clu.config.keymap]
adapter in [`clu.config.env`][clu.config.env], which if your app uses environment variables that look like like
`MYAPP_CONFIG_THINGY`, they can be accessed through `env.FrozenEnviron(appname='myapp')` or
`env.Environ(appname='myapp')` like so:
```python
appenv = Environ(appname='myapp')
assert appenv['config:thingy'] == "some value"
appenv['config:doohickey'] = "a different value" # sets MYAPP_CONFIG_DOOHICKEY
# in the current env
```
… and there are plenty of tools for rolling your own `KeyMap`s in [`clu.config`][clu.config]: the
[`proxy`][clu.config.proxy] subpackage has a `KeyMap` proxy class, [`ns`][clu.config.ns] has utility functions
for manipulating namespace strings, [`keymapview`][clu.config.keymapview] has a class tower for
[`KeyMap`][clu.config.keymap] key/value/item views, and [`abc`][clu.config.abc] has, as you’d expect, all
the abstract base classes upon which our [`KeyMap`s][clu.config.keymap] are built, for your perusal and
eventual enjoyment.
* [`constants`][clu.constants]: Definitions of [useful constants][clu.constants.consts], as well as
[polyfills][clu.constants.polyfills] to allow certain dependencies from the Python standard library to work even
when some of their moving parts are missing (i.e. Ye Olde Pythone 2.7, various PyPy implementations, etc).
* [`all`][clu.all]: Herein you will find some verrrrry interesting “meta” functions for CLU. You have the `import_all_modules(…)`
function, which when provided your projects’ base path and appname, will return all the package names therein,
whether class-based modules defined through [`clu.exporting`][clu.exporting] or plain ol’ modules defined by files
ending in “.py”, basically. It’s awesome.
The companion function `import_clu_modules(¬)` is a shortcut just for everything within CLU, and `inline_tests(…)`
yields an iterator over every CLU module that defines inline tests through [`clu.testing`][clu.testing]. These
are very useful within CLU; for your own project, write your own functions modeled after these! You can’t go wrong.
* [`fs`][clu.fs]: Filesystem-related things. Submodules include:
* [`fs.filesystem`][clu.fs.filesystem]: classes representing filesystem primitives like `Directory`,
`TemporaryDirectory`, `TemporaryName`; a version of [`tempfile.NamedTemporaryFile`][tempfile.NamedTemporaryFile]
that works with or without the leading dot in the provided suffix (a peeve of mine); functions
for common filesystem operations like `which(…)`, `back_ticks(…)`, `rm_rf(…)` (be careful
with that one), and so forth.
* The `Directory` class is particularly extensive, with methods for [Zipfile][zipfile] archiving, searching
for importable Python files and others, file-suffix histograms, context-managed working-directory
management, walking and reverse-walking, and much more.
* [`fs.appdirectories`][clu.fs.appdirectories]: Started out as a pretty much wholesale duplication of the popular
[`appdirs`][appdirs-link] package[<sup>†</sup>](#dagger) – but it’s been kitted out with many CLUish things, e.g.
[`clu.fs.filesystem.Directory`][clu.fs.filesystem] instances. A solid upgrade in my opinion!
* [`fs.misc`][clu.fs.misc]: a bunch of useful miscellany – noteworthy standouts include regex utility functions for
constructing filename regex match or exclusion tests.
* [`fs.pypath`][clu.fs.pypath]: functions for safe manipulation of [`sys.path`][sys.path] – `enhance(…)`,
`remove_paths(…)`, `remove_invalid_paths()`, &c.
* [`importing`][clu.importing]: a whole class-based-module system! Basically you can do this:
```python
class Derived(clu.importing.base.Module):
""" I heard you like docstrings """
yo = 'dogg'
@export
def yodogg(self):
return "I heard you like"
@export
def nodogg(self):
return None
export(yo, name='yo')
from clu.app import Derived as derived # TAKE NOTE!!!
assert isinstance(derived, Module)
assert derived.yo == 'dogg'
assert derived.yodogg() == "I heard you like"
assert derived.nodogg() is None
```
… see that? just by subclassing [`clu.importing.base.Module`][clu.importing.base] you can create something
instantly importable. Awesome, wouldn’t you say? I would say. We’re working out the best way to create the
base `Module` for your own project (the machinery is there but the semantics are not yet perfect) but do feel
free to play around with the stuff in [`clu.importing.base`][clu.importing.base], and have a look at the
implementation in [`clu.importing.proxy`][clu.importing.proxy] of the “parameterized” `ProxyModule` (there’s a
`ChainModuleMap` container available in the [`proxy`][clu.importing.proxy] submodule, too).
* [`repl`][clu.repl] and [`scripts`][clu.scripts]: Tools useful in Python REPL environments. In [`clu.repl`][clu.repl],
there’s a while module full of ANSI printing and formatting utilities, many of them as classes, a [`columnize`][clu.repl.columnize]
function for, uh, printing things in columns[<sup>†</sup>](#dagger), and a [`modules`][clu.repl.modules] submodule
focused on printing things about your project’s modules and submodules.
[`clu.scripts`][clu.scripts] contains a [“repl.py”][clu.scripts.repl] file, which is meant to be loaded into an interactive interpreter like e.g.:
```bash
$ bpython -i «PATH_TO_CLU»/clu/scripts/repl.py
```
… which will set all of CLU up for you to use interactively. N.B. if you have your own script you want to include
but stil want to use CLU, you can set the `CLU_USER_SCRIPT` environment variable to the path to your own script,
and our “repl.py” script will pick it up.
[`clu.scripts`][clu.scripts] also contains [`treeline`][clu.scripts.treeline] and [`dictroast`][clu.scripts.dictroast], which
are CLU’s nascent command-line parsing utilities. They make use of the CLU `KeyMap` idiom (q.v. note _supra_)
and are being worked on right this very µsecond!
* [`typespace`][clu.typespace]: Contains a submodule `typespace.namespace` defining `SimpleNamespace` (á la Python 3’s
[`types.SimpleNamespace`][types.SimpleNamespace]) and a slightly more useful `Namespace` ancestor class;
these are used to furnish a `typespace.types` namespace that contains everything in the standard-library
[`types`][types] module, but with all the typenames shortened so they no longer gratuitously end in “Type”. Like e.g.
[`types.ModuleType`][types.ModuleType] is to be found in `typespace.types.Module`, [`types.FunctionType`][types.FunctionType]
is `typespace.types.Function`, et cetera, ad nauseum, so you can just do `from 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 fucking [`types`][types] module and don’t need those overly verbose extra four characters
there at the end. ALSO, there are additional useful types, from Python’s standard library and common packages,
in the [`types` namespace][clu.typespace.namespace]. YOU’RE WELCOME!!
* [`enums`][clu.enums]: Furnishes `alias(…)` – which, spoiler alert, let you create aliases within your enums!
Oh yes. Like so:
```python
from clu.enums import alias
@unique
class Numbers(Enum):
ONE = 1
TWO = 2
THREE = 3
UNO = alias(ONE)
DOS = alias(TWO)
TRÉS = alias(THREE)
assert Numbers.ONE == Numbers.UNO
assert Numbers.TWO == Numbers.DOS
assert Numbers.THREE == Numbers.TRÉS
```
… aaaaand BOOM, there you go! The `alias` members of an enum don’t show up when iterating the
enum’s members, so they’re for your convenience. For a fantastic CLUish real-life example, have a look at
the [`clu.repl.ansi`][clu.repl.ansi] module, and [the enums it defines][clu.repl.ansi.enums] – these use a metaclass
to line the enum’s standard members up with some predefined class attributes defined in a third-party module;
we use `alias(…)` to provide more obvious lexical aliases of these attributes. Yes!
* [`dicts`][clu.dicts]: Functions and classes for wrangling [`dict`s][dicts] (and actually [`Mapping`][collections.abc.Mapping]
and [`MutableMapping`][collections.abc.MutableMapping] descendants in general). There are ABCs for
key/value/item views for your own mappings, a much better `ChainMap`, written from scratch and improving
on [`collections.ChainMap`][collections.ChainMap], plus a `ChainRepr` based on [`reprlib.Repr`][reprlib.Repr],
and a whole bunch of fast dict-merging functions.
* [`exporting`][clu.exporting]: This is kind of the heart of CLU. At the beginning of all internal CLU modules, you’ll find something
using the `Exporter`, like this:
```python
from clu.exporting import Exporter
exporter = Exporter(path=__file__)
export = exporter.decorator()
```
… which I know, I know, the use of `__file__` there is kind of irritating. But that `exporter` instance is now
registered with CLU, and whenever there’s a class or function you want made available outside the module,
you can specify it like:
```python
@export
def public_function():
print("I’m so public")
class PrivateAncestor:
""" I’m more private, don’t play with me """
@export
class PublicThing(PrivateAncestor):
""" I’m very public, indeed, and available """
```
At the end of the module (but before your CLU tests, q.v. note _sub_.) you put:
```python
__all__, __dir__ = exporter.all_and_dir()
```
… which makes things clear what is public and what is private to consumers of your code, without messing
around with underscore prefixes, which I find coarse, and vulgar. You’re not just labeling things for export,
though: [`clu.exporting`][clu.exporting] has tons of machinery for finding out the **“true name”** of a thing,
be it a class (easy), a function (trickier but still easy), an instance (trickier still), and a module variable (totally
very tricky indeed).
For your own project, at some part in your code, all you have to do is: `from clu.exporting import ExporterBase`,
and then subclass `ExporterBase` with your app’s name and base path. Like so:
```python
class Exporter(ExporterBase, basepath="/your/project", appname="MyProject"):
pass
```
… then import your own importer (or call it whatever you want) at the top of your own CLUish modules and
instantiate per the example _supra_. See also [`clu.scripts.dictroast`][clu.scripts.dictroast] for other tricks your
`Exporter` instances can perform.
* [`testing`][clu.testing]: a handy inline unit-test writing setup. It works fine with [`coverage`][coverage-link] and
[`pytest`][pytest-link] – all you have to do is, after your line assigning `__all__` and `__dir__` at the end
of the module proper, something like:
```python
def test():
from clu.testing.utils import inline
@inline.precheck
def before_everything_else():
""" This function runs once before testing """
# ...
@inline
def first_test():
""" This test does one thing """
# ...
@inline
def second_test():
""" This test does another thing """
# ...
@inline.runif(something == something_else)
def test_conditionally_run():
""" This test only does something if `something` == `something_else` """
# ...
@inline.diagnostic
def apres_testing():
""" This function runs once after testing """
# ...
return inline.test(100)
if __name__ == '__main__':
sys.exit(test())
```
… running the module (with either `python -m yourapp.yourmodule` or, say, [Nox][nox-link]) will show
you each tests’ output. But see that `return inline.test(100)` line? That integer argument tells
the CLU testrunner how many times to run each test (we here like to go a hundred times). You’ll get a
report – each test function only prints its output on the first run, the other 99 in this case are muted –
that shows you the time totals, which will look like this:
[](https://github.com/fish2000/CLU/tree/master/scratch/images/clu-testing-time-totals-example.jpg)
… which the astute will note is the output from a non-CLU module. [`clu.testing.utils`][clu.testing.utils]
is very easy to integrate, as it doesn’t require any other part of CLU. Look over [our noxfile][clu-noxfile] for
examples of how to run your inline tests as part of a larger suite.
… there are other testing support tools in[ `clu.testing.utils`][clu.testing.utils], have a look. There’s
also a [`clu.testing.pytest`][clu.testing.pytest] submodule, with some currently-under-development
[`pytest`][pytest-link] plugins.
* [`mathematics`][clu.mathematics]: the future home for math-related stuff. All there is right now is a `clamp(…)` function that works with
[`numpy`][numpy-link] [dtypes][numpy-dtype-link].
* [`naming`][clu.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 use `naming.qualified_import(…)` to import a class [`CurveSet`][instakit.processors.curves.CurveSet]
from its package [`instakit.processors.curves`][instakit.processors.curves] by doing:
```python
CurveSet = qualified_import('instakit.processors.curves.CurveSet')
```
… which that may be handier for you than composing and hard-coding an `import` statement. See also the
`nameof(…)` and `moduleof(…)` functions, and the utility functions (e.g. `qualified_name(…)`) and
predicates (e.g. `isnative(…)`). Most of these functions take literally anything for their argument.
* [`predicates`][clu.predicates]: If [`clu.exporting`][clu.exporting] is the heart, [`clu.predicates`][clu.predicates] is
all of the eyes, ears, fingers and toes of CLU.
* Do you want to know if a class is a metaclass? We have an `ismetaclass(…)` predicate for it, for example.
* Do you want to get an attribute from something you have, but not sure which attributes this _something_
may have (due to versioning or being passed around, or whatever)? `attr(thing, 'one', 'two', default=None)`
will give you `thing.one` if that exists, `thing.two`, if `thing.one` doesn’t, and `None` if neither of them
are there.
* But… would you maybe like to get a tuple with all of the `one` attributes across multiple things?
`attr_across('one', *things)` will do exactly that.
* Similar to the above, `pyattr(…)` does like `attr(…)` except `one` will be expanded to `__one__`, and
`item(…)` searches over mapping keys rather than attribute names.
Sweet, right? These functions, and others in the [`predicates`][clu.predicates] module, are based on `accessor`,
`aquirer`, `searcher`, and `collator` – abstract functions that can themselves be used. In fact most of
[`clu.predicates`][clu.predicates] is written in the functional style – that is to say they are built successively
out of multiple `lambda` statements. If this is not your taste, everything there has been documented thoroughly
for your use and you shouldn’t have to program in this style. But… if you _do_ enjoy a spot of FP, the primitives
in the module perhaps will interest you more than the more utilitarian contents.
* [`sanitizer`][clu.sanitizer]: functions for cleaning up unicode. Right now there is just a list-based `sanitize(…)`
function that tones down anything with high-value code points to the point where it can be safely `ascii`-ified.
* [`typology`][clu.typology]: This is like [`clu.predicates`][clu.predicates] but with more predicates, many of which are
based on typelists. The module is full of typelists and it uses them extensively in its predicates, via `isinstance(…)`,
`issubclass(…)` and a custom version of same called `subclasscheck(…)` which tries very hard to work with
what you give it (instead of just crapping out with a `False` return value). You will want to explore this one!
* [`version`][clu.version]: This is basically my take on the [`semver`][semver-link] package, only with improvements.
I originally developed it for internal use in some of my Python projects, but it stands on its own. You can
construct [`clu.version.VersionInfo`][clu.version.VersionInfo] instances using [`semver`][semver-link]
primitives amongst other things. The (skeletal) [`git_version`][clu.version.git_version] subpackage has a
couple of [Git-related][git-link] functions, but what you really want is in [`read_version`][clu.version.read_version]
– therein you’ll find a `read_version_file(…)` function that uses the `ast` module to read one of those
`__version__.py` files I know you have lying around. Yes
* [The `pytest` testsuite][clu-testsuite]: CLU has a full set of [`pytest`][pytest-link]-compatible unit tests.
In addition to copious module-specific [CLU inline tests][clu.testing], you can run this test suite using
[`pytest`][pytest-link] – or, if you’d like to run *all* the tests, use the fantastic [Nox][nox-link] testrunner
(which we use) along with [our included noxfile][clu-noxfile].
… 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!! [Download][download-link] CLU today and explore – if you want a full list of everything CLU
exports, install it and list them all in your terminal:
$ pip install -U python-clu
$ python -m clu
… which will give you a giant list that looks like this:
[](https://pypi.org/project/python-clu/)
<a name="dagger" style="text-decoration: none;">†</a> – the original code for some modules in CLU (e.g.
[`clu.fs.appdirectories`][clu.fs.appdirectories], [`clu.repl.columnize`][clu.repl.columnize],
[`clu.version.read_version`][clu.version.read_version]) was vendored in from third-party code.
This has all been appropriately licensed and credits are inlined where due. Thanks to all CLU
contributors, big and small!
<!--- LINKS! LINKS! LINKS! -->
[pypi-link]: https://pypi.org/project/python-clu/
[download-link]: https://files.pythonhosted.org/packages/3e/af/4b0dfabe816cee7802cf6981f7f79770c4f05f8df4ac64fc6984789baaaa/python_clu-0.12.3.tar.gz
[homage-replutilities-link]: https://github.com/fish2000/homage/blob/master/.script-bin/replutilities.py
[clu-tron-link]: https://tron.fandom.com/wiki/Clu
[appdirs-link]: https://github.com/ActiveState/appdirs
[coverage-link]: https://coverage.readthedocs.io/en/latest/
[git-link]: https://git-scm.com
[numpy-link]: https://numpy.org
[numpy-dtype-link]: https://numpy.org/doc/stable/user/basics.types.html
[bpython-link]: https://bpython-interpreter.org
[ipython-link]: https://ipython.org
[ptpython-link]: https://github.com/prompt-toolkit/ptpython
[semver-link]: https://pypi.org/project/semver/
[pytest-link]: https://docs.pytest.org/en/stable/
[nox-link]: https://nox.thea.codes/en/stable/
[lego-link]: https://www.lego.com/
[capsela-link]: https://hackaday.com/2017/09/15/retrotectactular-capsela-is-dead-long-live-capsela/
[robotix-link]: https://en.wikipedia.org/wiki/Robotix
[clu.config]: https://github.com/fish2000/CLU/tree/master/clu/config
[clu.config.abc]: https://github.com/fish2000/CLU/tree/master/clu/config/abc.py
[clu.config.env]: https://github.com/fish2000/CLU/tree/master/clu/config/env.py
[clu.config.filebase]: https://github.com/fish2000/CLU/tree/master/clu/config/filebase.py
[clu.config.keymap]: https://github.com/fish2000/CLU/tree/master/clu/config/keymap.py
[clu.config.keymapview]: https://github.com/fish2000/CLU/tree/master/clu/config/keymapview.py
[clu.config.ns]: https://github.com/fish2000/CLU/tree/master/clu/config/ns.py
[clu.config.proxy]: https://github.com/fish2000/CLU/tree/master/clu/config/proxy.py
[clu.constants]: https://github.com/fish2000/CLU/tree/master/clu/constants
[clu.constants.consts]: https://github.com/fish2000/CLU/tree/master/clu/constants/consts.py
[clu.constants.polyfills]: https://github.com/fish2000/CLU/tree/master/clu/constants/polyfills.py
[clu.fs]: https://github.com/fish2000/CLU/tree/master/clu/fs
[clu.fs.abc]: https://github.com/fish2000/CLU/tree/master/clu/fs/abc.py
[clu.fs.appdirectories]: https://github.com/fish2000/CLU/tree/master/clu/fs/appdirectories.py
[clu.fs.filesystem]: https://github.com/fish2000/CLU/tree/master/clu/fs/filesystem.py
[clu.fs.misc]: https://github.com/fish2000/CLU/tree/master/clu/fs/misc.py
[clu.fs.pypath]: https://github.com/fish2000/CLU/tree/master/clu/fs/pypath.py
[clu.importing]: https://github.com/fish2000/CLU/tree/master/clu/importing
[clu.importing.base]: https://github.com/fish2000/CLU/tree/master/clu/importing/base.py
[clu.importing.proxy]: https://github.com/fish2000/CLU/tree/master/clu/importing/proxy.py
[clu.repl]: https://github.com/fish2000/CLU/tree/master/clu/repl
[clu.repl.ansi]: https://github.com/fish2000/CLU/tree/master/clu/repl/ansi.py
[clu.repl.ansi.enums]: https://github.com/fish2000/CLU/blob/c5be3edcea7774b0d042b13125458fef6bd8a303/clu/repl/ansi.py#L150-L222
[clu.repl.banners]: https://github.com/fish2000/CLU/tree/master/clu/repl/banners.py
[clu.repl.columnize]: https://github.com/fish2000/CLU/tree/master/clu/repl/columnize.py
[clu.repl.modules]: https://github.com/fish2000/CLU/tree/master/clu/repl/modules.py
[clu.scripts]: https://github.com/fish2000/CLU/tree/master/clu/scripts
[clu.scripts.dictroast]: https://github.com/fish2000/CLU/tree/master/clu/scripts/dictroast.py
[clu.scripts.repl]: https://github.com/fish2000/CLU/tree/master/clu/scripts/repl.py
[clu.scripts.treeline]: https://github.com/fish2000/CLU/tree/master/clu/scripts/treeline.py
[clu.testing]: https://github.com/fish2000/CLU/tree/master/clu/testing
[clu.testing.pytest]: https://github.com/fish2000/CLU/tree/master/clu/testing/pytest.py
[clu.testing.utils]: https://github.com/fish2000/CLU/tree/master/clu/testing/utils.py
[clu.typespace]: https://github.com/fish2000/CLU/tree/master/clu/typespace
[clu.typespace.namespace]: https://github.com/fish2000/CLU/tree/master/clu/typespace/namespace.py
[clu.version]: https://github.com/fish2000/CLU/tree/master/clu/version
[clu.version.git_version]: https://github.com/fish2000/CLU/tree/master/clu/version/git_version.py
[clu.version.read_version]: https://github.com/fish2000/CLU/tree/master/clu/version/read_version.py
[clu.version.VersionInfo]: https://github.com/fish2000/CLU/blob/9f64200a947dbdcbf7eca44b87d0d9efeb4c6de7/clu/version/__init__.py#L100-L248
[clu]: https://github.com/fish2000/CLU
[clu-testsuite]: https://github.com/fish2000/CLU/tree/master/tests
[clu-noxfile]: https://github.com/fish2000/CLU/blob/master/noxfile.py
[clu.abstract]: https://github.com/fish2000/CLU/tree/master/clu/abstract.py
[clu.all]: https://github.com/fish2000/CLU/tree/master/clu/all.py
[clu.application]: https://github.com/fish2000/CLU/tree/master/clu/application.py
[clu.csv]: https://github.com/fish2000/CLU/tree/master/clu/csv.py
[clu.dicts]: https://github.com/fish2000/CLU/tree/master/clu/dicts.py
[clu.dispatch]: https://github.com/fish2000/CLU/tree/master/clu/dispatch.py
[clu.enums]: https://github.com/fish2000/CLU/tree/master/clu/enums.py
[clu.exporting]: https://github.com/fish2000/CLU/tree/master/clu/exporting.py
[clu.extending]: https://github.com/fish2000/CLU/tree/master/clu/extending.py
[clu.keyvalue]: https://github.com/fish2000/CLU/tree/master/clu/keyvalue.py
[clu.mathematics]: https://github.com/fish2000/CLU/tree/master/clu/mathematics.py
[clu.naming]: https://github.com/fish2000/CLU/tree/master/clu/naming.py
[clu.predicates]: https://github.com/fish2000/CLU/tree/master/clu/predicates.py
[clu.repr]: https://github.com/fish2000/CLU/tree/master/clu/repr.py
[clu.sanitizer]: https://github.com/fish2000/CLU/tree/master/clu/sanitizer.py
[clu.stdio]: https://github.com/fish2000/CLU/tree/master/clu/stdio.py
[clu.typology]: https://github.com/fish2000/CLU/tree/master/clu/typology.py
[instakit]: https://github.com/fish2000/instakit
[instakit.processors.curves]: https://github.com/fish2000/instakit/blob/master/instakit/processors/curves.py
[instakit.processors.curves.CurveSet]: https://github.com/fish2000/instakit/blob/ad5591c88176c2c997d86833b93dde017545277f/instakit/processors/curves.py#L109-L240
[collections.abc.Mapping]: https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping
[collections.abc.MutableMapping]: https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping
[collections.ChainMap]: https://docs.python.org/3/library/collections.html#chainmap-objects
[reprlib.Repr]: https://docs.python.org/3/library/reprlib.html#reprlib.Repr
[sys.path]: https://docs.python.org/3/library/sys_path_init.html
[tempfile.NamedTemporaryFIle]: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
[types]: https://docs.python.org/3/library/types.html
[types.ModuleType]: https://docs.python.org/3/library/types.html#types.ModuleType
[types.FunctionType]: https://docs.python.org/3/library/types.html#types.FunctionType
[types.SimpleNamespace]: https://docs.python.org/3/library/types.html#additional-utility-classes-and-functions
[zipfile]: https://docs.python.org/3/library/zipfile.html
[dicts]: https://docs.python.org/3/tutorial/datastructures.html#dictionaries
Raw data
{
"_id": null,
"home_page": "https://github.com/fish2000/clu",
"name": "python-clu",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": "Alexander B\u00f6hn <fish2000@gmail.com>",
"keywords": "testing, command, command-line, utilities, modules, REPL, tools",
"author": "Alexander B\u00f6hn",
"author_email": "Alexander B\u00f6hn <fish2000@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c4/2d/225ac8571cb0d95b5bfe1ce0d51751b9b1d0598cf531cd22dfa591bd171c/python_clu-0.12.9.tar.gz",
"platform": "any",
"description": "[Python-CLU][clu] \u2013 Common Lightweight Utilities\n========================================================\n\n[](https://codecov.io/gh/fish2000/CLU/)\n\nInstall it right now! [Download][download-link] or type: `$ pip install -U python-clu`\n------------------------------------------------------------------------------\n\nThe deal with CLU is, it is a bunch of stuff. Like, a junk drawer\u2026 but a junk drawer\nfull of building sets: [Legos][lego-link], [Robotix][robotix-link], [Capsela][capsela-link]\n\u2013 and also magic interfaces that let somehow you plug Legos into Capselas and all\nthat. It\u2019s a la carte: you can use one part of CLU (say the [inline testing stuff][clu.testing.utils])\nand ignore the rest. Or just the [`exporter`][clu.exporting], or just the [`predicates`][clu.predicates]\ncollection. Naturally, these things taste great and also taste great together, too.\n\n[](https://www.reddit.com/r/Xennials/comments/1aixaq7/construx_and_capsela_anyone_else_have_any/)\n\nCLU started out as a packaged-up and sanely written version of\n[the Python tools I wrote for my REPLs][homage-replutilities-link], divided up into\na bunch of subordinate packages. It\u2019s grown magnificently since then (if I do say so myself).\nAnd if you are wondering if \u201cCLU\u201d is a Tron reference, [you are correct][clu-tron-link].\n\u201cCLU\u201d stands for \u201cCommon Lightweight Utilities\u201d \u2013 it started out as an acronym for\n\u201cCommand-Line Utilities\u201d but it has grown useful beyond that scope, indeed.\n\nThe subordinate packages are pretty well-divided: [`clu.config`][clu.config] contains\nthings to help with configuration, like [config-file loading and saving][clu.config.filebase],\nand data structures like [our famous namespaced keymaps][clu.config.keymap].\n[`clu.exporting`][clu.exporting] has the `@export` decorator, a utility to easily label module\nmembers for export by adding them to a modules\u2019 `__all__` and `__dir__` members,\nplus other stuff like real-name determination. Which, speaking of which, [`clu.naming`][clu.naming]\nhas additional easy functions for dealing with the names of your things and other peoples\u2019,\nand [`clu.repr`][clu.repr] has stuff for easily printing, getting, and specifying an objects\u2019\nstring representation.\n\nYou\u2019ll like [`clu.abstract`][clu.abstract] if you like building class towers \u2013 we have ABCs\nfor all types of things. If you like [`dict`s][dicts], check out the aforementioned [`clu.config.keymap`][clu.config.keymap]\nand [`clu.dicts`][clu.dicts] modules \u2013 you\u2019ll find things to build dictionary types, represent\nthem, and deal with them later. [`clu.dispatch`][clu.dispatch] will help you manage\nsubprocesses easily, [`clu.version`][clu.version] is better then [`semver`][semver-link]\n(I promise), [`clu.testing`][clu.testing] is great for inlining some quick unit tests, and\n[`clu.scripts`][clu.scripts] and [`clu.repl`][clu.repl] are what you want for whatever your\nREPL environment may be\u2026 [`bpython`][bpython-link], [`ipython`][ipython-link],\n[`ptpython`][ptpython-link], and many others I am sure!\n\nSo do have a look around. Here\u2019s an abridged breakdown of some things within:\n\n* [`config`][clu.config]: Tons of useful things for dealing with your app\u2019s configuration. These are centered\n around lexically namespaced dictionaries called \u201cKeyMaps\u201d, which basic examples of which can be\n found in [`clu.config.keymap`][clu.config.keymap]. If your nested data looks like:\n\n ```python\n data = {\n 'yo' : {\n 'dogg' : {\n 'i-heard' : {\n 'you-like' : \"nested data\"\n }\n }\n }\n }\n ```\n \n \u2026 and you assign it to a keymap, like e.g. `keyed = keymap.Nested(data).flatten()`, then you can\n use `keyed` like so:\n \n ```python\n assert keyed[\"yo:dogg:i-heard:you-like\"] == \"nested data\"\n ```\n \n \u2026 The `Flat` and `Nested` classes are cheap to construct and lightweight, and generally act like most\n [`dict`][dicts] instances in most of the expected ways. There is also an environment-variable [`keymap`][clu.config.keymap]\n adapter in [`clu.config.env`][clu.config.env], which if your app uses environment variables that look like like\n `MYAPP_CONFIG_THINGY`, they can be accessed through `env.FrozenEnviron(appname='myapp')` or\n `env.Environ(appname='myapp')` like so:\n \n ```python\n appenv = Environ(appname='myapp')\n assert appenv['config:thingy'] == \"some value\"\n appenv['config:doohickey'] = \"a different value\" # sets MYAPP_CONFIG_DOOHICKEY\n # in the current env\n ```\n \n \u2026 and there are plenty of tools for rolling your own `KeyMap`s in [`clu.config`][clu.config]: the\n [`proxy`][clu.config.proxy] subpackage has a `KeyMap` proxy class, [`ns`][clu.config.ns] has utility functions\n for manipulating namespace strings, [`keymapview`][clu.config.keymapview] has a class tower for\n [`KeyMap`][clu.config.keymap] key/value/item views, and [`abc`][clu.config.abc] has, as you\u2019d expect, all\n the abstract base classes upon which our [`KeyMap`s][clu.config.keymap] are built, for your perusal and\n eventual enjoyment.\n\n* [`constants`][clu.constants]: Definitions of [useful constants][clu.constants.consts], as well as\n [polyfills][clu.constants.polyfills] to allow certain dependencies from the Python standard library to work even\n when some of their moving parts are missing (i.e. Ye Olde Pythone 2.7, various PyPy implementations, etc).\n\n* [`all`][clu.all]: Herein you will find some verrrrry interesting \u201cmeta\u201d functions for CLU. You have the `import_all_modules(\u2026)`\n function, which when provided your projects\u2019 base path and appname, will return all the package names therein,\n whether class-based modules defined through [`clu.exporting`][clu.exporting] or plain ol\u2019 modules defined by files\n ending in \u201c.py\u201d, basically. It\u2019s awesome.\n \n The companion function `import_clu_modules(\u00ac)` is a shortcut just for everything within CLU, and `inline_tests(\u2026)`\n yields an iterator over every CLU module that defines inline tests through [`clu.testing`][clu.testing]. These\n are very useful within CLU; for your own project, write your own functions modeled after these! You can\u2019t go wrong.\n\n* [`fs`][clu.fs]: Filesystem-related things. Submodules include:\n \n * [`fs.filesystem`][clu.fs.filesystem]: classes representing filesystem primitives like `Directory`,\n `TemporaryDirectory`, `TemporaryName`; a version of [`tempfile.NamedTemporaryFile`][tempfile.NamedTemporaryFile]\n that works with or without the leading dot in the provided suffix (a peeve of mine); functions\n for common filesystem operations like `which(\u2026)`, `back_ticks(\u2026)`, `rm_rf(\u2026)` (be careful\n with that one), and so forth. \n \n * The `Directory` class is particularly extensive, with methods for [Zipfile][zipfile] archiving, searching\n for importable Python files and others, file-suffix histograms, context-managed working-directory\n management, walking and reverse-walking, and much more.\n \n * [`fs.appdirectories`][clu.fs.appdirectories]: Started out as a pretty much wholesale duplication of the popular\n [`appdirs`][appdirs-link] package[<sup>\u2020</sup>](#dagger) \u2013 but it\u2019s been kitted out with many CLUish things, e.g.\n [`clu.fs.filesystem.Directory`][clu.fs.filesystem] instances. A solid upgrade in my opinion!\n \n * [`fs.misc`][clu.fs.misc]: a bunch of useful miscellany \u2013 noteworthy standouts include regex utility functions for\n constructing filename regex match or exclusion tests.\n \n * [`fs.pypath`][clu.fs.pypath]: functions for safe manipulation of [`sys.path`][sys.path] \u2013 `enhance(\u2026)`,\n `remove_paths(\u2026)`, `remove_invalid_paths()`, &c.\n \n* [`importing`][clu.importing]: a whole class-based-module system! Basically you can do this:\n\n ```python\n class Derived(clu.importing.base.Module):\n \n \"\"\" I heard you like docstrings \"\"\"\n \n yo = 'dogg'\n \n @export\n def yodogg(self):\n return \"I heard you like\"\n \n @export\n def nodogg(self):\n return None\n \n export(yo, name='yo')\n \n from clu.app import Derived as derived # TAKE NOTE!!!\n \n assert isinstance(derived, Module)\n assert derived.yo == 'dogg'\n assert derived.yodogg() == \"I heard you like\"\n assert derived.nodogg() is None\n ```\n\n \u2026 see that? just by subclassing [`clu.importing.base.Module`][clu.importing.base] you can create something\n instantly importable. Awesome, wouldn\u2019t you say? I would say. We\u2019re working out the best way to create the\n base `Module` for your own project (the machinery is there but the semantics are not yet perfect) but do feel\n free to play around with the stuff in [`clu.importing.base`][clu.importing.base], and have a look at the\n implementation in [`clu.importing.proxy`][clu.importing.proxy] of the \u201cparameterized\u201d `ProxyModule` (there\u2019s a\n `ChainModuleMap` container available in the [`proxy`][clu.importing.proxy] submodule, too).\n\n* [`repl`][clu.repl] and [`scripts`][clu.scripts]: Tools useful in Python REPL environments. In [`clu.repl`][clu.repl],\n there\u2019s a while module full of ANSI printing and formatting utilities, many of them as classes, a [`columnize`][clu.repl.columnize]\n function for, uh, printing things in columns[<sup>\u2020</sup>](#dagger), and a [`modules`][clu.repl.modules] submodule\n focused on printing things about your project\u2019s modules and submodules.\n \n [`clu.scripts`][clu.scripts] contains a [\u201crepl.py\u201d][clu.scripts.repl] file, which is meant to be loaded into an interactive interpreter like e.g.:\n \n ```bash\n $ bpython -i \u00abPATH_TO_CLU\u00bb/clu/scripts/repl.py\n ```\n \n \u2026 which will set all of CLU up for you to use interactively. N.B. if you have your own script you want to include\n but stil want to use CLU, you can set the `CLU_USER_SCRIPT` environment variable to the path to your own script,\n and our \u201crepl.py\u201d script will pick it up. \n \n [`clu.scripts`][clu.scripts] also contains [`treeline`][clu.scripts.treeline] and [`dictroast`][clu.scripts.dictroast], which\n are CLU\u2019s nascent command-line parsing utilities. They make use of the CLU `KeyMap` idiom (q.v. note _supra_)\n and are being worked on right this very \u00b5second!\n\n* [`typespace`][clu.typespace]: Contains a submodule `typespace.namespace` defining `SimpleNamespace` (\u00e1 la Python 3\u2019s\n [`types.SimpleNamespace`][types.SimpleNamespace]) and a slightly more useful `Namespace` ancestor class;\n these are used to furnish a `typespace.types` namespace that contains everything in the standard-library\n [`types`][types] module, but with all the typenames shortened so they no longer gratuitously end in \u201cType\u201d. Like e.g.\n [`types.ModuleType`][types.ModuleType] is to be found in `typespace.types.Module`, [`types.FunctionType`][types.FunctionType]\n is `typespace.types.Function`, et cetera, ad nauseum, so you can just do `from clu.typespace import types`\n to lose the redundant \u201cType\u201d naming suffix \u2013 which I don\u2019t know about you but that annoys me, I mean we all know\n that these things are types because they are in the fucking [`types`][types] module and don\u2019t need those overly verbose extra four characters\n there at the end. ALSO, there are additional useful types, from Python\u2019s standard library and common packages,\n in the [`types` namespace][clu.typespace.namespace]. YOU\u2019RE WELCOME!!\n\n* [`enums`][clu.enums]: Furnishes `alias(\u2026)` \u2013 which, spoiler alert, let you create aliases within your enums!\n Oh yes. Like so:\n \n ```python\n \n from clu.enums import alias\n \n @unique\n class Numbers(Enum):\n ONE = 1\n TWO = 2\n THREE = 3\n UNO = alias(ONE)\n DOS = alias(TWO)\n TR\u00c9S = alias(THREE)\n \n assert Numbers.ONE == Numbers.UNO\n assert Numbers.TWO == Numbers.DOS\n assert Numbers.THREE == Numbers.TR\u00c9S\n \n ```\n \n \u2026 aaaaand BOOM, there you go! The `alias` members of an enum don\u2019t show up when iterating the\n enum\u2019s members, so they\u2019re for your convenience. For a fantastic CLUish real-life example, have a look at\n the [`clu.repl.ansi`][clu.repl.ansi] module, and [the enums it defines][clu.repl.ansi.enums] \u2013 these use a metaclass\n to line the enum\u2019s standard members up with some predefined class attributes defined in a third-party module;\n we use `alias(\u2026)` to provide more obvious lexical aliases of these attributes. Yes!\n\n* [`dicts`][clu.dicts]: Functions and classes for wrangling [`dict`s][dicts] (and actually [`Mapping`][collections.abc.Mapping]\n and [`MutableMapping`][collections.abc.MutableMapping] descendants in general). There are ABCs for\n key/value/item views for your own mappings, a much better `ChainMap`, written from scratch and improving\n on [`collections.ChainMap`][collections.ChainMap], plus a `ChainRepr` based on [`reprlib.Repr`][reprlib.Repr],\n and a whole bunch of fast dict-merging functions.\n\n* [`exporting`][clu.exporting]: This is kind of the heart of CLU. At the beginning of all internal CLU modules, you\u2019ll find something\n using the `Exporter`, like this:\n \n ```python\n from clu.exporting import Exporter\n \n exporter = Exporter(path=__file__)\n export = exporter.decorator()\n ```\n \u2026 which I know, I know, the use of `__file__` there is kind of irritating. But that `exporter` instance is now\n registered with CLU, and whenever there\u2019s a class or function you want made available outside the module,\n you can specify it like:\n \n ```python\n @export\n def public_function():\n print(\"I\u2019m so public\")\n \n class PrivateAncestor:\n \"\"\" I\u2019m more private, don\u2019t play with me \"\"\"\n \n @export\n class PublicThing(PrivateAncestor):\n \"\"\" I\u2019m very public, indeed, and available \"\"\"\n ```\n \n At the end of the module (but before your CLU tests, q.v. note _sub_.) you put:\n \n ```python\n __all__, __dir__ = exporter.all_and_dir()\n ```\n \n \u2026 which makes things clear what is public and what is private to consumers of your code, without messing\n around with underscore prefixes, which I find coarse, and vulgar. You\u2019re not just labeling things for export,\n though: [`clu.exporting`][clu.exporting] has tons of machinery for finding out the **\u201ctrue name\u201d** of a thing,\n be it a class (easy), a function (trickier but still easy), an instance (trickier still), and a module variable (totally\n very tricky indeed).\n \n For your own project, at some part in your code, all you have to do is: `from clu.exporting import ExporterBase`,\n and then subclass `ExporterBase` with your app\u2019s name and base path. Like so:\n \n ```python\n class Exporter(ExporterBase, basepath=\"/your/project\", appname=\"MyProject\"):\n pass\n ```\n \n \u2026 then import your own importer (or call it whatever you want) at the top of your own CLUish modules and\n instantiate per the example _supra_. See also [`clu.scripts.dictroast`][clu.scripts.dictroast] for other tricks your\n `Exporter` instances can perform. \n\n* [`testing`][clu.testing]: a handy inline unit-test writing setup. It works fine with [`coverage`][coverage-link] and\n [`pytest`][pytest-link] \u2013 all you have to do is, after your line assigning `__all__` and `__dir__` at the end\n of the module proper, something like:\n \n ```python\n def test():\n from clu.testing.utils import inline\n \n @inline.precheck\n def before_everything_else():\n \t \"\"\" This function runs once before testing \"\"\"\n # ...\n \n @inline\n def first_test():\n \"\"\" This test does one thing \"\"\"\n # ...\n \n @inline\n def second_test():\n \t \"\"\" This test does another thing \"\"\"\n # ...\n \n @inline.runif(something == something_else)\n def test_conditionally_run():\n \t \"\"\" This test only does something if `something` == `something_else` \"\"\"\n # ...\n \n @inline.diagnostic\n def apres_testing():\n \t \"\"\" This function runs once after testing \"\"\"\n # ...\n \n return inline.test(100)\n \n if __name__ == '__main__':\n sys.exit(test())\n ```\n\n \u2026 running the module (with either `python -m yourapp.yourmodule` or, say, [Nox][nox-link]) will show\n you each tests\u2019 output. But see that `return inline.test(100)` line? That integer argument tells\n the CLU testrunner how many times to run each test (we here like to go a hundred times). You\u2019ll get a\n report \u2013 each test function only prints its output on the first run, the other 99 in this case are muted \u2013\n that shows you the time totals, which will look like this:\n \n [](https://github.com/fish2000/CLU/tree/master/scratch/images/clu-testing-time-totals-example.jpg)\n \n \u2026 which the astute will note is the output from a non-CLU module. [`clu.testing.utils`][clu.testing.utils]\n is very easy to integrate, as it doesn\u2019t require any other part of CLU. Look over [our noxfile][clu-noxfile] for\n examples of how to run your inline tests as part of a larger suite.\n \n \u2026 there are other testing support tools in[ `clu.testing.utils`][clu.testing.utils], have a look. There\u2019s\n also a [`clu.testing.pytest`][clu.testing.pytest] submodule, with some currently-under-development\n [`pytest`][pytest-link] plugins.\n\n* [`mathematics`][clu.mathematics]: the future home for math-related stuff. All there is right now is a `clamp(\u2026)` function that works with\n [`numpy`][numpy-link] [dtypes][numpy-dtype-link].\n\n* [`naming`][clu.naming]: functions for determining the names of things (even module constants and other random things\n that generally lack things like `__name__` attributes) and for the importing and exporting of things by\n \u201cqualified names\u201d \u2013 for instance, you can use `naming.qualified_import(\u2026)` to import a class [`CurveSet`][instakit.processors.curves.CurveSet]\n from its package [`instakit.processors.curves`][instakit.processors.curves] by doing:\n \n ```python\n CurveSet = qualified_import('instakit.processors.curves.CurveSet')\n ```\n \n \u2026 which that may be handier for you than composing and hard-coding an `import` statement. See also the\n `nameof(\u2026)` and `moduleof(\u2026)` functions, and the utility functions (e.g. `qualified_name(\u2026)`) and\n predicates (e.g. `isnative(\u2026)`). Most of these functions take literally anything for their argument.\n\n* [`predicates`][clu.predicates]: If [`clu.exporting`][clu.exporting] is the heart, [`clu.predicates`][clu.predicates] is\n all of the eyes, ears, fingers and toes of CLU.\n \n * Do you want to know if a class is a metaclass? We have an `ismetaclass(\u2026)` predicate for it, for example.\n * Do you want to get an attribute from something you have, but not sure which attributes this _something_\n may have (due to versioning or being passed around, or whatever)? `attr(thing, 'one', 'two', default=None)`\n will give you `thing.one` if that exists, `thing.two`, if `thing.one` doesn\u2019t, and `None` if neither of them\n are there.\n * But\u2026 would you maybe like to get a tuple with all of the `one` attributes across multiple things?\n `attr_across('one', *things)` will do exactly that.\n * Similar to the above, `pyattr(\u2026)` does like `attr(\u2026)` except `one` will be expanded to `__one__`, and\n `item(\u2026)` searches over mapping keys rather than attribute names. \n \n Sweet, right? These functions, and others in the [`predicates`][clu.predicates] module, are based on `accessor`,\n `aquirer`, `searcher`, and `collator` \u2013 abstract functions that can themselves be used. In fact most of\n [`clu.predicates`][clu.predicates] is written in the functional style \u2013 that is to say they are built successively\n out of multiple `lambda` statements. If this is not your taste, everything there has been documented thoroughly\n for your use and you shouldn\u2019t have to program in this style. But\u2026 if you _do_ enjoy a spot of FP, the primitives\n in the module perhaps will interest you more than the more utilitarian contents.\n\n* [`sanitizer`][clu.sanitizer]: functions for cleaning up unicode. Right now there is just a list-based `sanitize(\u2026)`\n function that tones down anything with high-value code points to the point where it can be safely `ascii`-ified. \n\n* [`typology`][clu.typology]: This is like [`clu.predicates`][clu.predicates] but with more predicates, many of which are\n based on typelists. The module is full of typelists and it uses them extensively in its predicates, via `isinstance(\u2026)`,\n `issubclass(\u2026)` and a custom version of same called `subclasscheck(\u2026)` which tries very hard to work with\n what you give it (instead of just crapping out with a `False` return value). You will want to explore this one!\n\n* [`version`][clu.version]: This is basically my take on the [`semver`][semver-link] package, only with improvements.\n I originally developed it for internal use in some of my Python projects, but it stands on its own. You can\n construct [`clu.version.VersionInfo`][clu.version.VersionInfo] instances using [`semver`][semver-link]\n primitives amongst other things. The (skeletal) [`git_version`][clu.version.git_version] subpackage has a\n couple of [Git-related][git-link] functions, but what you really want is in [`read_version`][clu.version.read_version]\n \u2013 therein you\u2019ll find a `read_version_file(\u2026)` function that uses the `ast` module to read one of those\n `__version__.py` files I know you have lying around. Yes\n\n* [The `pytest` testsuite][clu-testsuite]: CLU has a full set of [`pytest`][pytest-link]-compatible unit tests.\n In addition to copious module-specific [CLU inline tests][clu.testing], you can run this test suite using\n [`pytest`][pytest-link] \u2013 or, if you\u2019d like to run *all* the tests, use the fantastic [Nox][nox-link] testrunner\n (which we use) along with [our included noxfile][clu-noxfile].\n\n\u2026 AND MORE!!! There really are a ton of useful things in here and one day I will list them (but not today). \n Have fun with it!! [Download][download-link] CLU today and explore \u2013 if you want a full list of everything CLU\n exports, install it and list them all in your terminal:\n\n $ pip install -U python-clu\n $ python -m clu\n\n\u2026 which will give you a giant list that looks like this:\n\n[](https://pypi.org/project/python-clu/)\n\n<a name=\"dagger\" style=\"text-decoration: none;\">\u2020</a> \u2013 the original code for some modules in CLU (e.g.\n [`clu.fs.appdirectories`][clu.fs.appdirectories], [`clu.repl.columnize`][clu.repl.columnize],\n [`clu.version.read_version`][clu.version.read_version]) was vendored in from third-party code.\n This has all been appropriately licensed and credits are inlined where due. Thanks to all CLU\n contributors, big and small!\n\n<!--- LINKS! LINKS! LINKS! -->\n[pypi-link]: https://pypi.org/project/python-clu/\n[download-link]: https://files.pythonhosted.org/packages/3e/af/4b0dfabe816cee7802cf6981f7f79770c4f05f8df4ac64fc6984789baaaa/python_clu-0.12.3.tar.gz\n[homage-replutilities-link]: https://github.com/fish2000/homage/blob/master/.script-bin/replutilities.py\n[clu-tron-link]: https://tron.fandom.com/wiki/Clu\n\n[appdirs-link]: https://github.com/ActiveState/appdirs\n[coverage-link]: https://coverage.readthedocs.io/en/latest/\n[git-link]: https://git-scm.com\n[numpy-link]: https://numpy.org\n[numpy-dtype-link]: https://numpy.org/doc/stable/user/basics.types.html\n[bpython-link]: https://bpython-interpreter.org\n[ipython-link]: https://ipython.org\n[ptpython-link]: https://github.com/prompt-toolkit/ptpython\n[semver-link]: https://pypi.org/project/semver/\n[pytest-link]: https://docs.pytest.org/en/stable/\n[nox-link]: https://nox.thea.codes/en/stable/\n[lego-link]: https://www.lego.com/\n[capsela-link]: https://hackaday.com/2017/09/15/retrotectactular-capsela-is-dead-long-live-capsela/\n[robotix-link]: https://en.wikipedia.org/wiki/Robotix\n\n[clu.config]: https://github.com/fish2000/CLU/tree/master/clu/config\n[clu.config.abc]: https://github.com/fish2000/CLU/tree/master/clu/config/abc.py\n[clu.config.env]: https://github.com/fish2000/CLU/tree/master/clu/config/env.py\n[clu.config.filebase]: https://github.com/fish2000/CLU/tree/master/clu/config/filebase.py\n[clu.config.keymap]: https://github.com/fish2000/CLU/tree/master/clu/config/keymap.py\n[clu.config.keymapview]: https://github.com/fish2000/CLU/tree/master/clu/config/keymapview.py\n[clu.config.ns]: https://github.com/fish2000/CLU/tree/master/clu/config/ns.py\n[clu.config.proxy]: https://github.com/fish2000/CLU/tree/master/clu/config/proxy.py\n\n[clu.constants]: https://github.com/fish2000/CLU/tree/master/clu/constants\n[clu.constants.consts]: https://github.com/fish2000/CLU/tree/master/clu/constants/consts.py\n[clu.constants.polyfills]: https://github.com/fish2000/CLU/tree/master/clu/constants/polyfills.py\n\n[clu.fs]: https://github.com/fish2000/CLU/tree/master/clu/fs\n[clu.fs.abc]: https://github.com/fish2000/CLU/tree/master/clu/fs/abc.py\n[clu.fs.appdirectories]: https://github.com/fish2000/CLU/tree/master/clu/fs/appdirectories.py\n[clu.fs.filesystem]: https://github.com/fish2000/CLU/tree/master/clu/fs/filesystem.py\n[clu.fs.misc]: https://github.com/fish2000/CLU/tree/master/clu/fs/misc.py\n[clu.fs.pypath]: https://github.com/fish2000/CLU/tree/master/clu/fs/pypath.py\n\n[clu.importing]: https://github.com/fish2000/CLU/tree/master/clu/importing\n[clu.importing.base]: https://github.com/fish2000/CLU/tree/master/clu/importing/base.py\n[clu.importing.proxy]: https://github.com/fish2000/CLU/tree/master/clu/importing/proxy.py\n\n[clu.repl]: https://github.com/fish2000/CLU/tree/master/clu/repl\n[clu.repl.ansi]: https://github.com/fish2000/CLU/tree/master/clu/repl/ansi.py\n[clu.repl.ansi.enums]: https://github.com/fish2000/CLU/blob/c5be3edcea7774b0d042b13125458fef6bd8a303/clu/repl/ansi.py#L150-L222\n[clu.repl.banners]: https://github.com/fish2000/CLU/tree/master/clu/repl/banners.py\n[clu.repl.columnize]: https://github.com/fish2000/CLU/tree/master/clu/repl/columnize.py\n[clu.repl.modules]: https://github.com/fish2000/CLU/tree/master/clu/repl/modules.py\n\n[clu.scripts]: https://github.com/fish2000/CLU/tree/master/clu/scripts\n[clu.scripts.dictroast]: https://github.com/fish2000/CLU/tree/master/clu/scripts/dictroast.py\n[clu.scripts.repl]: https://github.com/fish2000/CLU/tree/master/clu/scripts/repl.py\n[clu.scripts.treeline]: https://github.com/fish2000/CLU/tree/master/clu/scripts/treeline.py\n\n[clu.testing]: https://github.com/fish2000/CLU/tree/master/clu/testing\n[clu.testing.pytest]: https://github.com/fish2000/CLU/tree/master/clu/testing/pytest.py\n[clu.testing.utils]: https://github.com/fish2000/CLU/tree/master/clu/testing/utils.py\n\n[clu.typespace]: https://github.com/fish2000/CLU/tree/master/clu/typespace\n[clu.typespace.namespace]: https://github.com/fish2000/CLU/tree/master/clu/typespace/namespace.py\n\n[clu.version]: https://github.com/fish2000/CLU/tree/master/clu/version\n[clu.version.git_version]: https://github.com/fish2000/CLU/tree/master/clu/version/git_version.py\n[clu.version.read_version]: https://github.com/fish2000/CLU/tree/master/clu/version/read_version.py\n[clu.version.VersionInfo]: https://github.com/fish2000/CLU/blob/9f64200a947dbdcbf7eca44b87d0d9efeb4c6de7/clu/version/__init__.py#L100-L248\n\n[clu]: https://github.com/fish2000/CLU\n[clu-testsuite]: https://github.com/fish2000/CLU/tree/master/tests\n[clu-noxfile]: https://github.com/fish2000/CLU/blob/master/noxfile.py\n\n[clu.abstract]: https://github.com/fish2000/CLU/tree/master/clu/abstract.py\n[clu.all]: https://github.com/fish2000/CLU/tree/master/clu/all.py\n[clu.application]: https://github.com/fish2000/CLU/tree/master/clu/application.py\n[clu.csv]: https://github.com/fish2000/CLU/tree/master/clu/csv.py\n[clu.dicts]: https://github.com/fish2000/CLU/tree/master/clu/dicts.py\n[clu.dispatch]: https://github.com/fish2000/CLU/tree/master/clu/dispatch.py\n[clu.enums]: https://github.com/fish2000/CLU/tree/master/clu/enums.py\n[clu.exporting]: https://github.com/fish2000/CLU/tree/master/clu/exporting.py\n[clu.extending]: https://github.com/fish2000/CLU/tree/master/clu/extending.py\n[clu.keyvalue]: https://github.com/fish2000/CLU/tree/master/clu/keyvalue.py\n[clu.mathematics]: https://github.com/fish2000/CLU/tree/master/clu/mathematics.py\n[clu.naming]: https://github.com/fish2000/CLU/tree/master/clu/naming.py\n[clu.predicates]: https://github.com/fish2000/CLU/tree/master/clu/predicates.py\n[clu.repr]: https://github.com/fish2000/CLU/tree/master/clu/repr.py\n[clu.sanitizer]: https://github.com/fish2000/CLU/tree/master/clu/sanitizer.py\n[clu.stdio]: https://github.com/fish2000/CLU/tree/master/clu/stdio.py\n[clu.typology]: https://github.com/fish2000/CLU/tree/master/clu/typology.py\n\n[instakit]: https://github.com/fish2000/instakit\n[instakit.processors.curves]: https://github.com/fish2000/instakit/blob/master/instakit/processors/curves.py\n[instakit.processors.curves.CurveSet]: https://github.com/fish2000/instakit/blob/ad5591c88176c2c997d86833b93dde017545277f/instakit/processors/curves.py#L109-L240\n[collections.abc.Mapping]: https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping\n[collections.abc.MutableMapping]: https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping\n[collections.ChainMap]: https://docs.python.org/3/library/collections.html#chainmap-objects\n[reprlib.Repr]: https://docs.python.org/3/library/reprlib.html#reprlib.Repr\n[sys.path]: https://docs.python.org/3/library/sys_path_init.html\n[tempfile.NamedTemporaryFIle]: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile\n[types]: https://docs.python.org/3/library/types.html\n[types.ModuleType]: https://docs.python.org/3/library/types.html#types.ModuleType\n[types.FunctionType]: https://docs.python.org/3/library/types.html#types.FunctionType\n[types.SimpleNamespace]: https://docs.python.org/3/library/types.html#additional-utility-classes-and-functions\n[zipfile]: https://docs.python.org/3/library/zipfile.html\n[dicts]: https://docs.python.org/3/tutorial/datastructures.html#dictionaries\n",
"bugtrack_url": null,
"license": null,
"summary": "Python-CLU: Common Lightweight Utilities",
"version": "0.12.9",
"project_urls": {
"Download": "https://github.com/fish2000/clu/zipball/master",
"Homepage": "https://github.com/fish2000/clu",
"changelog": "https://github.com/fish2000/CLU/blob/master/CHANGELOG.md",
"documentation": "https://github.com/fish2000/CLU/blob/master/README.md",
"download": "https://pypi.org/project/python-clu/",
"homepage": "https://github.com/fish2000/CLU",
"repository": "https://github.com/fish2000/CLU",
"source": "https://github.com/fish2000/CLU",
"tracker": "https://github.com/fish2000/CLU/issues"
},
"split_keywords": [
"testing",
" command",
" command-line",
" utilities",
" modules",
" repl",
" tools"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "7369e2927e5c944ef9f800da45090072446b937376382305cb73e201a69a677a",
"md5": "2b25d0aafe54f6b6da3c964c5e970b7c",
"sha256": "c23b774663582c5e63460f03a9d0dd6f632f335c796c3dd799b01b5d32658b0b"
},
"downloads": -1,
"filename": "python_clu-0.12.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b25d0aafe54f6b6da3c964c5e970b7c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 299268,
"upload_time": "2025-05-24T23:04:57",
"upload_time_iso_8601": "2025-05-24T23:04:57.055315Z",
"url": "https://files.pythonhosted.org/packages/73/69/e2927e5c944ef9f800da45090072446b937376382305cb73e201a69a677a/python_clu-0.12.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c42d225ac8571cb0d95b5bfe1ce0d51751b9b1d0598cf531cd22dfa591bd171c",
"md5": "fd0bd3ea3ac118cd2eec38a6da9964b8",
"sha256": "e6345e0e7d46bc39d916fe9bcdd7ebca66972a3e2cf6436fb19876a56dee8d8c"
},
"downloads": -1,
"filename": "python_clu-0.12.9.tar.gz",
"has_sig": false,
"md5_digest": "fd0bd3ea3ac118cd2eec38a6da9964b8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15695475,
"upload_time": "2025-05-24T23:05:00",
"upload_time_iso_8601": "2025-05-24T23:05:00.918132Z",
"url": "https://files.pythonhosted.org/packages/c4/2d/225ac8571cb0d95b5bfe1ce0d51751b9b1d0598cf531cd22dfa591bd171c/python_clu-0.12.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-05-24 23:05:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fish2000",
"github_project": "clu",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"landscape": true,
"appveyor": true,
"tox": true,
"lcname": "python-clu"
}