@@ -27,6 +27,9 @@ pub struct ProjectMetadata {
2727 /// The raw options
2828 pub ( super ) options : Options ,
2929
30+ /// Config file to override any discovered configuration
31+ pub ( super ) config_file_override : Option < SystemPathBuf > ,
32+
3033 /// Paths of configurations other than the project's configuration that were combined into [`Self::options`].
3134 ///
3235 /// This field stores the paths of the configuration files, mainly for
@@ -45,9 +48,28 @@ impl ProjectMetadata {
4548 root,
4649 extra_configuration_paths : Vec :: default ( ) ,
4750 options : Options :: default ( ) ,
51+ config_file_override : None ,
4852 }
4953 }
5054
55+ pub fn from_config_file (
56+ path : SystemPathBuf ,
57+ root : SystemPathBuf ,
58+ system : & dyn System ,
59+ ) -> Result < Self , ConfigurationFileError > {
60+ tracing:: debug!( "Using overridden configuration file at '{path}'" ) ;
61+
62+ let config_file = ConfigurationFile :: from_path ( path. clone ( ) , system) ?;
63+ let options = config_file. into_options ( ) ;
64+ Ok ( Self {
65+ name : Name :: new ( root. file_name ( ) . unwrap_or ( "root" ) ) ,
66+ root,
67+ options,
68+ extra_configuration_paths : Vec :: new ( ) ,
69+ config_file_override : Some ( path) ,
70+ } )
71+ }
72+
5173 /// Loads a project from a `pyproject.toml` file.
5274 pub ( crate ) fn from_pyproject (
5375 pyproject : PyProject ,
@@ -92,6 +114,7 @@ impl ProjectMetadata {
92114 root,
93115 options,
94116 extra_configuration_paths : Vec :: new ( ) ,
117+ config_file_override : None ,
95118 } )
96119 }
97120
0 commit comments