99BLOCK_DIRECTORY = 'modules'
1010
1111OPTIONAL_FILES = {
12- 'FaceDetector' : 'utils/models/haar_cascade/*' ,
13- 'ObjectDetector' : 'utils/models/yolov3/*'
12+ 'FaceDetector' : 'utils/models/haar_cascade/**/*' ,
13+ 'ObjectDetector' : 'utils/models/yolov3/**/*'
14+ }
15+
16+ BLOCK_DEPENDENCIES = {
17+ 'FaceDetector' : ['opencv-python' , 'numpy' ],
18+ 'ObjectDetector' : ['opencv-python' , 'numpy' ],
19+ 'ContourDetector' : ['opencv-python' , 'numpy' ],
20+ 'Cropper' : ['opencv-python' , 'numpy' ],
21+ 'ColorFilter' : ['opencv-python' , 'numpy' ],
22+ 'Blur' : ['opencv-python' , 'numpy' ],
23+ 'Dilation' : ['opencv-python' , 'numpy' ],
24+ 'EdgeDetector' : ['opencv-python' , 'numpy' ],
25+ 'Erosion' : ['opencv-python' , 'numpy' ],
26+ 'Threshold' : ['opencv-python' , 'numpy' ],
27+ 'VideoStreamer' : ['opencv-python' , 'numpy' ],
28+ 'ImageRead' : ['opencv-python' , 'numpy' ]
1429}
1530
1631PROJECT_FILE_EXTENSION = '.vc3'
@@ -34,6 +49,7 @@ def syntheize_modules(data: dict, zipfile: InMemoryZip) -> Tuple[InMemoryZip, Di
3449 parameters = {}
3550 synhronize_frequency = {}
3651 optional_files = {}
52+ project_dependencies = set ()
3753 wire_comp = data ['design' ]['graph' ]['wires' ] # Retrieve all wire connections from the design graph
3854 dep_no = {} # Dictionary to store the number of blocks of each type
3955
@@ -61,6 +77,9 @@ def process_dependency(dep, zipfile, synhronize_frequency, optional_files, dep_n
6177 if script_name in optional_files :
6278 optional_files [script_name ] = True # Mark the script as required in optional files
6379
80+ if script_name in BLOCK_DEPENDENCIES :
81+ project_dependencies .update (BLOCK_DEPENDENCIES [script_name ])
82+
6483 script_name += dependency ['package' ]['version' ].replace ('.' , '' ) # Append version number to the script name, removing dots
6584
6685 # Increment the count for this script type or initialize it
@@ -303,7 +322,7 @@ def process_wires(valid_wires):
303322 zipfile .append ('data.json' , json .dumps (data )) # Append the JSON data to the zipfile
304323
305324
306- return zipfile , optional_files
325+ return zipfile , optional_files , project_dependencies
307326
308327def synthesize_executioner (zipfile : InMemoryZip , optional_files : Dict [str , bool ]) -> InMemoryZip :
309328 '''Synthesize python code necessary to run the blocks.
@@ -338,9 +357,13 @@ def synthesize(data: dict) -> Tuple[str, BytesIO]:
338357 '''
339358 zipfile = InMemoryZip ()
340359 # Optional files required based on blocks present.
341- zipfile , optional_files = syntheize_modules (data , zipfile )
360+ zipfile , optional_files , project_dependencies = syntheize_modules (data , zipfile )
342361 zipfile = synthesize_executioner (zipfile , optional_files )
343362 zipfile = syntesize_extras (zipfile )
363+
364+ if project_dependencies :
365+ requirements_content = "\n " .join (project_dependencies ) + "\n "
366+ zipfile .append ('requirements.txt' , requirements_content )
344367
345368 # Project name (zipfile name)
346369 project_name = f"{ data ['package' ]['name' ]} " if data ['package' ]['name' ] != '' else 'Project'
0 commit comments