GithubHelp home page GithubHelp logo

ethanrowe / python-mandrel Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 7.0 72 KB

Mandrel provides bootstrapping and configuration tools for consistent, straightforward project config management.

License: MIT License

Python 100.00%

python-mandrel's People

Contributors

ethanrowe avatar willdrew avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-mandrel's Issues

Mandrel root can be specified via environment variable

Mandrel, by design, is heavy handed in its expectations when you invoke its bootstrap machinery.

However, there are cases where it's nice if you don't have that heavy-handedness, and could instead just tell it where the project root lives.

So let's impose an environment variable: MANDREL_ROOT.

If given, then bootstrapping should automatically treat that as the root.
In so doing, it should process a Mandrel.py file if one exists in the specified root.
If no such file exists, that should not cause an error; the default search path and defautl logging behavior should all work fine.

Python 3 support

I'd like to port treehouse, which uses Mandrel, to python 3, but ran into problems because Mandrel isn't python 3 compatible.

Default logging is sub-awesome

The default logger configuration has some annoyances:

  • Too verbose -- use INFO level instead of DEBUG
  • Awful format -- Use a saner format that is less miserable

In particular, get an ISO timestamp of the %Y-%m-%dT%H:%M:%SZ variety, so it's sortable and less than hideous.

Including the pid as well would be nice.

Use a less awful delimiter so the log entries are more readable, too.

bootstrap basename can be specified via environment variable

This is an odd use case, but if you're trying to import mandrel on a virtual machine with your current working directory being a mapped volume from OSX, it fails because OSX is a case-insensitive filesystem. When python is attempting to load the bootstrap module, it finds Mandrel.py in my current working directory (/mnt/hgfs/atebbe1/Documents/code/thingy/) and seems to load that instead of the installed package.

In this case, I am running mandrel-runner from a directory that contains a Mandrel.py bootstrap file

Traceback (most recent call last):
  File "/home/adam/virtualenv/bin/mandrel-runner", line 9, in <module>
    load_entry_point('mandrel==0.2.0', 'console_scripts', 'mandrel-runner')()
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 558, in load_entry_point
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2682, in load_entry_point
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2355, in load
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2361, in resolve
  File "/mnt/hgfs/atebbe1/Documents/code/thingy/mandrel.py", line 1, in <module>
    bootstrap.SEARCH_PATHS.append("/etc/conf")
NameError: name 'bootstrap' is not defined

To get around this, I would propose not naming the bootstrap file Mandrel.py, and adding support for an environment variable to override mandrel.bootstrap.__BOOTSTRAP_BASENAME

Configuration class can use structured environment variables

Mandrel should offer a configuration class variant that expects to get its attributes from environment variables.

There are a number of ways one could go about this. Certainly would could provide functionality to reduce environment variables down to a basic native (nested) dictionary, which could be used as the initial dict for a Configuration instance. However, it would probably be more idiomatic if the thing were a configuration class in its own right, which all other configuration extensions could use just by chaining.

The point is we want to be able to say things like:

  • this variable is this attribute, and it should be an integer
  • this variable is this attribute, and it should be a comma-separated list of strings
  • variables with this prefix are a nested dict (which is a complicated case)

And so on.

This requires some thought.

Provide dynamic loader utility class and configuration property helper

In some uses, you want to be able to, in configuration, say a setting widget: foo means that you want an auto-loaded, auto-configured app.widgets.foo_widget.Widget instance or whatever, and simply changing "foo" should change the widget module accessed or whatever.

This is useful as a general utility object (a loader that provides the plugin naming scheme and post-import callback invoker), and as a property helper function on the Configuration class.

Provide runner scripts that give some control over bootstrapping

Purpose

Mandrel should provide runner utilities that allow the execution of arbitrary code/scripts but give an initial pass at bootstrap configuration.

These runners would let us do things like customize the configuration search path, or specify the logging configuration file, as highest-priority command-line options, and would overrule or extend whatever took place in the usual bootstrap file.

Approach

Have two runners:

  • mandrel-runner should allow execution of an arbitrary callable specified by fully-qualified name.
  • mandrel-script should allow execution of an arbitrary python script, specified by path.

In each case, the first step should be to parse mandrel-specific options to allow:

  • full setting of search path
  • setting of logging configuration path
  • prepend to search path
  • append to search path

Each runner would bootstrap, then apply the changes implicit in the options. The name of the thing to run, in both cases, should be the first positional parameter (and is required). All other items on sys.argv can be passed along to the thing that is run in a manner idiomatic to the type of thing being run:

  • for the callable, the remaining items should simply be handed as a list to the callable as its first (and only) positional parameter)
  • for the script, the script name should be set as sys.argv[0] and the remaining items to sys.argv[1:].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.