Skip to content

Commit

Permalink
fix: add /ext/ to sys.path for importing from local dirs #1179
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydw committed Sep 6, 2021
1 parent 7857167 commit 3e1ef7e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions grow/pods/pods.py
Expand Up @@ -71,9 +71,8 @@ def goodbye_pods():

class Pod(object):
"""Grow pod."""
# TODO(jeremydw): A handful of the properties of "pod" should be moved to the
# "podspec" class.
DEFAULT_EXTENSIONS_DIR_NAME = 'extensions'
INSTALLED_EXTENSIONS_DIR_PATH = 'extensions'
LOCAL_EXTENSIONS_DIR_PATH = 'ext'
FEATURE_UI = 'ui'
FEATURE_TRANSLATION_STATS = 'translation_stats'
FEATURE_OLD_SLUGIFY = 'legacy_slugify'
Expand Down Expand Up @@ -109,9 +108,14 @@ def __init__(self, root, storage=grow_storage.AUTO, env=None, load_extensions=Tr

if self.exists:
# Modify sys.path for built-in extension support.
_ext_dir = self.abs_path(self.extensions_dir)
if os.path.exists(_ext_dir):
sys.path.insert(0, _ext_dir)
_installed_ext_dir = self.abs_path(self.extensions_dir)
if os.path.exists(_installed_ext_dir):
sys.path.insert(0, _installed_ext_dir)

# Modify sys.path for local extension support.
_local_ext_dir = self.abs_path(Pod.LOCAL_EXTENSIONS_DIR_PATH)
if os.path.exists(_local_ext_dir):
sys.path.insert(0, _local_ext_dir)

# Load the features from the podspec.
self._load_features()
Expand Down Expand Up @@ -408,7 +412,7 @@ def translation_stats(self):

@property
def extensions_dir(self):
return self.yaml.get('extensions_dir', Pod.DEFAULT_EXTENSIONS_DIR_NAME)
return self.yaml.get('extensions_dir', Pod.INSTALLED_EXTENSIONS_DIR_PATH)

@property
def ui(self):
Expand Down

0 comments on commit 3e1ef7e

Please sign in to comment.