lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.44k stars 336 forks source link

Add providers to Generic dynamically. #238

Closed lk-geimfari closed 7 years ago

lk-geimfari commented 7 years ago

At this moment it should be done manually, which means that every time a new data provider appears, you must manually add it to Generic (), which is not convenient. I suggest add all providers from __all__ to Generic() automatically, but we need to save current API.

Any ideas?

Marlysson commented 7 years ago

Can you explain more details about that?

The data providers are this ?

And the manually add that you said are the method in add_provider in generic.py file?

Automatically that you say is load from data profile folder and run the add_provider soon after?

lk-geimfari commented 7 years ago

I mean this: https://github.com/lk-geimfari/mimesis/blob/master/mimesis/providers/generic.py#L13

lk-geimfari commented 7 years ago

It would be awesome to add new provider to generic automatically, i.e from __all__. Keep in mind that we use lazy initialization for providers which use locale.

Marlysson commented 7 years ago

Why some attributes have the underscore and other not?

lk-geimfari commented 7 years ago

Because some providers pull data from files when another not. if attribute start with underscore then it use file from data/locale/provider.json and we use lazy initialization for ones.

Marlysson commented 7 years ago

What you think about read the class in providers folder, and insert it in __all__ list, and the Generic class read this list and call __new__ from each element.

The problem would be detect when call lazy load or normal load.. The current _ at begin from attribute.