Giter Site home page Giter Site logo

os.environb suppport? about ecological HOT 3 CLOSED

abathur avatar abathur commented on August 23, 2024
os.environb suppport?

from ecological.

Comments (3)

marcinzaremba avatar marcinzaremba commented on August 23, 2024 2

That's a great idea. We can support both actually. If source is provided on class then it overrides the settings on Variable.
However in this case (when source would be os.environb) my thinking is it is undesirable to have it globally because it would be very painful for user to convert from bytes to str for example:

# Given that the transform func on Variable is the default cast
>>> from ecological import config
>>> config.cast(b'My value', str)
"b'My value'"

So suddenly all strings become screwed when you switch globally to os.environb and then you would new to explictly use Variable on each of them to do some other transform.

from ecological.

marcinzaremba avatar marcinzaremba commented on August 23, 2024

For me it sounds like really easy change that can be implemented in a very generic, useful way.

First introduce a concept of source on Variable class and pass it as the constructor parameter; the protocol here would be source is a dictionary that Variable reads values from where os.environ stays the default one. Then utilizing os.environb would be trivial from user POV:

class Configuration(ecological.AutoConfig):
    my_var1: str = ecological.Variable("my_var1", source=os.environb)

from ecological.

thilp avatar thilp commented on August 23, 2024

Would there be a way to also specify source as "class argument", just like prefix? (I think you would have all your values coming from the same dict much more often than from different dicts.)

from ecological.

Related Issues (15)

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.