cutcutcodec 1.0.post3__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.
Potentially problematic release.
This version of cutcutcodec might be problematic. Click here for more details.
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__main__.py +38 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/c_build.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/_helper_properties.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/duration.py +83 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/ffprobe.py +637 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/find.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/time_backprop.py +68 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_audio.py +239 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_video.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/shape.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/time_backprop.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/duration.py +162 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/nb_frames.py +159 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/rate.py +102 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/timestamps.py +194 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/container.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/encoder.py +152 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/filter.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame.py +127 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_audio.py +205 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_video.py +322 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/layout.py +206 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/meta_filter.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/muxer.py +184 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/node.py +164 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream.py +182 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_audio.py +130 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_video.py +193 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/__init__.py +7 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/ast_to_file.py +125 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/compatibility.py +734 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/default.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/encodec.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/muxer.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/rate.py +133 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_ast.py +477 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_json.py +104 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_tree.py +190 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/json_to_graph.py +114 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/parse.py +123 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/__init__.py +15 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/dynamic.py +544 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/lambdify.py +612 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/preprocess.py +698 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/printer.py +926 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/tree_to_graph.py +168 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/decision/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/add.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/remove.py +476 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/exceptions.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/add.py +170 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cut.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/delay.py +85 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/equation.py +261 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/fir.py +231 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/resample.py +451 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/cut.py +74 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/audio_cast.py +208 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/video_cast.py +197 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/subclip.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/add.py +331 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cut.py +113 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/delay.py +84 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/equation.py +265 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/pad.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/empty.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/equation.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/noise.py +243 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/c_fractal.cpython-312-x86_64-linux-gnu.so +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/empty.py +69 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/equation.py +109 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/fractal.c +116 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/geometry.py +100 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/mandelbrot.py +176 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/noise.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/seedable.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_ffmpeg.py +904 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_svg.py +145 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/scheduler.py +356 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/write.py +340 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/basic.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/graph.py +80 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/graph.py +81 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/singleton.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cuda/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/proba.py +189 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/delay_to_fir.py +88 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/graph.py +17 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/buffer.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/utils.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/audio_5.1_narration.oga +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/intro.webm +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/logo.svg +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/project.json +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/video.mp4 +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__main__.py +25 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/actions.py +63 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/app.py +248 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/base.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/container_input_ffmpeg.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_equation.py +45 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_fir.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_cut.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_delay.py +20 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_subclip.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_equation.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_equation.py +14 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_noise.py +19 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_equation.py +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_mandelbrot.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_noise.py +18 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/base.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/default.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/documentation.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/general.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/interface.py +305 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/loader.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/main.py +62 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edition_tabs.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/base.py +122 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/filters.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/generators.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry_tabs.py +46 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/_helper.py +54 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/container.py +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/doc.py +67 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/encodec.py +289 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/main.py +173 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/edge_properties.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/main.py +280 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/node.py +44 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/main.py +151 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/menu.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/audio_settings.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/main.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/video_settings.py +257 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/run.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/main.py +30 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/slider.py +286 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/track.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/view.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/toolbar.py +29 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/tools.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/audio_player.py +103 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/control.py +96 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/frame_extractor.py +254 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/main.py +115 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__main__.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/coding_style.py +49 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/generation.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/install.py +72 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/run.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/abstract.py +215 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_cast.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_equation.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/c_memory.py +132 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compatibility.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compile.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/encoder.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_cut.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_delay.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_empty.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/fir.py +143 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/hashes.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/initialisation.py +24 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/muxer.py +22 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/nan_snapshot.py +39 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/read.py +192 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/serialization_equality.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/snapshot_shape.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/sympy_to_torch.py +135 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/thread_safe.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/time_range.py +55 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/video_equation.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/write.py +95 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/utils.py +40 -0
- cutcutcodec-1.0.post3.dist-info/LICENSE +7 -0
- cutcutcodec-1.0.post3.dist-info/METADATA +271 -0
- cutcutcodec-1.0.post3.dist-info/RECORD +233 -0
- cutcutcodec-1.0.post3.dist-info/WHEEL +5 -0
- cutcutcodec-1.0.post3.dist-info/entry_points.txt +6 -0
- cutcutcodec-1.0.post3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Compile an assembly graph into an evaluable source code of tree."""
|
|
4
|
+
|
|
5
|
+
import ast
|
|
6
|
+
import inspect
|
|
7
|
+
import pathlib
|
|
8
|
+
import re
|
|
9
|
+
import time
|
|
10
|
+
import unidecode
|
|
11
|
+
|
|
12
|
+
import networkx
|
|
13
|
+
|
|
14
|
+
from cutcutcodec.core.classes.container import ContainerOutput
|
|
15
|
+
from cutcutcodec.core.classes.node import Node
|
|
16
|
+
from cutcutcodec.utils import get_project_root
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _node_to_ast(
|
|
20
|
+
node_name: str, graph: networkx.MultiDiGraph
|
|
21
|
+
) -> tuple[ast.FunctionDef, list[ast.ImportFrom]]:
|
|
22
|
+
'''Create the ast Function of this node.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
node_name : str
|
|
27
|
+
The node name to compile.
|
|
28
|
+
graph : networkx.MultiDiGraph
|
|
29
|
+
The assembly graph.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
func : ast.FunctionDef
|
|
34
|
+
The ast fonction corresponding to the part of this branch,
|
|
35
|
+
including the fourch node or the input node.
|
|
36
|
+
modules : list[ast.ImportFrom]
|
|
37
|
+
The cutcutcodec modules requiers for this branch.
|
|
38
|
+
|
|
39
|
+
Notes
|
|
40
|
+
-----
|
|
41
|
+
* No check for performances reasons.
|
|
42
|
+
* Input / Ouput pickalisable, no modification inplace for alow parralelisation.
|
|
43
|
+
|
|
44
|
+
Examples
|
|
45
|
+
--------
|
|
46
|
+
>>> import ast
|
|
47
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
48
|
+
>>> from cutcutcodec.core.compilation.graph_to_ast import _node_to_ast
|
|
49
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
50
|
+
>>> from cutcutcodec.core.filters.audio.delay import FilterAudioDelay
|
|
51
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
52
|
+
>>>
|
|
53
|
+
>>> gen = GeneratorAudioNoise(0)
|
|
54
|
+
>>> filter_2 = FilterAudioDelay(gen.out_streams, 10)
|
|
55
|
+
>>> filter_1 = FilterAudioDelay(filter_2.out_streams, 5)
|
|
56
|
+
>>> graph = tree_to_graph(ContainerOutput(filter_1.out_streams))
|
|
57
|
+
>>>
|
|
58
|
+
>>> func, modules = _node_to_ast("container_output_1", graph)
|
|
59
|
+
>>> print(ast.unparse(func))
|
|
60
|
+
def get_container_output_1(filter_audio_delay_1: Node) -> ContainerOutput:
|
|
61
|
+
"""Create the node 'container_output_1'."""
|
|
62
|
+
container_output_1 = ContainerOutput.__new__(ContainerOutput)
|
|
63
|
+
container_output_1.setstate([filter_audio_delay_1.out_streams[0]], state={})
|
|
64
|
+
return container_output_1
|
|
65
|
+
>>> func, modules = _node_to_ast("filter_audio_delay_1", graph)
|
|
66
|
+
>>> print(ast.unparse(func))
|
|
67
|
+
def get_filter_audio_delay_1(filter_audio_delay_2: Node) -> FilterAudioDelay:
|
|
68
|
+
"""Create the node 'filter_audio_delay_1'."""
|
|
69
|
+
filter_audio_delay_1 = FilterAudioDelay.__new__(FilterAudioDelay)
|
|
70
|
+
filter_audio_delay_1.setstate([filter_audio_delay_2.out_streams[0]], state={'delay': '5'})
|
|
71
|
+
return filter_audio_delay_1
|
|
72
|
+
>>> func, modules = _node_to_ast("generator_audio_noise_1", graph)
|
|
73
|
+
>>> print(ast.unparse(func))
|
|
74
|
+
def get_generator_audio_noise_1() -> GeneratorAudioNoise:
|
|
75
|
+
"""Create the node 'generator_audio_noise_1'."""
|
|
76
|
+
generator_audio_noise_1 = GeneratorAudioNoise.__new__(GeneratorAudioNoise)
|
|
77
|
+
generator_audio_noise_1.setstate([], state={'seed': 0.0, 'layout': 'stereo'})
|
|
78
|
+
return generator_audio_noise_1
|
|
79
|
+
>>>
|
|
80
|
+
'''
|
|
81
|
+
modules = []
|
|
82
|
+
body = []
|
|
83
|
+
name = _node_name_to_var_name(node_name)
|
|
84
|
+
|
|
85
|
+
# typing annotation returns type and doctring
|
|
86
|
+
returns = ast.Name(id=graph.nodes[node_name]["class"].__name__, ctx=ast.Load())
|
|
87
|
+
modules.append(_class_to_ast(graph.nodes[node_name]["class"]))
|
|
88
|
+
body.append(ast.Expr(value=ast.Constant(f"Create the node {repr(node_name)}.")))
|
|
89
|
+
|
|
90
|
+
# node creation statement
|
|
91
|
+
in_var_index = [
|
|
92
|
+
(_node_name_to_var_name(src), int(key.split("->")[0]))
|
|
93
|
+
for src, key in sorted(
|
|
94
|
+
((src, key) for src, _, key in graph.in_edges(node_name, keys=True)),
|
|
95
|
+
key=lambda src_key: int(src_key[1].split("->")[1]),
|
|
96
|
+
)
|
|
97
|
+
]
|
|
98
|
+
state = ast.parse(repr(graph.nodes[node_name]["state"]), mode="eval").body
|
|
99
|
+
body.append(
|
|
100
|
+
ast.Assign(
|
|
101
|
+
targets=[ast.Name(id=node_name, ctx=ast.Store())],
|
|
102
|
+
value=ast.Call(
|
|
103
|
+
func=ast.Attribute(
|
|
104
|
+
value=ast.Name(id=graph.nodes[node_name]["class"].__name__, ctx=ast.Load()),
|
|
105
|
+
attr="__new__",
|
|
106
|
+
ctx=ast.Load(),
|
|
107
|
+
),
|
|
108
|
+
args=[ast.Name(id=graph.nodes[node_name]["class"].__name__, ctx=ast.Load())],
|
|
109
|
+
keywords=[],
|
|
110
|
+
),
|
|
111
|
+
lineno=0, # fix AttributeError: 'Assign' object has no attribute 'lineno'
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
body.append(
|
|
115
|
+
ast.Expr(
|
|
116
|
+
value=ast.Call(
|
|
117
|
+
func=ast.Attribute(
|
|
118
|
+
value=ast.Name(id=node_name, ctx=ast.Load()),
|
|
119
|
+
attr="setstate",
|
|
120
|
+
ctx=ast.Load(),
|
|
121
|
+
),
|
|
122
|
+
args=[
|
|
123
|
+
ast.List(
|
|
124
|
+
elts=[
|
|
125
|
+
ast.Subscript(
|
|
126
|
+
value=ast.Attribute(
|
|
127
|
+
value=ast.Name(id=var, ctx=ast.Load()),
|
|
128
|
+
attr="out_streams",
|
|
129
|
+
ctx=ast.Load()
|
|
130
|
+
),
|
|
131
|
+
slice=ast.Constant(value=ind),
|
|
132
|
+
ctx=ast.Load()
|
|
133
|
+
)
|
|
134
|
+
for var, ind in in_var_index
|
|
135
|
+
],
|
|
136
|
+
ctx=ast.Load(),
|
|
137
|
+
)
|
|
138
|
+
],
|
|
139
|
+
keywords=[ast.keyword(arg="state", value=state)],
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# return statement
|
|
145
|
+
body.append(
|
|
146
|
+
ast.Return(value=ast.Name(id=name, ctx=ast.Load()))
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# input args
|
|
150
|
+
args = ast.arguments(
|
|
151
|
+
posonlyargs=[],
|
|
152
|
+
args=[
|
|
153
|
+
ast.arg(arg=node, annotation=ast.Name(id="Node", ctx=ast.Load()))
|
|
154
|
+
for node in sorted({n for n, _ in in_var_index})
|
|
155
|
+
],
|
|
156
|
+
kwonlyargs=[],
|
|
157
|
+
kw_defaults=[],
|
|
158
|
+
defaults=[],
|
|
159
|
+
)
|
|
160
|
+
modules.append(_class_to_ast(Node))
|
|
161
|
+
func = ast.FunctionDef(
|
|
162
|
+
name=f"get_{name}",
|
|
163
|
+
args=args,
|
|
164
|
+
body=body,
|
|
165
|
+
decorator_list=[],
|
|
166
|
+
returns=returns,
|
|
167
|
+
lineno=0, # fix AttributeError: 'FunctionDef' object has no attribute 'lineno'
|
|
168
|
+
)
|
|
169
|
+
return func, modules
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _class_to_ast(cls: type) -> ast.ImportFrom:
|
|
173
|
+
"""Localise the position of the class and parse the location.
|
|
174
|
+
|
|
175
|
+
Parameters
|
|
176
|
+
----------
|
|
177
|
+
cls : type
|
|
178
|
+
The class to import.
|
|
179
|
+
|
|
180
|
+
Returns
|
|
181
|
+
-------
|
|
182
|
+
imp : ast.ImportFrom
|
|
183
|
+
The parsed location of this class in the cutcutcodec module.
|
|
184
|
+
|
|
185
|
+
Raises
|
|
186
|
+
------
|
|
187
|
+
TypeError
|
|
188
|
+
If the class is not a cutcutcodec accessible class.
|
|
189
|
+
|
|
190
|
+
Examples
|
|
191
|
+
--------
|
|
192
|
+
>>> import ast
|
|
193
|
+
>>> from cutcutcodec.core.compilation.graph_to_ast import _class_to_ast
|
|
194
|
+
>>> from cutcutcodec.core.classes.node import Node
|
|
195
|
+
>>> print(ast.unparse(_class_to_ast(Node)))
|
|
196
|
+
from cutcutcodec.core.classes.node import Node
|
|
197
|
+
>>>
|
|
198
|
+
"""
|
|
199
|
+
if (source := inspect.getsourcefile(cls)) is None:
|
|
200
|
+
raise TypeError(f"impossible to locate {cls}")
|
|
201
|
+
source = pathlib.Path(source).resolve()
|
|
202
|
+
root = get_project_root()
|
|
203
|
+
if not source.is_relative_to(root):
|
|
204
|
+
raise TypeError(f"class {cls} ({source}) is not a cutcutcodec class ({root})")
|
|
205
|
+
rel_source = "cutcutcodec" / source.relative_to(root)
|
|
206
|
+
rel_source = rel_source.with_suffix("")
|
|
207
|
+
imp = ast.ImportFrom(
|
|
208
|
+
module=".".join(rel_source.parts), names=[ast.alias(cls.__name__)], level=0
|
|
209
|
+
)
|
|
210
|
+
return imp
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _mod_sort_factor(mods: list[ast.ImportFrom]) -> list[ast.ImportFrom]:
|
|
214
|
+
"""Sorting and factoring an import group.
|
|
215
|
+
|
|
216
|
+
Parameters
|
|
217
|
+
----------
|
|
218
|
+
mods : list[ast.ImportFrom]
|
|
219
|
+
All modules to be processed, there may be redundancy.
|
|
220
|
+
|
|
221
|
+
Returns
|
|
222
|
+
-------
|
|
223
|
+
list[ast.ImportFrom]
|
|
224
|
+
An equivalent sorted and compacted version. The order can be changed.
|
|
225
|
+
|
|
226
|
+
Notes
|
|
227
|
+
-----
|
|
228
|
+
This algorithm is in o(n*log(n)).
|
|
229
|
+
|
|
230
|
+
Examples
|
|
231
|
+
--------
|
|
232
|
+
>>> import ast
|
|
233
|
+
>>> from pprint import pprint
|
|
234
|
+
>>> from cutcutcodec.core.compilation.graph_to_ast import _mod_sort_factor
|
|
235
|
+
>>> mods = [
|
|
236
|
+
... ast.ImportFrom(module="a.b", names=[ast.alias("f_1")], level=0),
|
|
237
|
+
... ast.ImportFrom(module="b", names=[ast.alias("f_2")], level=0),
|
|
238
|
+
... ast.ImportFrom(module="b", names=[ast.alias("f_1")], level=0),
|
|
239
|
+
... ast.ImportFrom(module="a", names=[ast.alias("f_1")], level=0),
|
|
240
|
+
... ast.ImportFrom(module="a", names=[ast.alias("f_2")], level=0),
|
|
241
|
+
... ast.ImportFrom(module="a", names=[ast.alias("f_2")], level=0),
|
|
242
|
+
... ast.ImportFrom(module="a", names=[ast.alias("f_3"), ast.alias("f_4")], level=0),
|
|
243
|
+
... ]
|
|
244
|
+
>>> pprint([ast.dump(mod) for mod in _mod_sort_factor(mods)])
|
|
245
|
+
["ImportFrom(module='a', names=[alias(name='f_1'), alias(name='f_2'), "
|
|
246
|
+
"alias(name='f_3'), alias(name='f_4')], level=0)",
|
|
247
|
+
"ImportFrom(module='a.b', names=[alias(name='f_1')], level=0)",
|
|
248
|
+
"ImportFrom(module='b', names=[alias(name='f_1'), alias(name='f_2')], "
|
|
249
|
+
'level=0)']
|
|
250
|
+
>>>
|
|
251
|
+
"""
|
|
252
|
+
assert all(isinstance(mod, ast.ImportFrom) for mod in mods), mods
|
|
253
|
+
assert all(mod.level == 0 for mod in mods), [mod.level for mod in mods]
|
|
254
|
+
|
|
255
|
+
mods_as_dict = {}
|
|
256
|
+
for mod in mods:
|
|
257
|
+
mods_as_dict[mod.module] = mods_as_dict.get(mod.module, set())
|
|
258
|
+
mods_as_dict[mod.module].update(
|
|
259
|
+
{
|
|
260
|
+
(alias.name, alias.asname) if alias.asname is not None else (alias.name,)
|
|
261
|
+
for alias in mod.names
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
compact_mods = [
|
|
265
|
+
ast.ImportFrom(
|
|
266
|
+
module=module,
|
|
267
|
+
names=[ast.alias(*al) for al in sorted(mods_as_dict[module])],
|
|
268
|
+
level=0, # fix python3.9 ast.unparse: TypeError
|
|
269
|
+
)
|
|
270
|
+
for module in sorted(mods_as_dict)
|
|
271
|
+
]
|
|
272
|
+
return compact_mods
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _node_name_to_var_name(name: str) -> str:
|
|
276
|
+
"""Convert any string in correct snake case func name style.
|
|
277
|
+
|
|
278
|
+
Parameters
|
|
279
|
+
----------
|
|
280
|
+
name : str
|
|
281
|
+
The generical non empty name.
|
|
282
|
+
|
|
283
|
+
Returns
|
|
284
|
+
-------
|
|
285
|
+
func_name
|
|
286
|
+
The normalized name in chamel case.
|
|
287
|
+
|
|
288
|
+
Examples
|
|
289
|
+
--------
|
|
290
|
+
>>> from cutcutcodec.core.compilation.graph_to_ast import _node_name_to_var_name
|
|
291
|
+
>>> _node_name_to_var_name("Éléphant 2spaceCamelCase_snake__To")
|
|
292
|
+
'elephant_2space_camel_case_snake_to'
|
|
293
|
+
>>> _node_name_to_var_name("0")
|
|
294
|
+
'_0'
|
|
295
|
+
>>>
|
|
296
|
+
"""
|
|
297
|
+
assert isinstance(name, str), name.__class__.__name__
|
|
298
|
+
assert not re.fullmatch(r"\s", name), f"name have to contains printable caracters {repr(name)}"
|
|
299
|
+
|
|
300
|
+
name = unidecode.unidecode(name) # remove accents
|
|
301
|
+
name = re.sub(r"(?!^)([A-Z]+)", r"_\1", name).lower() # snake case
|
|
302
|
+
name = name.replace(" ", "_")
|
|
303
|
+
while "__" in name:
|
|
304
|
+
name = name.replace("__", "_")
|
|
305
|
+
if name[0].isdigit():
|
|
306
|
+
name = "_" + name
|
|
307
|
+
return name
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def graph_to_ast(graph: networkx.MultiDiGraph) -> ast.Module:
|
|
311
|
+
'''Create the complete source code module from the assembly graph.
|
|
312
|
+
|
|
313
|
+
Parameters
|
|
314
|
+
----------
|
|
315
|
+
graph : networkx.MultiDiGraph
|
|
316
|
+
The assembly graph.
|
|
317
|
+
|
|
318
|
+
Returns
|
|
319
|
+
-------
|
|
320
|
+
module : ast.Module
|
|
321
|
+
The syntaxical graph of an equivalent code.
|
|
322
|
+
The function ``get_complete_tree`` returns the graph.
|
|
323
|
+
|
|
324
|
+
Examples
|
|
325
|
+
--------
|
|
326
|
+
>>> import ast
|
|
327
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
328
|
+
>>> from cutcutcodec.core.compilation.graph_to_ast import graph_to_ast
|
|
329
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
330
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
331
|
+
>>> graph = tree_to_graph(ContainerOutput(GeneratorAudioNoise(0).out_streams))
|
|
332
|
+
>>> graph_to_ast(graph) # doctest: +ELLIPSIS
|
|
333
|
+
<ast.Module object at ...>
|
|
334
|
+
>>> print(ast.unparse(_))
|
|
335
|
+
"""Autogenerated project exportation script.
|
|
336
|
+
<BLANKLINE>
|
|
337
|
+
Creation: ...
|
|
338
|
+
Graph: MultiDiGraph with 2 nodes and 1 edges
|
|
339
|
+
"""
|
|
340
|
+
from cutcutcodec.core.classes.container import ContainerOutput
|
|
341
|
+
from cutcutcodec.core.classes.node import Node
|
|
342
|
+
from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
343
|
+
<BLANKLINE>
|
|
344
|
+
def get_container_output_1(generator_audio_noise_1: Node) -> ContainerOutput:
|
|
345
|
+
"""Create the node 'container_output_1'."""
|
|
346
|
+
container_output_1 = ContainerOutput.__new__(ContainerOutput)
|
|
347
|
+
container_output_1.setstate([generator_audio_noise_1.out_streams[0]], state={})
|
|
348
|
+
return container_output_1
|
|
349
|
+
<BLANKLINE>
|
|
350
|
+
def get_generator_audio_noise_1() -> GeneratorAudioNoise:
|
|
351
|
+
"""Create the node 'generator_audio_noise_1'."""
|
|
352
|
+
generator_audio_noise_1 = GeneratorAudioNoise.__new__(GeneratorAudioNoise)
|
|
353
|
+
generator_audio_noise_1.setstate([], state={'seed': 0.0, 'layout': 'stereo'})
|
|
354
|
+
return generator_audio_noise_1
|
|
355
|
+
<BLANKLINE>
|
|
356
|
+
def get_complete_tree() -> ContainerOutput:
|
|
357
|
+
"""Retrive the complete assembly graph."""
|
|
358
|
+
generator_audio_noise_1 = get_generator_audio_noise_1()
|
|
359
|
+
container_output_1 = get_container_output_1(generator_audio_noise_1)
|
|
360
|
+
return container_output_1
|
|
361
|
+
if __name__ == '__main__':
|
|
362
|
+
get_complete_tree().write()
|
|
363
|
+
>>>
|
|
364
|
+
'''
|
|
365
|
+
assert isinstance(graph, networkx.MultiDiGraph), graph.__class__.__name__
|
|
366
|
+
|
|
367
|
+
body = []
|
|
368
|
+
imps = []
|
|
369
|
+
|
|
370
|
+
# get_final node_name
|
|
371
|
+
final_var = [n for n, data in graph.nodes.data() if issubclass(data["class"], ContainerOutput)]
|
|
372
|
+
if len(final_var) != 1:
|
|
373
|
+
raise RuntimeError(f"must have exactly one ContainerOutput node, {final_var} founded")
|
|
374
|
+
final_var = _node_name_to_var_name(final_var.pop())
|
|
375
|
+
|
|
376
|
+
# extract each final lines in arbitrary order
|
|
377
|
+
sequence = [] # (ast_func, in_args_set, out_var)
|
|
378
|
+
for node in sorted(graph): # sorted for repetability
|
|
379
|
+
ast_func, imp = _node_to_ast(node, graph)
|
|
380
|
+
body.append(ast_func)
|
|
381
|
+
imps.extend(imp)
|
|
382
|
+
sequence.append(
|
|
383
|
+
(
|
|
384
|
+
ast_func, # ast.FunctionDef
|
|
385
|
+
{ast_arg.arg for ast_arg in ast_func.args.args}, # set[str], input variable
|
|
386
|
+
_node_name_to_var_name(node), # str, output variable
|
|
387
|
+
)
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
# sorted func call position in an executable sequence order o(n**2)
|
|
391
|
+
sorted_sequence = [] # index final -> bottom, output; index 0 -> top
|
|
392
|
+
defines_out = set()
|
|
393
|
+
while sequence:
|
|
394
|
+
for i, (_, in_args_set, out_var) in enumerate(sequence.copy()):
|
|
395
|
+
if in_args_set.issubset(defines_out):
|
|
396
|
+
sorted_sequence.append(sequence.pop(i))
|
|
397
|
+
defines_out.add(out_var)
|
|
398
|
+
break
|
|
399
|
+
else:
|
|
400
|
+
raise RuntimeError("cycle found")
|
|
401
|
+
if out_var == final_var:
|
|
402
|
+
break
|
|
403
|
+
|
|
404
|
+
# import management and simplification
|
|
405
|
+
imps = _mod_sort_factor(imps)
|
|
406
|
+
body = imps + body
|
|
407
|
+
|
|
408
|
+
# main func management
|
|
409
|
+
tree_body = []
|
|
410
|
+
for ast_func, in_args_set, out_var in sorted_sequence:
|
|
411
|
+
tree_body.append(
|
|
412
|
+
ast.Assign(
|
|
413
|
+
targets=[ast.Name(id=out_var, ctx=ast.Store())],
|
|
414
|
+
value=ast.Call(
|
|
415
|
+
func=ast.Name(id=ast_func.name, ctx=ast.Load()),
|
|
416
|
+
args=[ast.Name(id=arg, ctx=ast.Load()) for arg in sorted(in_args_set)],
|
|
417
|
+
keywords=[],
|
|
418
|
+
),
|
|
419
|
+
),
|
|
420
|
+
)
|
|
421
|
+
tree_body.append(ast.Return(value=ast.Name(id=sorted_sequence[-1][2], ctx=ast.Load())))
|
|
422
|
+
tree_body.insert(0, ast.Expr(value=ast.Constant("Retrive the complete assembly graph.")))
|
|
423
|
+
body.append(
|
|
424
|
+
ast.FunctionDef(
|
|
425
|
+
name="get_complete_tree",
|
|
426
|
+
args=ast.arguments(posonlyargs=[], args=[], kwonlyargs=[], kw_defaults=[], defaults=[]),
|
|
427
|
+
body=tree_body,
|
|
428
|
+
decorator_list=[],
|
|
429
|
+
returns=sorted_sequence[-1][0].returns,
|
|
430
|
+
)
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
# doctstring creation
|
|
434
|
+
body.insert(
|
|
435
|
+
0,
|
|
436
|
+
ast.Expr(
|
|
437
|
+
value=ast.Constant(
|
|
438
|
+
"Autogenerated project exportation script.\n"
|
|
439
|
+
"\n"
|
|
440
|
+
f"Creation: {time.ctime()}\n"
|
|
441
|
+
f"Graph: {graph}\n"
|
|
442
|
+
),
|
|
443
|
+
),
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
# main script execution
|
|
447
|
+
body.append(
|
|
448
|
+
ast.If(
|
|
449
|
+
test=ast.Compare(
|
|
450
|
+
left=ast.Name(id="__name__", ctx=ast.Load()),
|
|
451
|
+
ops=[ast.Eq()],
|
|
452
|
+
comparators=[ast.Constant(value="__main__")],
|
|
453
|
+
),
|
|
454
|
+
body=[
|
|
455
|
+
ast.Expr(
|
|
456
|
+
value=ast.Call(
|
|
457
|
+
func=ast.Attribute(
|
|
458
|
+
value=ast.Call(
|
|
459
|
+
func=ast.Name(id="get_complete_tree", ctx=ast.Load()),
|
|
460
|
+
args=[],
|
|
461
|
+
keywords=[]
|
|
462
|
+
),
|
|
463
|
+
attr="write",
|
|
464
|
+
ctx=ast.Load()
|
|
465
|
+
),
|
|
466
|
+
args=[],
|
|
467
|
+
keywords=[]
|
|
468
|
+
)
|
|
469
|
+
)
|
|
470
|
+
],
|
|
471
|
+
orelse=[],
|
|
472
|
+
)
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
module = ast.Module(body=body, type_ignores=[])
|
|
476
|
+
module = ast.fix_missing_locations(module) # fix "required field 'lineno' missing"
|
|
477
|
+
return module
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Help for serialisation of assembly graph."""
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
import pathlib
|
|
7
|
+
|
|
8
|
+
import networkx
|
|
9
|
+
|
|
10
|
+
from cutcutcodec.core.classes.node import Node
|
|
11
|
+
from cutcutcodec.utils import get_project_root
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _node_cls_to_string(cls: type) -> str:
|
|
15
|
+
"""Convert a Node class in str.
|
|
16
|
+
|
|
17
|
+
Bijection with ``cutcutcodec.core.compilation.json_to_graph._string_to_node_cls`` function.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
cls : type
|
|
22
|
+
The cutcutcodec.core.classes.node.Node subclass.
|
|
23
|
+
|
|
24
|
+
Returns
|
|
25
|
+
-------
|
|
26
|
+
str
|
|
27
|
+
The relative import path of the class.
|
|
28
|
+
|
|
29
|
+
Examples
|
|
30
|
+
--------
|
|
31
|
+
>>> from cutcutcodec.core.compilation.graph_to_json import _node_cls_to_string
|
|
32
|
+
>>> from cutcutcodec.core.classes.node import Node
|
|
33
|
+
>>> _node_cls_to_string(Node)
|
|
34
|
+
'classes.node.Node'
|
|
35
|
+
>>>
|
|
36
|
+
"""
|
|
37
|
+
assert issubclass(cls, Node), cls.__name__
|
|
38
|
+
root_parts = (
|
|
39
|
+
pathlib.Path(inspect.getsourcefile(cls))
|
|
40
|
+
.resolve()
|
|
41
|
+
.relative_to(get_project_root() / "core")
|
|
42
|
+
.with_suffix("")
|
|
43
|
+
.parts
|
|
44
|
+
)
|
|
45
|
+
cls_str = ".".join(root_parts) + "." + cls.__name__
|
|
46
|
+
return cls_str
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def graph_to_json(graph: networkx.MultiDiGraph) -> dict[str]:
|
|
50
|
+
"""Create the complete json serializable dictionary of the assembly graph.
|
|
51
|
+
|
|
52
|
+
Reverse operation with ``cutcutcodec.core.compilation.json_to_graph.json_to_graph`` function.
|
|
53
|
+
Leave the "cache" of the nodes.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
graph : networkx.MultiDiGraph
|
|
58
|
+
The assembly graph.
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
dict[str]
|
|
63
|
+
The equivalent graph (without cache) in the dictionary form.
|
|
64
|
+
|
|
65
|
+
Examples
|
|
66
|
+
--------
|
|
67
|
+
>>> from pprint import pprint
|
|
68
|
+
>>> from cutcutcodec.core.classes.container import ContainerOutput
|
|
69
|
+
>>> from cutcutcodec.core.compilation.graph_to_json import graph_to_json
|
|
70
|
+
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
|
|
71
|
+
>>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
|
|
72
|
+
>>> graph = tree_to_graph(ContainerOutput(GeneratorAudioNoise(0).out_streams))
|
|
73
|
+
>>> graph.nodes["container_output_1"]["cache"] = None
|
|
74
|
+
>>> graph.nodes["container_output_1"]["state"]["copy"] = False
|
|
75
|
+
>>> graph.nodes["container_output_1"]["display"] = {"position": [0, 0]}
|
|
76
|
+
>>> pprint(graph_to_json(graph))
|
|
77
|
+
{'edges': [['generator_audio_noise_1', 'container_output_1', '0->0']],
|
|
78
|
+
'nodes': {'container_output_1': {'class': 'classes.container.ContainerOutput',
|
|
79
|
+
'display': {'position': [0, 0]},
|
|
80
|
+
'state': {'copy': False}},
|
|
81
|
+
'generator_audio_noise_1': {'class': 'generation.audio.noise.GeneratorAudioNoise',
|
|
82
|
+
'state': {'layout': 'stereo',
|
|
83
|
+
'seed': 0.0}}}}
|
|
84
|
+
>>>
|
|
85
|
+
"""
|
|
86
|
+
assert isinstance(graph, networkx.MultiDiGraph), graph.__class__.__name__
|
|
87
|
+
|
|
88
|
+
def get_node_attrs(data: dict) -> dict:
|
|
89
|
+
"""Convert a node into json."""
|
|
90
|
+
assert {"class", "state"}.issubset(data), set(data) # issubset(dict) <=> issubset(set)
|
|
91
|
+
attrs = {"class": _node_cls_to_string(data["class"]), "state": data["state"]}
|
|
92
|
+
if attrs["state"].get("copy") is True: # remove because it's the default behavour
|
|
93
|
+
attrs["state"] = {k: v for k, v in data["state"].items() if k != "copy"}
|
|
94
|
+
for category in data:
|
|
95
|
+
if category in {"cache", "class", "state"}:
|
|
96
|
+
continue
|
|
97
|
+
attrs.update({category: data[category]})
|
|
98
|
+
return attrs
|
|
99
|
+
|
|
100
|
+
json_dict = {
|
|
101
|
+
"edges": sorted((list(e) for e in graph.edges)),
|
|
102
|
+
"nodes": {node: get_node_attrs(data) for node, data in graph.nodes.data()},
|
|
103
|
+
}
|
|
104
|
+
return json_dict
|