From 9540b2bdb4f3d65fa2b032b7d5d41db35e7e0bde Mon Sep 17 00:00:00 2001 From: sunaley Date: Fri, 25 Jun 2021 12:20:36 +0800 Subject: [PATCH 1/7] Set BASE_DIR to sys path also --- src/dotenv/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index b85836a5..3b0a6043 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -97,6 +97,9 @@ def set_as_environment_variables(self): continue if v is not None: os.environ[to_env(k)] = to_env(v) + if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: + logger.info('Append BASE_DIR to path.') + sys.path.append(to_env(v)) return True From c5b9f2ab6688db7ece91ff175773949c84658aef Mon Sep 17 00:00:00 2001 From: sunaley Date: Fri, 25 Jun 2021 17:23:46 +0800 Subject: [PATCH 2/7] Update README.md for adding BASE_DIR to sys.path --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9757e672..b92143c0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # python-dotenv +This fork is written by Cloudybay Info Co. +Implement method `set_as_environment_variables` of `DotEnv()` to add django's BASE_DIR to sys.path for more convenience. + +--- + [![Build Status][build_status_badge]][build_status_link] [![PyPI version][pypi_badge]][pypi_link] From da77001f0be17d24aac9e599a5c1b5c9a02c1213 Mon Sep 17 00:00:00 2001 From: sunaley Date: Tue, 6 Jul 2021 23:08:13 +0800 Subject: [PATCH 3/7] Add BASE_DIR to sys.path whether in os.environ --- src/dotenv/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index 3b0a6043..ecb324af 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -93,13 +93,13 @@ def set_as_environment_variables(self): Load the current dotenv as system environment variable. """ for k, v in self.dict().items(): + if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: + logger.info('Append BASE_DIR to path.') + sys.path.append(to_env(v)) if k in os.environ and not self.override: continue if v is not None: os.environ[to_env(k)] = to_env(v) - if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: - logger.info('Append BASE_DIR to path.') - sys.path.append(to_env(v)) return True From 94e40590294d07d5b0af74d988f86e034c39b81b Mon Sep 17 00:00:00 2001 From: sunaley Date: Fri, 25 Jun 2021 12:20:36 +0800 Subject: [PATCH 4/7] Set BASE_DIR to sys path also --- src/dotenv/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index b6de171c..fc33267f 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -107,7 +107,10 @@ def set_as_environment_variables(self) -> bool: if k in os.environ and not self.override: continue if v is not None: - os.environ[k] = v + os.environ[to_env(k)] = to_env(v) + if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: + logger.info('Append BASE_DIR to path.') + sys.path.append(to_env(v)) return True From e62d26f970229c4e80a4c24a7b5b2d59654f6ffa Mon Sep 17 00:00:00 2001 From: sunaley Date: Fri, 25 Jun 2021 17:23:46 +0800 Subject: [PATCH 5/7] Update README.md for adding BASE_DIR to sys.path --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7594086b..e67f527d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # python-dotenv +This fork is written by Cloudybay Info Co. +Implement method `set_as_environment_variables` of `DotEnv()` to add django's BASE_DIR to sys.path for more convenience. + +--- + [![Build Status][build_status_badge]][build_status_link] [![PyPI version][pypi_badge]][pypi_link] From de5955aa3603fd7767afe88ba765ce6972ab7e39 Mon Sep 17 00:00:00 2001 From: sunaley Date: Tue, 6 Jul 2021 23:08:13 +0800 Subject: [PATCH 6/7] Add BASE_DIR to sys.path whether in os.environ --- src/dotenv/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index fc33267f..a5789264 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -104,13 +104,13 @@ def set_as_environment_variables(self) -> bool: return False for k, v in self.dict().items(): + if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: + logger.info('Append BASE_DIR to path.') + sys.path.append(to_env(v)) if k in os.environ and not self.override: continue if v is not None: os.environ[to_env(k)] = to_env(v) - if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: - logger.info('Append BASE_DIR to path.') - sys.path.append(to_env(v)) return True From 4828d30102932066ca0149268d745808fdfbaa90 Mon Sep 17 00:00:00 2001 From: him0116 Date: Fri, 19 Sep 2025 11:19:57 +0800 Subject: [PATCH 7/7] Refactor BASE_DIR handling to directly append to sys.path and update environment variables --- src/dotenv/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index a5789264..c3775af1 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -104,13 +104,13 @@ def set_as_environment_variables(self) -> bool: return False for k, v in self.dict().items(): - if to_env(k) == 'BASE_DIR' and to_env(v) not in sys.path: + if k == 'BASE_DIR' and v not in sys.path: logger.info('Append BASE_DIR to path.') - sys.path.append(to_env(v)) + sys.path.append(v) if k in os.environ and not self.override: continue if v is not None: - os.environ[to_env(k)] = to_env(v) + os.environ[k] = v return True