From 3eb8dff36cb20d35c8ba68976ced751a8224992c Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 23 Nov 2021 14:18:19 +0100 Subject: [PATCH] Improve monorepo discovery Protect against parent directories containing Unreal Engine source code without the current directory being part of a monorepo setup. --- nimp/environment.py | 4 ++-- nimp/unreal.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nimp/environment.py b/nimp/environment.py index 943e7d06..3a086c25 100644 --- a/nimp/environment.py +++ b/nimp/environment.py @@ -382,9 +382,9 @@ def validate_uproject(self, urpoject): def display_unreal_info(self): '''display engine and selected uproject info''' if hasattr(self, 'unreal_full_version') and hasattr(self, 'unreal_dir'): - logging.info(f'Found Unreal engine {self.unreal_full_version} in {self.unreal_dir}') + logging.info(f'Found Unreal Engine {self.unreal_full_version} in {self.unreal_dir}') else: - logging.info('No Unreal engine loaded') + logging.info('No Unreal Engine found') if hasattr(self, 'uproject') and hasattr(self, 'uproject_dir'): logging.info(f'Found Unreal project {self.uproject} in {self.uproject_dir}') else: diff --git a/nimp/unreal.py b/nimp/unreal.py index 6ba06f00..c460ac4f 100644 --- a/nimp/unreal.py +++ b/nimp/unreal.py @@ -48,13 +48,17 @@ def load_config(env): unreal_base_paths = [ 'UE', 'UE4', - '', + '.', ] - for unreal_path in unreal_base_paths: - unreal_dir = nimp.system.find_dir_containing_file(os.path.join(unreal_path, unreal_file)) - if unreal_dir: - unreal_dir = os.path.join(unreal_dir, unreal_path) - break + for base in unreal_base_paths: + path_to_base = nimp.system.find_dir_containing_file(os.path.join(base, unreal_file)) + if not path_to_base: + continue + # Sanity check: if `base` indicates a monorepo setup, check that it is really one + if base != '.' and not os.path.isfile(os.path.join(path_to_base, '.nimp/monorepo_commands/__init__.py')): + continue + unreal_dir = os.path.join(path_to_base, base) + break if not unreal_dir: env.is_unreal = env.is_ue4 = env.is_ue5 = False