Coder Social home page Coder Social logo

upsilonconf's People

Contributors

hoedt avatar sphh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sphh

upsilonconf's Issues

Space/hyphen/period in keywords

Thanks for your wonderful upsilonconf!

I noticed, that it is neither possible to load a configuration file, where the keys have spaces or hyphens (periods simply adds a new level). This requires to convert all hyphens and spaces to underscores in the config file. This is not a very big problem, but often the files are more readable, if these characters are allowed in the keys.

I could think of the following approach how to tackle this drawback:

  • When loading a file, convert the space and hyphen to an underscore. This should be configurable with keyword arguments to the load(…, space='_', hyphen='_', period='_') function (with the three keyword parameters defaulting to None resulting in the current behaviour).
  • When saving, the same interface could be used: e.g. save(…, space='_') would replace underscores with spaces. If the load function uses different replacements for space/hyphen/period, it would be even possible to use something like save(…, space='__', hyphen='_'). Again the three keyword parameters would default to None resulting in the current behaviour.

What do you think? If you want, I could make a PR with these changes.

Support for lists in `to_dict`

Currently from_dict works to recursively go down through lists to get sub FrozenConfiguration objects. By example:

>>> conf = FrozenConfiguration.from_dict({"things": [    {"a": 0, "b": 1},     {"a": 2, "b": 3}, ]})
FrozenConfiguration(things=(FrozenConfiguration(a=0, b=1), FrozenConfiguration(a=2, b=3)))

>>> conf.to_dict()
{'things': (FrozenConfiguration(a=0, b=1), FrozenConfiguration(a=2, b=3))}

And then I cannot serialize this to e.g. YAML simply.

Only import `json` and `argparse`, if needed

In my case I use YAML files for configuration. Would it be possible to reorganize the code, so that neither json nor argparser are imported, if they are not used?

Since both modules are include in the standard Python, these imports should be ok. But they take time and use up memory, so it would be preferable to only import them, if needed!

saving to / reading from configurations in directories

I'm not sure what would be the best way to handle it when trying to save a configuration to a directory.
The main problem is that a user might have several goals when trying to read from/write to a directory:

  1. interact with a file that follows some form of standard in the directory (e.g. a file called "config.yaml"),
  2. interact with one/any (existing) file in the directory that has a valid configuration extension,
  3. interact with multiple/all (existing) files in the directory that have a valid configuration extension.

Each of these options requires choices to be made about the file type. Also, it is unclear what the name of a non-default config file should be if it does not yet exist.
I had the following ideas in mind, but I am not sure what would make more sense:

  1. Introduce a constant that represent a default filename:
    try:
        import yaml
        DEFAULT_FILENAME = "config.yaml"
    except ImportError:
        DEFAULT_FILENAME = "config.json"
    The main problem with this is that users might not like the defaults.
    It would be possible to overwrite the constant, but I don't think that this would be a nice solution
  2. Read all files of a particular type in the directory and use the filenames as keys in the resulting configuration:
    data = {file.stem: _load(file) for file in path.glob("*.yaml")}
    In order to get a symmetric writing operation, a configuration would only be allowed to have sub-configurations when trying to write to a directory.
    This might lead to frustration in some scenarios.
  3. Fail when trying to write to a directory (the current implementation).

I am probably missing a lot of things in my considerations, therefore I leave this here for more intelligent people to leave their thoughts.

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.