Giter Club home page Giter Club logo

lib.py.configfile's People

Contributors

kynikos avatar lahwaacz avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lahwaacz

lib.py.configfile's Issues

Allow customizing regular expressions

Allow easily customizing the regular expressions that define the various elements of a configuration file.
For example allow changing the subsection separator, or allow trimming quotes around the value of an option.

Use a generic mapping class

Let the user define which mapping class should be used to store the configuration file data (dict, OrderedDict etc.). This would also simplify all the "ordered" and "ignore case" options, since e.g. to ignore the case it would be enough to make a mapping class that saves keys only with lowercase characters.

Change interpolation syntax

The current interpolation syntax is very flexible but probably unnecessarily complicated: the characters allowed in section and option names are already very limited by default, so only the interpolation start character could be introduced by a special character. Also, the configured section separator could be used to separate the sections in the path and the option name too. For example:

${section1.section2.option}
${.section1.section2.option}

In this case a leading . should mean a relative path.

${section1/section2/option}
${/section1/section2/option}

In this case a leading / should mean an absolute path.

Note that this change would create a backward incompatibility!

Edit: if using something like:

${section1.section2:option}
${section1/section2:option}

The option name shouldn't need to forbid the section separator, although section names should also forbid the :.

Interpolation of options from parent sections

I was thinking of this config:

site = ArchWiki
cache-dir = ~/.cache/wiki-scripts/

[ArchWiki]
api-url = https://wiki.archlinux.org/api.php
index-url = https://wiki.archlinux.org/index.php

[ArchWiki.statistics]
cookie-file = ${cache-dir$}/ArchWiki.bot.cookie

Unfortunately parsing this with interpolation=True (and inherit_options=True) fails with KeyError: 'cache-dir'...

(Btw. I had to add - to the Section._OPTION regex to support the above keys, which should be solved by #5, but is there a reason why it's not included by default?)

Fully replace configparser

Support all configparser features, so that this library can replace it (not drop-in though).
For example, optionally support inline comments.

Automatically comment new sections and options

When exporting, automatically introduce added sections and options with comments like "# {These options have|This section has} been added automatically".
Remember that the comment character must be customizable.

Support lists of values

By default, if a key is duplicated in a section, its value is assigned with the cascading rule.
Optionally, instead, interpret this as the definition of a list, with each duplicated key hosting an item:

option = aaa
option = bbb
option = ccc

Alternatively, support interpreting numbered suffixes as list items, for example:

option[1] = aaa
option[2] = bbb
option[3] = ccc

Or distinguish lists from normal keys with a special prefix:

*option = aaa
*option = bbb
*option = ccc

Support including other files

Allow including other configuration files with a special syntax, e.g. #include /etc/config.conf.
Prevend circular inclusions.

Improve exception classes

Improve the exception classes:

  • Compare them with configparser's.
  • Derive them from more specific classes than Exception.
  • Store more information than just the error message.

Allow using indentation

Allow indenting sections and options e.g. relatively to the parent section.
When updating an existing file, the current indentation should be preserved.

Automatic lookup for items in parent sections

I just wrote something like:

cf = configfile.ConfigFile(stream, inherit_options=True)
try:
    return cf(top_level)(subname).get_options()
except KeyError:
    try:
        return cf(top_level).get_options()
    except KeyError:
        return OrderedDict()

I'm dreading the day when I'll need to go one more level deep... At first I thought that inherit_options would allow me to write just return cf(top_level)(subname).get_options() with configfile handling the rest, but it seems that non-existent subsections just don't exist. Would it be safe to let Section.__call__() (optionally) return parent section if the requested one is not found? Is a config file with an only section [foo.bar.baz] even considered valid (i.e. how are the parents of baz handled)?

As an unrelated side note, could you add an example of value interpolation to the documentation? I'm having trouble understanding even the concept...

Add tests

Add automatic testing and remind to run them before releasing.

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.