pyvado 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyvado/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+
2
+ from .pyvado import Pyvado
3
+ from .pyvado_error import PyvadoError
4
+ from .pyvado_session import PyvadoSession
5
+ from .pyvado_process import PyvadoProcess
pyvado/pyvado.py ADDED
@@ -0,0 +1,149 @@
1
+ """
2
+ File name: pyvado
3
+ Author: aureliesa
4
+ Version: 1.0.0
5
+ License: GPL-3.0-or-later
6
+ Dependencies: pyvado_process, pyvado_session, pyvado_manager
7
+ Descriptions: Vivado Python API wrapper
8
+ """
9
+
10
+ from .pyvado_process import PyvadoProcess
11
+ from .pyvado_session import PyvadoSession
12
+ from .pyvado_manager import *
13
+ import os
14
+
15
+ class Pyvado:
16
+ """
17
+ Python vivado API wrapper
18
+
19
+ Attributes
20
+ ----------
21
+ session : PyvadoSession
22
+ pyvado session data structure
23
+ project : ProjectManager
24
+ pyvado project manager
25
+ flow : FlowManager
26
+ pyvado synthesis flow manager
27
+ files : FilesManager
28
+ project file manager
29
+ hardware : HardwareManager
30
+ vivado hardware manager
31
+ report : ReportManager
32
+ vivado report manager
33
+ simulator : SimulatorManager
34
+ vivado simulator
35
+ tcl : TCLManager
36
+ direct tcl command
37
+ """
38
+
39
+ def __init__(self,
40
+ project_path : str = "",
41
+ vivado_command : str = "vivado",
42
+ process_timeout : int = 600
43
+ ):
44
+ """
45
+ PyVado constructor
46
+
47
+ Parameters
48
+ ----------
49
+ project_path : str = ""
50
+ vivado project path
51
+ vivado_command : str = "vivado"
52
+ vivado command line
53
+ process_timeout : int = 600
54
+ vivado command timeout
55
+ """
56
+
57
+ if not os.path.exists(".pyvadoLog"):
58
+ os.makedirs(".pyvadoLog")
59
+
60
+
61
+
62
+
63
+ self.__session = PyvadoSession(
64
+ project_path = project_path,
65
+ vivado_command=vivado_command,
66
+ process_timeout=process_timeout
67
+ )
68
+
69
+ self.__project = ProjectManager(
70
+ pyvado_session = self.session
71
+ )
72
+
73
+ self.__flow = FlowManager(
74
+ pyvado_session = self.session
75
+ )
76
+
77
+ self.__files = FileManager(
78
+ pyvado_session = self.session
79
+ )
80
+
81
+ self.__hardware = HardwareManager(
82
+ pyvado_session = self.session
83
+ )
84
+
85
+ self.__report = ReportManager(
86
+ pyvado_session = self.session
87
+ )
88
+
89
+ self.__simulator = SimulationManager(
90
+ pyvado_session = self.session
91
+ )
92
+
93
+ self.__tcl = TCLManager(
94
+ pyvado_session = self.session
95
+ )
96
+
97
+ @property
98
+ def session(self) -> PyvadoSession:
99
+ return self.__session
100
+
101
+ @property
102
+ def project(self) -> ProjectManager:
103
+ return self.__project
104
+
105
+ @property
106
+ def flow(self) -> FlowManager:
107
+ return self.__flow
108
+
109
+ @property
110
+ def files(self) -> FileManager:
111
+ return self.__files
112
+
113
+ @property
114
+ def hardware(self) -> HardwareManager:
115
+ return self.__hardware
116
+
117
+ @property
118
+ def report(self) -> ReportManager:
119
+ return self.__report
120
+
121
+ @property
122
+ def simulator(self) -> SimulationManager:
123
+ return self.__simulator
124
+
125
+ @property
126
+ def tcl(self) -> TCLManager:
127
+ return self.__tcl
128
+
129
+ def __enter__(self):
130
+ return self
131
+
132
+ def __exit__(self, exc_type, exc, tb):
133
+
134
+ if self.__session.target.is_open():
135
+ self.hardware.close_target()
136
+
137
+ if self.__session.hw_server.is_open():
138
+ self.hardware.disconnect_server()
139
+
140
+ if self.__session.hardware.is_open():
141
+ self.hardware.close_hardware()
142
+
143
+ if self.__session.project.is_open():
144
+ self.project.close()
145
+
146
+ if self.__session.simulator.is_open():
147
+ self.simulator.close()
148
+
149
+ self.__session.process.close()
pyvado/pyvado_error.py ADDED
@@ -0,0 +1,23 @@
1
+ """
2
+ File name: pyvado_error
3
+ Author: aureliesa
4
+ Version: 1.0.0
5
+ License: GPL-3.0-or-later
6
+ Contact: aurelie.saulq@proton.me
7
+ Dependencies:
8
+ Descriptions: Pyvado error
9
+ """
10
+
11
+ class PyvadoError(Exception):
12
+ """
13
+ Pyvado internal error class
14
+
15
+ Attributes
16
+ ----------
17
+
18
+ Methods
19
+ -------
20
+ """
21
+
22
+ def __init__(self, message : str):
23
+ super().__init__(message)
@@ -0,0 +1,9 @@
1
+
2
+ from .project_manager import ProjectManager
3
+ from .pyvado_manager import PyvadoManager
4
+ from .flow_manager import FlowManager
5
+ from .file_manager import FileManager
6
+ from .hardware_manager import HardwareManager
7
+ from .report_manager import ReportManager
8
+ from .simulation_manager import SimulationManager
9
+ from .tcl_manager import TCLManager
@@ -0,0 +1,358 @@
1
+ """
2
+ File name: file_manager
3
+ Author: aureliesa
4
+ Version: 1.2.1
5
+ License: GPL-3.0-or-later
6
+ Dependencies: pyvado_process, pyvado_session, pyvado_manager, pyvado_error, pathlib, shlex
7
+ Descriptions: Pyvado synthesis flow manager
8
+ """
9
+
10
+ from .pyvado_manager import PyvadoManager
11
+ from ..pyvado_process import PyvadoProcess
12
+ from ..pyvado_session import PyvadoSession
13
+ from ..pyvado_error import PyvadoError
14
+ from pathlib import Path
15
+ import shlex
16
+
17
+ class FileManager(PyvadoManager):
18
+ """
19
+ File system manager
20
+
21
+ Attributes
22
+ ----------
23
+ SUPPORTED_FILE_EXTENSIONS : list[str] (static)
24
+ list of supported file extensions
25
+
26
+ Methods
27
+ -------
28
+ add_file(file_path : str | list[str], used_in_synth : bool = True, used_in_sim : bool = True, import_file : bool =False, force : bool =True)
29
+ Add file(s) on vivado project. Function detect if the file is a constraint file
30
+ change_property(file_path : str | list[str], used_in_synth : bool = True, used_in_sim : bool = True)
31
+ change file property
32
+ add_directory(directory_path : str, used_in_synth : bool = True, used_in_sim : bool = True, import_file : bool =False, force : bool =True)
33
+ Add all files in directory and subdirectory
34
+ add_simulation_file(self, file_path : str, import_file : bool = False, force : bool = True)
35
+ Add simulation only file
36
+ add_constraint_file(file_path : str, import_file : bool = False, force : bool = True)
37
+ Add constraint file
38
+ remove_file(file_name : str, delete_from_disk : bool = False)
39
+ remove file from vivado projectt
40
+ get_files(self) -> list[str]
41
+ get files in vivado project
42
+ """
43
+
44
+ SUPPORTED_FILE_EXTENSIONS = [
45
+ ".nky", ".nkz", ".dcp", ".vho", ".vhd",
46
+ ".vhdl", ".vhf", ".vhdp", ".sv", ".svp",
47
+ ".v", ".veo", ".svo", ".vf", ".verilog",
48
+ ".vr", ".vg", ".vb", ".tf", ".vlog",
49
+ ".vp", ".vm", ".sveo", ".veo", ".svo",
50
+ ".vh", ".h", ".svh", ".vhp", ".svhp",
51
+ ".edn", ".edf", ".edif", ".ngc", ".bnx",
52
+ ".bmm", ".mif", ".mem", ".bd", ".wcfg",
53
+ ".coe", ".sdc", ".xdc", ".tcl"
54
+ ]
55
+
56
+ def __init__(self,
57
+ pyvado_session : PyvadoSession
58
+ ):
59
+ """
60
+ Pyvado file manager
61
+
62
+ Parameters
63
+ ----------
64
+ vivado_process : PyvadoProcess
65
+ vivado process
66
+ pyvado_session : PyvadoSession
67
+ pyvado project session
68
+ """
69
+
70
+ super().__init__(
71
+ pyvado_session = pyvado_session
72
+ )
73
+
74
+ def add_file(self, file_path : str | list[str], used_in_synth : bool = True, used_in_sim : bool = True, import_file : bool =False, force : bool =True):
75
+ """
76
+ Add file(s) on vivado project. Function detect if the file is a constraint file
77
+
78
+ Parameters
79
+ ----------
80
+ file_path : str | [str]
81
+ path of file to add
82
+ used_in_synth : bool = Trie
83
+ the added file will be available for synthesis
84
+ used_in_sim : bool = True
85
+ the added file will be available for simulation
86
+ import_file : bool = False
87
+ the added file will be copy in the vivado project repo
88
+ force : bool = True+
89
+ force the file to be add if the file already exist
90
+
91
+ Errors
92
+ ------
93
+ ValueError
94
+ file must be available at least for synhtesis or simulation
95
+ PyvadoError
96
+ project is not open
97
+ """
98
+
99
+ if not used_in_synth and not used_in_sim:
100
+ raise ValueError("a file must be at least in simulation or synthesis")
101
+
102
+ if not self._pyvado_session.project.is_open():
103
+ raise PyvadoError("Project must be open to add files")
104
+
105
+ if not isinstance(file_path, list):
106
+ file_path = [file_path]
107
+
108
+ design_files = []
109
+ constrainst_files = []
110
+
111
+ file_path = [Path(f).resolve() for f in file_path]
112
+
113
+ for f in file_path:
114
+
115
+ if not f.suffix in self.SUPPORTED_FILE_EXTENSIONS:
116
+ raise PyvadoError(f"{f.suffix} extension is not supported")
117
+
118
+ if not f.exists():
119
+ raise PyvadoError(f"{f} does not exists")
120
+
121
+ if f.suffix == ".xdc" or f.suffix == ".sdc":
122
+ constrainst_files.append(f.as_posix())
123
+ else:
124
+ design_files.append(f.as_posix())
125
+
126
+ force = '-force' if force else ''
127
+ file = "import_files" if import_file else "add_files"
128
+
129
+ cmd = []
130
+
131
+ if design_files != []:
132
+ files = ' '.join(design_files)
133
+ cmd.append(f"{file} -norecurse {force} {files}")
134
+
135
+ if constrainst_files != []:
136
+ files = ' '.join(constrainst_files)
137
+ cmd.append(f"{file} -fileset constrs_1 -norecurse {force} {files}")
138
+
139
+
140
+ cmd.append("update_compile_order")
141
+
142
+
143
+ self._pyvado_session.process.send(
144
+ cmd = cmd
145
+ )
146
+
147
+ if design_files != []:
148
+ files = self.get_files()
149
+
150
+ file_name = [f.name for f in file_path]
151
+
152
+ new_files = ' '.join([f for f in files if Path(f).resolve().name in file_name and not Path(f).suffix in [".xdc", ".sdc"] ])
153
+
154
+ self._pyvado_session.process.send(cmd=[
155
+ f"set_property used_in_synthesis {used_in_synth} [get_files {{{new_files}}}]",
156
+ f"set_property used_in_simulation {used_in_sim} [get_files {{{new_files}}}]"
157
+ ])
158
+
159
+ def change_property(self, file_path : str | list[str], used_in_synth : bool = True, used_in_sim : bool = True):
160
+ """
161
+ change file property
162
+
163
+ Parameters
164
+ ----------
165
+ file_path : str | list[str]
166
+ file path
167
+ used_in_synth : bool = True
168
+ file will be available for synthesis
169
+ used_in_sim : bool = True
170
+ file will be available for simulation
171
+
172
+ Errors
173
+ ------
174
+ ValueError
175
+ file must be available at least for synhtesis or simulation
176
+ PyvadoError
177
+ project is not open
178
+ """
179
+
180
+ if not used_in_synth and not used_in_sim:
181
+ raise ValueError("a file must be at least in simulation or synthesis")
182
+
183
+ if not self._pyvado_session.project.is_open():
184
+ raise PyvadoError("Project must be open to add files")
185
+
186
+ files = self.get_files()
187
+
188
+ if not isinstance(file_path, list):
189
+ file_path = [file_path]
190
+
191
+ file_path = [Path(f).resolve() for f in file_path]
192
+
193
+ if any(f.suffix == ".xdc" for f in file_path):
194
+ return
195
+
196
+ for f in file_path:
197
+ if not f.as_posix() in files:
198
+ raise PyvadoError(f"{f} is not into the project")
199
+
200
+ files = ' '.join([f.as_posix() for f in file_path])
201
+
202
+ self._pyvado_session.process.send([
203
+ f"set_property used_in_synthesis {used_in_synth} [get_files {{{files}}}]",
204
+ f"set_property used_in_simulation {used_in_sim} [get_files {{{files}}}]"
205
+ ])
206
+
207
+ def add_directory(self, directory_path : str, used_in_synth : bool = True, used_in_sim : bool = True, import_file : bool =False, force : bool =True):
208
+ """
209
+ Add all files in directory and subdirectory
210
+
211
+ Parameters
212
+ ----------
213
+ directory_path : str
214
+ directoy path
215
+ used_in_synth : bool = True
216
+ files will be available for synthesis
217
+ used_in_sim : bool = Truee
218
+ files will be available for simulation
219
+ import_file : bool = False
220
+ files will be copy on loval project
221
+ force : bool = True
222
+ if files already exist, files will be replace
223
+
224
+ Errors
225
+ ------
226
+ ValueError
227
+ directory path deos not exist
228
+ ValueError
229
+ directory_path is not a directory
230
+ """
231
+
232
+ directory_path = Path(directory_path).resolve()
233
+
234
+ if not directory_path.exists():
235
+ raise ValueError(f"{directory_path} does not exist")
236
+
237
+ if not directory_path.is_dir():
238
+ raise ValueError(f"{directory_path} is not a directory")
239
+
240
+ files = sorted(f for f in directory_path.rglob("*") if f.is_file() and f.suffix in self.SUPPORTED_FILE_EXTENSIONS)
241
+
242
+ self.add_file(file_path=files, used_in_synth=used_in_synth, used_in_sim=used_in_sim, force=force, import_file=import_file)
243
+
244
+ def add_simulation_file(self, file_path : str, import_file : bool = False, force : bool = True):
245
+ """
246
+ Add simulation only file
247
+
248
+ Parameters
249
+ ----------
250
+ file_path : str
251
+ path of file to add
252
+ import_file : bool
253
+ the added file will be copy in the vivado project repo
254
+ force : bool
255
+ force the file to be add if the file already exist
256
+ """
257
+
258
+ self.add_file(
259
+ file_path=file_path,
260
+ used_in_synth=False,
261
+ used_in_sim=True,
262
+ import_file=import_file,
263
+ force=force
264
+ )
265
+
266
+ def add_constraint_file(self, file_path : str, import_file : bool = False, force : bool = True):
267
+ """
268
+ Add constraint file
269
+
270
+ Parameters
271
+ ----------
272
+ file_path : str
273
+ path of file to add
274
+ import_file : bool
275
+ the added file will be copy in the vivado project repo
276
+ force : bool
277
+ force the file to be add if the file already exist
278
+
279
+ Errors
280
+ ------
281
+ ValueError
282
+ extension must be .xdc or .sdc
283
+ """
284
+
285
+ sfx = Path(file_path).suffix
286
+ if sfx != ".xdc" and sfx != ".sdc":
287
+ raise ValueError(f"{sfx} constrainst file extension must be xdc or sdc")
288
+
289
+ self.add_file(
290
+ file_path=file_path,
291
+ used_in_sim=True,
292
+ used_in_synth=True,
293
+ import_file=import_file,
294
+ force=force
295
+ )
296
+
297
+ def remove_file(self, file_name : str, delete_from_disk : bool = False):
298
+ """
299
+ remove file from vivado project
300
+
301
+ Parameters
302
+ ----------
303
+ file_name : str
304
+ name of file to remove
305
+ delete_from_disk : bool = False
306
+ if file has been imported into the vivado project, set to true to delete this copy.
307
+
308
+ Errors
309
+ ------
310
+ PyvadoError
311
+ vivado project must be open
312
+ """
313
+
314
+ if not self._pyvado_session.project.is_open():
315
+ raise PyvadoError("Project must be open to add files")
316
+
317
+ cmd = [f"remove_files {file_name}"]
318
+
319
+ if delete_from_disk:
320
+ proj_source = f"{self._pyvado_session.project_name}.srcs/"
321
+ files = self.get_files()
322
+ for f in files:
323
+ if proj_source in str(f) and Path(f).name == Path(file_name).name:
324
+ cmd.append(f"file delete -force {f}")
325
+ break
326
+
327
+ cmd.append("update_compile_order")
328
+
329
+ self._pyvado_session.process.send(cmd=cmd)
330
+
331
+ def get_files(self) -> list[str]:
332
+ """
333
+ get files in vivado project
334
+
335
+ Returns
336
+ -------
337
+ list[str]
338
+ list of files
339
+
340
+ Errors
341
+ ------
342
+ PyvadoError
343
+ vivado project must be open
344
+ """
345
+
346
+ if not self._pyvado_session.project.is_open():
347
+ raise PyvadoError("Project must be open to add files")
348
+
349
+ self._pyvado_session.process.send("puts [get_files]")
350
+ files = self._pyvado_session.process.read()
351
+
352
+ if files is None:
353
+ return []
354
+
355
+ if "No files matched" in files:
356
+ return []
357
+
358
+ return shlex.split(files)