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

Add clean fix for WindowsPath type when calling read_env() method #287

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import warnings
import urllib.parse as urlparselib

from pathlib import WindowsPath

from urllib.parse import urlparse, urlunparse, ParseResult, parse_qs, unquote_plus

from .compat import json, DJANGO_POSTGRES, REDIS_DRIVER, ImproperlyConfigured
Expand Down Expand Up @@ -81,7 +83,7 @@ class Env:
'ldap': 'ldapdb.backends.ldap',
}
_DB_BASE_OPTIONS = ['CONN_MAX_AGE', 'ATOMIC_REQUESTS', 'AUTOCOMMIT', 'DISABLE_SERVER_SIDE_CURSORS']

DEFAULT_CACHE_ENV = 'CACHE_URL'
CACHE_SCHEMES = {
'dbcache': 'django.core.cache.backends.db.DatabaseCache',
Expand Down Expand Up @@ -128,7 +130,7 @@ def __call__(self, var, cast=None, default=NOTSET, parse_default=False):

def __contains__(self, var):
return var in self.ENVIRON

# Shortcuts

def str(self, var, default=NOTSET, multiline=False):
Expand Down Expand Up @@ -644,7 +646,8 @@ def read_env(cls, env_file=None, **overrides):
return

try:
with open(env_file) if isinstance(env_file, str) else env_file as f:
with (open(env_file) if isinstance(env_file, str) else
open(env_file.__str__()) if isinstance(env_file, WindowsPath) else env_file) as f:
content = f.read()
except OSError:
warnings.warn(
Expand Down