Skip to content

Commit ba21b04

Browse files
committed
Support JlcParts dir from environment variable
1 parent daba000 commit ba21b04

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

edg/jlcparts/JlcPartsBase.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 configure_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

Comments
 (0)