@@ -95,7 +95,7 @@ def config_root_dir(root_dir: str):
9595 CapacitorsMultilayer_Ceramic_Capacitors_MLCC___SMDakaSMT.json.gz
9696 This setting is on a JlcPartsBase-wide basis."""
9797 assert JlcPartsBase ._config_parts_root_dir is None , \
98- f"attempted to reassign config_root_dir , was { JlcPartsBase ._config_parts_root_dir } , new { root_dir } "
98+ f"attempted to reassign configure_root_dir , was { JlcPartsBase ._config_parts_root_dir } , new { root_dir } "
9999 JlcPartsBase ._config_parts_root_dir = root_dir
100100
101101 _JLC_PARTS_FILE_NAMES : ClassVar [List [str ]] # set by subclass
@@ -118,14 +118,19 @@ def _entry_to_table_row(cls, row_dict: Dict[PartsTableColumn, Any], filename: st
118118 @classmethod
119119 def _parse_table (cls ) -> PartsTable :
120120 """Parses the file to a PartsTable"""
121- assert cls ._config_parts_root_dir is not None , "must config_root_dir with jlcparts data folder"
121+ jlcparts_dir = os .environ .get ("JLCPARTS_DIR" )
122+ if jlcparts_dir is None :
123+ jlcparts_dir = cls ._config_parts_root_dir
124+ assert jlcparts_dir is not None , "no jlcparts data directory specified, either " \
125+ "set JLCPARTS_DIR environment variable or call JlcPartsBase.config_root_dir " \
126+ "with jlcparts data folder"
122127
123128 rows : List [PartsTableRow ] = []
124129
125130 for filename in cls ._JLC_PARTS_FILE_NAMES :
126- with gzip .open (os .path .join (cls . _config_parts_root_dir , filename + kTableFilenamePostfix ), 'r' ) as f :
131+ with gzip .open (os .path .join (jlcparts_dir , filename + kTableFilenamePostfix ), 'r' ) as f :
127132 data = JlcPartsFile .model_validate_json (f .read ())
128- with open (os .path .join (cls . _config_parts_root_dir , filename + kStockFilenamePostfix ), 'r' ) as f :
133+ with open (os .path .join (jlcparts_dir , filename + kStockFilenamePostfix ), 'r' ) as f :
129134 stocking = JlcPartsStockFile .model_validate_json (f .read ())
130135
131136 lcsc_index = data .jlcpart_schema .index ("lcsc" )
0 commit comments