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

Environment variables' reimports not supported #477

Open
shbshka opened this issue Jun 21, 2023 · 1 comment
Open

Environment variables' reimports not supported #477

shbshka opened this issue Jun 21, 2023 · 1 comment
Assignees
Labels
need reproducible example Example is required to reproduce the issue

Comments

@shbshka
Copy link

shbshka commented Jun 21, 2023

No matter how I write the environment.py file:

import environ
import pathlib

env = environ.Env(DEBUG=(bool, False))

current_dir = pathlib.Path(__file__).resolve().parent
env_file = pathlib.Path(current_dir, "./data/.env")
with open(env_file, 'r') as fd:
    environ.Env.read_env(env_file=fd)

TOKEN = env("TOKEN")
admin_chat = env("admin_chat")

or

import environ

env = environ.Env(DEBUG=(bool, False))
environ.Env.read_env(env_file='data/.env'))

TOKEN = env("TOKEN")
admin_chat = env("admin_chat")

I receive errors because of importing TOKEN and admin_chat to notify_admins.py and loader.py (from environment import X) and then running the script from main.py. The errors derive from having these values set to None, though running the files with imports separately and not from main is fine. Thus a stupid question: is django-environ only for django projects and cannot be adapted for other projects in any way?

My project's structure:

my_project
├──__pycache__
├── .spyproject
├──core
│  ├──__init__.py
│  ├──functions
│  │  └──__init__.py
│  │  └──notify_admins.py
│  └──handlers
│     └──__init__.py
│     └──start_message.py
├──data
│  └──.env
├──venv
├──environment.py
├──loader.py
└──main.py

Ready to provide the contents of other files if needed.

@sergeyklay
Copy link
Collaborator

Hello @shbshka,

Thank you for reporting this issue. I'm trying to understand the nature of the problem you're facing, but I could use a bit more information to reproduce it accurately.

Would you be able to provide a minimal code sample that reproduces the issue? Ideally, something that can be run in a clean virtual machine with only Python installed would be most helpful.

@sergeyklay sergeyklay self-assigned this Sep 8, 2023
@sergeyklay sergeyklay added the need reproducible example Example is required to reproduce the issue label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need reproducible example Example is required to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants