Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do you use autocomplete with dynaconf? #298

Open
Markxy opened this issue Feb 18, 2020 · 9 comments · Fixed by #339
Open

Question: How do you use autocomplete with dynaconf? #298

Markxy opened this issue Feb 18, 2020 · 9 comments · Fixed by #339
Labels
Milestone

Comments

@Markxy
Copy link

Markxy commented Feb 18, 2020

Hello!
First of all, great project, love the feel, idea and execution!

To the question-
How do you use autocomplete with IDEs (PyCharm in my case) when using dynaconf?
from dynaconf import settings gets its attributes on execution and I get that, but it takes away so much with it.. The autocomplete plus the IDE not being able to tell if there's a variable like that at all.

Or am I just missing something?

Because I already had a (quite long) settings.py file before introducing dynaconf and I wanted just to take out some vars and tuck them into separate files, I just set their values as:
VAR_1 = dynaconf_settings.VAR_1

rochacbruno added a commit that referenced this issue May 12, 2020
implemented `__dir__` on Settings and Dynabox
rochacbruno added a commit that referenced this issue May 12, 2020
implemented `__dir__` on Settings and Dynabox
@rochacbruno
Copy link
Member

resolved @Markxy still pending release

@Markxy
Copy link
Author

Markxy commented May 12, 2020

awesome, @rochacbruno 👍

rochacbruno added a commit that referenced this issue Jun 22, 2020
Shortlog of commits since last release:

    Bernardo Gomes (2):
          Adding f string (#319)
          Added little information about how dev into this project. (#321)

    Bruno Rocha (18):
          Release version 3.0.0rc1
          Better exception handling on env_loader (#316)
          Add support for config aliases (#332)
          Add ENVLESS_MODE (#337)
          Fix #272 allow access of lowercase keys (#338)
          Fix #298 allow auto complete for editors and console (#339)
          Vendoring dependencies Fix #301 (#345)
          Clean tox installation for local testing (#346)
          Validator improvements on conditions (#353)
          Add note about quoting in env vars (#347)
          DEPRECATED global settings object.
          DEPRECATED global settings object. (#356)
          Lowecase read allowed by default (#357)
          Merge branch 'master' of github.com:rochacbruno/dynaconf
          envless by default - breaking change ⚠️ (#358)
          dotenv is no more loaded by default (#360)
          No more loading of `settings.*` by default (#361)
          NO more logger and debug messages (#362)

    Douglas Maciel d'Auriol Souza (1):
          Insert news validator conditions: (len_eq, len_ne, len_min, len_max, contd) (#328)

    Jeff Wayne (1):
          s/DYNACONF_ENV/ENV_FOR_DYNACONF (#335)

    Marcos Benevides (1):
          Fix minor typo in Flask extension docs (#318)

    Nicholas Nadeau, Ph.D., P.Eng (1):
          Fixed comma typo (#334)

    sfunkhouser (1):
          Add option to override default mount_point for vault (#349)
@ynouri
Copy link

ynouri commented Apr 5, 2021

Hi! My team is looking to adopt a new configuration framework and DynaConf looks really good. One of our goals is to maximize productivity, for example through code completion available in the IDE (e.g. PyCharm or VS Code).

settings.toml:

[foo]
bar = 1

my_app.py

from config import settings

# When I type "settings.", IDE should suggest "foo"
settings.foo.bar

I was initially thinking that this issue was about to enable this behavior, but after testing with dynaconf==3.1.4 and PyCharm 2020.3.5, I realized that I might have misinterpreted the scope of this specific feature. I can see that the foo is present at execution, but is there anyway to make it appear in IDE's autocompletions at coding time?

Thanks!

@rochacbruno rochacbruno reopened this Apr 6, 2021
@rochacbruno rochacbruno added this to the 3.2.0 milestone Apr 6, 2021
@rochacbruno rochacbruno modified the milestones: 3.2.0, 4.0.0 Mar 31, 2022
@timovanasten
Copy link

Would very much like the IDE to autocomplete the settings as well! Would be a big boost to productivity

@efesurekli
Copy link

+1 for the IDE autocomplete

@SonGokussj4
Copy link

Hi. This would be extremely helpful. I did a workaround with arg parser

# settings.yaml
app:
  models_dir: models
  skip_download: true
# main.py
...
# Dynaconf
from config import settings

parser = argparse.ArgumentParser()
parser.add_argument('-m', '--models-dir', dest="models_dir", action="store", default=settings.app.models_dir)
parser.add_argument('-sd', '--skip-download', dest='skip_download', action="store_true", default=settings.app.skip_download)

@dataclass
class MyAppArgs:
    models_dir: str
    skip_download: bool

args = MyAppArgs(**vars(parser.parse_args()))

# Then VSCode autocompletes
skip_downloads = args.sk|  --> skip_downloads

It would be most pleasant to have it in dynaconf too. Without a workaround.

settings.a|  --> app

It there some kind of ETA?

@rochacbruno
Copy link
Member

The work is being done on #683

@ferreirajoaouerj
Copy link

I'm using a derived singleton class. I write the config parameters as class attributes so the IDE can auto-complete. Of course, this also means that you should keep the environment variables / settings file in sync with those attributes.

class Singleton(type):
    def __init__(cls, name, bases, mmbs):
        super(Singleton, cls).__init__(name, bases, mmbs)
        cls._instance = super(Singleton, cls).__call__()

    def __call__(cls, *args, **kw):
        return cls._instance


class Settings(Dynaconf, metaclass=Singleton):
    name: str
    age: int
    not_in_env_or_settings: str

    def __init__(self):
        print('Initializing project config...')
        super().__init__(
            envvar_prefix="PROJECT",
            settings_files="settings.yaml",
            environments=True,
            env_switcher="PROJECT_ENV",
        )
        
os.environ['PROJECT_NAME'] = 'my_name'
os.environ['PROJECT_AGE'] = '30'

settings = Settings()

print(settings.name)  # 'my_name'
print(settings.age)  # 30
print(settings.not_in_env_or_settings)  # AttributeError: 'Settings' object has no attribute 'NOT_IN_ENV_OR_SETTINGS'

@rochacbruno
Copy link
Member

@ferreirajoaouerj we are planning to implement something similar to your example, but using Pydantic as the base model see #1045

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants