@@ -753,12 +753,42 @@ def get_codebase_config_directory(self):
753753
754754 def get_input_config_file (self ):
755755 """
756- Return the ``scancode-config.yml`` file from the input/ directory if
757- available.
758- """
759- config_file = self .input_path / settings .SCANCODEIO_CONFIG_FILE
760- if config_file .exists ():
761- return config_file
756+ Return the ``scancode-config.yml`` file from the input/ directory
757+ or from the codebase/ immediate subdirectories.
758+
759+ Priority order:
760+ 1. If a config file exists directly in the input/ directory, return it.
761+ 2. If exactly one config file exists in a codebase/ immediate subdirectory,
762+ return it.
763+ 3. If multiple config files are found in subdirectories, report an error.
764+ """
765+ config_filename = settings .SCANCODEIO_CONFIG_FILE
766+
767+ # Check for the config file in the root of the input/ directory.
768+ root_config_file = self .input_path / config_filename
769+ if root_config_file .exists ():
770+ return root_config_file
771+
772+ # Search for config files in immediate codebase/ subdirectories.
773+ subdir_config_files = list (self .codebase_path .glob (f"*/{ config_filename } " ))
774+
775+ # If exactly one config file is found in codebase/ subdirectories, return it.
776+ if len (subdir_config_files ) == 1 :
777+ return subdir_config_files [0 ]
778+
779+ # If multiple config files are found, report an error.
780+ if len (subdir_config_files ) > 1 :
781+ self .add_warning (
782+ f"More than one { config_filename } found. "
783+ f"Could not determine which one to use." ,
784+ model = "Project" ,
785+ details = {
786+ "resources" : [
787+ str (path .relative_to (self .work_path ))
788+ for path in subdir_config_files
789+ ]
790+ },
791+ )
762792
763793 def get_settings_as_yml (self ):
764794 """Return the ``settings`` file content as yml, suitable for a config file."""
@@ -774,17 +804,23 @@ def get_enabled_settings(self):
774804
775805 def get_env (self , field_name = None ):
776806 """
777- Return the project environment loaded from the ``. scancode/ config.yml`` config
778- file, when available, and overriden by the ``settings`` model field.
807+ Return the project environment loaded from the ``scancode- config.yml`` config
808+ file, when available, and overridden by the ``settings`` model field.
779809
780810 ``field_name`` can be provided to get a single entry from the env.
781811 """
782812 env = {}
783813
784814 # 1. Load settings from config file when available.
785815 if config_file := self .get_input_config_file ():
786- with suppress (saneyaml .YAMLError ):
816+ logger .info (f"Loading env from { config_file .relative_to (self .work_path )} " )
817+ try :
787818 env = saneyaml .load (config_file .read_text ())
819+ except saneyaml .YAMLError :
820+ self .add_error (
821+ f'Failed to load configuration from "{ config_file } ". '
822+ f"The file format is invalid."
823+ )
788824
789825 # 2. Update with defined values from the Project ``settings`` field.
790826 env .update (self .get_enabled_settings ())
0 commit comments