mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Compare commits
22 Commits
0.3.1
...
8909594a98
| Author | SHA1 | Date | |
|---|---|---|---|
| 8909594a98 | |||
| e2aecc684f | |||
| 72cb52e0bf | |||
| 5efae02594 | |||
| 1eed4ed198 | |||
| 922765c7eb | |||
| 9a449b01fa | |||
| bfcab5f46d | |||
| 0c2174525e | |||
| 2a6c42829f | |||
| 8b719bc3f9 | |||
| 118425f994 | |||
| 53712f76ce | |||
| d5fad2beb6 | |||
| 4e4ada293e | |||
| 1e48aa144e | |||
| 233fd5742d | |||
| 7d1a9e6310 | |||
| 7194a335dd | |||
| b3834edaee | |||
| 14e1a3b7a2 | |||
| a71979c6ac |
28
.github/workflows/build-exe.yml
vendored
Normal file
28
.github/workflows/build-exe.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
name: Workflow - Build exe
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: windows-latest
|
||||||
|
name: Build Windows exe
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
name: Checkout
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
name: Setup Python
|
||||||
|
with:
|
||||||
|
python-version: ${{ vars.PYTHON_VERSION}}
|
||||||
|
- name: Install deps
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install .[build]
|
||||||
|
- name: Build
|
||||||
|
run: pyinstaller dyn2py.spec
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
name: Upload artifact
|
||||||
|
with:
|
||||||
|
name: dyn2py.exe
|
||||||
|
path: dist/dyn2py.exe
|
||||||
29
.github/workflows/build-installer.yml
vendored
Normal file
29
.github/workflows/build-installer.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
|
||||||
|
name: Workflow - Build installer
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-installer:
|
||||||
|
runs-on: windows-latest
|
||||||
|
name: Build Windows installer
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
name: Checkout
|
||||||
|
- name: Install Inno Setup
|
||||||
|
run: |
|
||||||
|
Invoke-WebRequest -Uri https://jrsoftware.org/download.php/is.exe -OutFile is.exe
|
||||||
|
.\is.exe /verysilent
|
||||||
|
- name: Download artifact
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dyn2py.exe
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
.\dyn2py-installer.ps1
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
name: Upload artifact
|
||||||
|
with:
|
||||||
|
name: dyn2py-installer.exe
|
||||||
|
path: Output/dyn2py-installer.exe
|
||||||
47
.github/workflows/release.yml
vendored
47
.github/workflows/release.yml
vendored
@@ -10,6 +10,7 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
name: Test
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
@@ -18,31 +19,20 @@ jobs:
|
|||||||
python-version: ${{ vars.PYTHON_VERSION }}
|
python-version: ${{ vars.PYTHON_VERSION }}
|
||||||
os: ${{ matrix.os }}
|
os: ${{ matrix.os }}
|
||||||
|
|
||||||
build:
|
build-exe:
|
||||||
runs-on: windows-latest
|
name: Build Windows exe
|
||||||
needs: test
|
needs: test
|
||||||
steps:
|
uses: ./.github/workflows/build-exe.yml
|
||||||
- uses: actions/checkout@v3
|
|
||||||
name: Checkout
|
build-installer:
|
||||||
- uses: actions/setup-python@v4
|
name: Build Windows installer
|
||||||
name: Setup Python
|
needs: build-exe
|
||||||
with:
|
uses: ./.github/workflows/build-installer.yml
|
||||||
python-version: ${{ vars.PYTHON_VERSION}}
|
|
||||||
- name: Install deps
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install .[build]
|
|
||||||
- name: Build
|
|
||||||
run: pyinstaller dyn2py.spec
|
|
||||||
- uses: actions/upload-artifact@v3
|
|
||||||
name: Upload artifact
|
|
||||||
with:
|
|
||||||
name: dyn2py.exe
|
|
||||||
path: dist/dyn2py.exe
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
|
name: Create Github release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build-installer
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
name: Checkout
|
name: Checkout
|
||||||
@@ -51,19 +41,26 @@ jobs:
|
|||||||
uses: metcalfc/changelog-generator@v4.1.0
|
uses: metcalfc/changelog-generator@v4.1.0
|
||||||
with:
|
with:
|
||||||
myToken: ${{ secrets.GITHUB_TOKEN }}
|
myToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Download artifact
|
- name: Download exe
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: dyn2py.exe
|
name: dyn2py.exe
|
||||||
|
- name: Download installer
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dyn2py-installer.exe
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: dyn2py.exe
|
files: |
|
||||||
body: ${{ steps.modified.outputs.log }}
|
dyn2py.exe
|
||||||
|
dyn2py-installer.exe
|
||||||
|
body: ${{ steps.changelog.outputs.changelog }}
|
||||||
|
|
||||||
pip:
|
pip:
|
||||||
|
name: Publish to PyPI
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: release
|
needs: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
name: Checkout
|
name: Checkout
|
||||||
|
|||||||
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@@ -8,11 +8,15 @@ on:
|
|||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
name: Workflow - Test
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
name: Run tests
|
||||||
runs-on: ${{ inputs.os }}
|
runs-on: ${{ inputs.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
name: Checkout
|
||||||
- name: Set up Python ${{ inputs.python-version }}
|
- name: Set up Python ${{ inputs.python-version }}
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
@@ -21,5 +25,5 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install .
|
pip install .
|
||||||
- name: Test
|
- name: Run tests
|
||||||
run: python -m unittest discover -v -s ./tests -p "test_*.py"
|
run: python -m unittest discover -v -s ./tests -p "test_*.py"
|
||||||
2
.github/workflows/unittests.yml
vendored
2
.github/workflows/unittests.yml
vendored
@@ -5,12 +5,14 @@ on:
|
|||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
|
name: Unit tests
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
|
|||||||
14
.github/workflows/website.yml
vendored
14
.github/workflows/website.yml
vendored
@@ -5,7 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# security: restrict permissions for CI jobs.
|
# security: restrict permissions for CI jobs.
|
||||||
@@ -18,19 +17,22 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build the documentation and upload the static HTML files as an artifact.
|
|
||||||
build:
|
build:
|
||||||
|
name: Build documentation
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
name: Checkout
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
|
name: Setup Python
|
||||||
with:
|
with:
|
||||||
python-version: "3.11"
|
python-version: ${{ vars.PYTHON_VERSION }}
|
||||||
|
|
||||||
- run: pip install -e .[doc]
|
- run: pip install -e .[doc]
|
||||||
|
name: Install deps
|
||||||
- run: pdoc -d google -o docs dyn2py
|
- run: pdoc -d google -o docs dyn2py
|
||||||
|
name: Generate docs
|
||||||
- uses: actions/upload-pages-artifact@v1
|
- uses: actions/upload-pages-artifact@v1
|
||||||
|
name: Upload artifact
|
||||||
with:
|
with:
|
||||||
path: docs/
|
path: docs/
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ jobs:
|
|||||||
# This is a separate job so that only actions/deploy-pages has the necessary permissions.
|
# This is a separate job so that only actions/deploy-pages has the necessary permissions.
|
||||||
deploy:
|
deploy:
|
||||||
needs: build
|
needs: build
|
||||||
|
name: Publish documentation
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
pages: write
|
pages: write
|
||||||
@@ -47,4 +50,5 @@ jobs:
|
|||||||
url: ${{ steps.deployment.outputs.page_url }}
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
steps:
|
steps:
|
||||||
- id: deployment
|
- id: deployment
|
||||||
|
name: Deploy page
|
||||||
uses: actions/deploy-pages@v1
|
uses: actions/deploy-pages@v1
|
||||||
|
|||||||
17
.github/workflows/windows-build.yml
vendored
Normal file
17
.github/workflows/windows-build.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
name: Build Windows exe and installer
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
# push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-exe:
|
||||||
|
uses: ./.github/workflows/build-exe.yml
|
||||||
|
name: Build Windows exe
|
||||||
|
|
||||||
|
build-installer:
|
||||||
|
name: Build Windows installer
|
||||||
|
needs: build-exe
|
||||||
|
uses: ./.github/workflows/build-installer.yml
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,3 +6,5 @@ build
|
|||||||
dist
|
dist
|
||||||
docs
|
docs
|
||||||
tests/output_files
|
tests/output_files
|
||||||
|
Output
|
||||||
|
dyn2py.exe
|
||||||
151
README.md
151
README.md
@@ -1,3 +1,10 @@
|
|||||||
|
[](https://github.com/infeeeee/dyn2py/releases/latest)
|
||||||
|
[](https://pypi.org/project/dyn2py/)
|
||||||
|
[](https://github.com/infeeeee/dyn2py/releases/latest)
|
||||||
|
[](https://github.com/infeeeee/dyn2py/commits/main)
|
||||||
|
[](https://github.com/infeeeee/dyn2py/actions/workflows/unittests.yml)
|
||||||
|
[](https://github.com/infeeeee/dyn2py/blob/main/LICENSE)
|
||||||
|
|
||||||
# dyn2py
|
# dyn2py
|
||||||
|
|
||||||
Extract python code from Dynamo graphs
|
Extract python code from Dynamo graphs
|
||||||
@@ -5,27 +12,30 @@ Extract python code from Dynamo graphs
|
|||||||
Use cases:
|
Use cases:
|
||||||
|
|
||||||
- Track changes in python nodes in source control systems like git
|
- Track changes in python nodes in source control systems like git
|
||||||
- Work on python code in your favorite code editor outside Dynamo. `dyn2py` can also update Dynamo graphs from the previously exported python files.
|
- Work on python code in your favorite code editor outside Dynamo. `dyn2py` can also update Dynamo graphs from previously exported python files.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Windows portable
|
### Windows portable and installer
|
||||||
|
|
||||||
Prebuilt exe available from github releases.
|
Prebuilt portable exe and installer available from github releases.
|
||||||
|
|
||||||
No requirements, just download `dyn2py.exe` from release assets:
|
No requirements, just download `dyn2py.exe` or `dyn2py-installer.exe` from release assets:
|
||||||
|
|
||||||
https://github.com/infeeeee/dyn2py/releases/latest
|
https://github.com/infeeeee/dyn2py/releases/latest
|
||||||
|
|
||||||
### With pip from Github
|
Installer automatically adds the install folder to the path, so simply `dyn2py` can be called from anywhere.
|
||||||
|
|
||||||
Requirements: git, python, pip
|
### With pip
|
||||||
|
|
||||||
|
For usage as a module or as a command line program
|
||||||
|
|
||||||
|
Requirements: python, pip
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install "dyn2py @ git+https://github.com/infeeeee/dyn2py"
|
pip install dyn2py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### As a standalone command line program
|
### As a standalone command line program
|
||||||
@@ -43,7 +53,7 @@ options:
|
|||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --version show program's version number and exit
|
-v, --version show program's version number and exit
|
||||||
-l LOGLEVEL, --loglevel LOGLEVEL
|
-l LOGLEVEL, --loglevel LOGLEVEL
|
||||||
set log level, possible options: CRITICAL, ERROR, WARNING, INFO, DEBUG
|
set log level, possible options: HEADLESS, CRITICAL, ERROR, WARNING, INFO, DEBUG
|
||||||
-n, --dry-run do not modify files, only show log
|
-n, --dry-run do not modify files, only show log
|
||||||
-F, --force overwrite even if the files are older
|
-F, --force overwrite even if the files are older
|
||||||
-b, --backup create a backup for updated files
|
-b, --backup create a backup for updated files
|
||||||
@@ -58,47 +68,114 @@ dynamo options, only for processing Dynamo graphs:
|
|||||||
The script by default overwrites older files with newer files.
|
The script by default overwrites older files with newer files.
|
||||||
Do not move the source Dynamo graphs, or update won't work with them later.
|
Do not move the source Dynamo graphs, or update won't work with them later.
|
||||||
Multiple sources are supported, separate them by spaces.
|
Multiple sources are supported, separate them by spaces.
|
||||||
|
HEADLESS loglevel only prints modified filenames.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
*Notes: In Windows cmd use backward slashes as path separators, in any other shells use forward slashes. Powershell accepts both of them. Wrap paths with spaces in double quotes.*
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# Extract all nodes next to a Dynamo file:
|
||||||
|
dyn2py path/to/dynamofile.dyn
|
||||||
|
|
||||||
|
# Update a Dynamo file from previously exported and modified python files:
|
||||||
|
dyn2py --update path/to/dynamofile.dyn
|
||||||
|
|
||||||
|
# Extract python nodes to a specific folder, process multiple Dynamo files:
|
||||||
|
dyn2py --python-folder path/to/pythonfiles path/to/dynamofile1.dyn path/to/dynamofile2.dyn
|
||||||
|
|
||||||
|
# Update Dynamo files from python files from a folder. Only check python files, create backups:
|
||||||
|
dyn2py --filter py --backup path/to/pythonfiles
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Git hooks
|
||||||
|
|
||||||
|
Git hooks are a built-in feature of Git that allow developers to automate tasks throughout the Git workflow. Read more here: https://githooks.com/
|
||||||
|
|
||||||
|
With the `pre-commit` hook it's possible to add more files to the currently initialized commit.
|
||||||
|
|
||||||
|
You can find an example pre-commit hook here: [pre-commit](pre-commit). Copy this file to the `.git/hooks` folder of your repo of Dynamo graphs. This folder is hidden by default, but it should exist in all initialized git repo. Do not rename this file.
|
||||||
|
|
||||||
|
This script will go through staged `.dyn` files and export python scripts from them, and add them to the current commit. Now you can check changed lines in a diff tool, you can see changed python code in a PR!
|
||||||
|
|
||||||
### As a python module
|
### As a python module
|
||||||
|
|
||||||
Full API documentation available here: https://infeeeee.github.io/dyn2py
|
Full API documentation available here: https://infeeeee.github.io/dyn2py
|
||||||
|
|
||||||
Most basic example to extract all nodes next to a dynamo file:
|
#### Examples
|
||||||
|
|
||||||
|
Extract all nodes from python nodes next to a Dynamo file:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import dyn2py
|
import dyn2py
|
||||||
|
|
||||||
|
# Open a Dynamo graph:
|
||||||
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")
|
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")
|
||||||
python_files = dynamo_file.extract_python()
|
|
||||||
[python_file.write() for python_file in python_files]
|
# Extract python nodes:
|
||||||
|
dynamo_file.extract_python()
|
||||||
|
|
||||||
|
# Save all python nodes as separate files:
|
||||||
|
dyn2py.PythonFile.write_open_files()
|
||||||
```
|
```
|
||||||
|
|
||||||
Change options like with the command line switches with the `Options` class:
|
Update python node from a python file:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import dyn2py
|
import dyn2py
|
||||||
|
|
||||||
# Create a backup on overwrite, read python files from a different folder:
|
# Open a python file:
|
||||||
options = dyn2py.Options(
|
python_file = dyn2py.PythonFile("path/to/pythonfile.py")
|
||||||
backup=True,
|
|
||||||
python_folder="path/to/pythonfiles")
|
|
||||||
|
|
||||||
|
# Update the node in the graph:
|
||||||
|
python_file.update_dynamo()
|
||||||
|
|
||||||
|
# Save modified Dynamo graph:
|
||||||
|
dyn2py.DynamoFile.write_open_files()
|
||||||
|
```
|
||||||
|
|
||||||
|
Update all python nodes of a Dynamo grapg from a different folder, save backups:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import dyn2py
|
||||||
|
|
||||||
|
# open a Dynamo graph:
|
||||||
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")
|
dynamo_file = dyn2py.DynamoFile("path/to/dynamofile.dyn")
|
||||||
python_files = dynamo_file.get_related_python_files(options)
|
|
||||||
|
# Get python files from a dofferent folder:
|
||||||
|
python_files = dynamo_file.get_related_python_files(python_folder="path/to/pythonfiles")
|
||||||
|
|
||||||
# Read python files and update the graph:
|
# Read python files and update the graph:
|
||||||
[python_file.update_dynamo(options) for python_file in python_files]
|
[python_file.update_dynamo() for python_file in python_files]
|
||||||
|
|
||||||
# Don't forget to save at the end:
|
# Save open Dynamo graphs:
|
||||||
dynamo_file.write(options)
|
dyn2py.DynamoFile.write_open_files(backup=True)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For more examples check tests in the [tests folder on Github](https://github.com/infeeeee/dyn2py/tree/main/tests)
|
||||||
|
|
||||||
|
They should work in Dynamo, inside CPython3 nodes.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
If you have a problem, open an [issue on Github](https://github.com/infeeeee/dyn2py/issues)
|
||||||
|
|
||||||
|
You can also ask about this project on [Dynamo Forum](https://forum.dynamobim.com/), don't forget to ping me: [@infeeeee](https://forum.dynamobim.com/u/infeeeee)
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
Only supports Dynamo 2 files, Dynamo 1 files are reported and ignored. Please update them to Dynamo 2 by opening them in Dynamo 2.
|
||||||
|
|
||||||
|
Both IronPython2 and CPython3 nodes are supported! IronPython2 nodes won't be updated to CPython3, they will be imported as-is.
|
||||||
|
|
||||||
|
Cannot create new python nodes, only existing ones can be updated.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
Requirements: git, pip
|
Requirements: git, python, pip
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/infeeeee/dyn2py
|
git clone https://github.com/infeeeee/dyn2py
|
||||||
@@ -111,21 +188,47 @@ With venv:
|
|||||||
```
|
```
|
||||||
git clone https://github.com/infeeeee/dyn2py
|
git clone https://github.com/infeeeee/dyn2py
|
||||||
cd dyn2py
|
cd dyn2py
|
||||||
venv .venv
|
python -m venv .venv
|
||||||
. ./.venv/bin/activate
|
. ./.venv/bin/activate
|
||||||
pip install -e .
|
pip install -e .
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build
|
### Build for Windows
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install -e .[build]
|
pip install -e .[build]
|
||||||
pyinstaller dyn2py.spec
|
pyinstaller dyn2py.spec
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create installer for Windows
|
||||||
|
|
||||||
|
- Install Inno Setup: https://jrsoftware.org/isdl.php
|
||||||
|
- Build an exe
|
||||||
|
- Run `dyn2py-installer.ps1` in powershell
|
||||||
|
|
||||||
### Live module documentation
|
### Live module documentation
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install -e .[doc]
|
pip install -e .[doc]
|
||||||
pdoc -d google dyn2py
|
pdoc -d google dyn2py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Unit tests
|
||||||
|
|
||||||
|
VSCode should automatically discover unit tests.
|
||||||
|
|
||||||
|
To run them manually:
|
||||||
|
|
||||||
|
```
|
||||||
|
python -m unittest discover -v -s ./tests -p "test_*.py"
|
||||||
|
```
|
||||||
|
|
||||||
|
### New release
|
||||||
|
|
||||||
|
1. Update version number in `pyproject.toml`
|
||||||
|
2. Create and publish a git tag with that number
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
GPL-3.0
|
||||||
|
|
||||||
|
|||||||
9
TODO.md
9
TODO.md
@@ -7,6 +7,7 @@
|
|||||||
- [x] DynamoFile
|
- [x] DynamoFile
|
||||||
- [x] PythonFile
|
- [x] PythonFile
|
||||||
- [x] PythonNode
|
- [x] PythonNode
|
||||||
|
- [ ] Options
|
||||||
- [ ] run()
|
- [ ] run()
|
||||||
|
|
||||||
## CI/CD
|
## CI/CD
|
||||||
@@ -15,16 +16,16 @@
|
|||||||
- [x] Tests on Windows
|
- [x] Tests on Windows
|
||||||
- [x] Windows Build
|
- [x] Windows Build
|
||||||
- [x] Pip
|
- [x] Pip
|
||||||
|
- [x] Windows Installer
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
- [x] API docs
|
- [x] API docs
|
||||||
- [ ] Installation in readme
|
- [x] Installation in readme
|
||||||
- [ ] Terminal examples in readme
|
- [x] Terminal examples in readme
|
||||||
- [ ] About git hooks in readme
|
- [x] About git hooks in readme
|
||||||
|
|
||||||
## Extra features maybe later
|
## Extra features maybe later
|
||||||
|
|
||||||
- [ ] Windows Installer
|
|
||||||
- [ ] Autocomplete
|
- [ ] Autocomplete
|
||||||
- [ ] Winget
|
- [ ] Winget
|
||||||
86
dyn2py-installer.iss
Normal file
86
dyn2py-installer.iss
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
[Setup]
|
||||||
|
AppId={{E924F481-6909-43F8-8469-11155A5EB9A2}
|
||||||
|
AppName=dyn2py
|
||||||
|
AppVersion=x.x.x
|
||||||
|
AppPublisher=infeeeee
|
||||||
|
AppPublisherURL=https://github.com/infeeeee/dyn2py
|
||||||
|
AppSupportURL=https://github.com/infeeeee/dyn2py/issues
|
||||||
|
AppUpdatesURL=https://github.com/infeeeee/dyn2py/releases/latest
|
||||||
|
DefaultDirName={autopf}\dyn2py
|
||||||
|
DisableProgramGroupPage=auto
|
||||||
|
DefaultGroupName=dyn2py
|
||||||
|
LicenseFile=LICENSE
|
||||||
|
PrivilegesRequired=admin
|
||||||
|
OutputBaseFilename=dyn2py-installer
|
||||||
|
Compression=lzma
|
||||||
|
SolidCompression=yes
|
||||||
|
WizardStyle=modern
|
||||||
|
ChangesEnvironment=yes
|
||||||
|
|
||||||
|
[Languages]
|
||||||
|
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||||
|
|
||||||
|
[Files]
|
||||||
|
Source: "dyn2py.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
|
|
||||||
|
[Icons]
|
||||||
|
Name: "{group}\dyn2py (cmd)"; Filename: "{cmd}"; WorkingDir: "{userdocs}"; Parameters: "/k dyn2py"
|
||||||
|
Name: "{group}\dyn2py (powershell)"; Filename: "powershell"; WorkingDir: "{userdocs}"; Parameters: "-noexit -command dyn2py"
|
||||||
|
|
||||||
|
[Code]
|
||||||
|
const EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
|
||||||
|
|
||||||
|
procedure EnvAddPath(Path: string);
|
||||||
|
var
|
||||||
|
Paths: string;
|
||||||
|
begin
|
||||||
|
{ Retrieve current path (use empty string if entry not exists) }
|
||||||
|
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
|
||||||
|
then Paths := '';
|
||||||
|
|
||||||
|
{ Skip if string already found in path }
|
||||||
|
if Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';') > 0 then exit;
|
||||||
|
|
||||||
|
{ App string to the end of the path variable }
|
||||||
|
Paths := Paths + ';'+ Path +';'
|
||||||
|
|
||||||
|
{ Overwrite (or create if missing) path environment variable }
|
||||||
|
if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
|
||||||
|
then Log(Format('The [%s] added to PATH: [%s]', [Path, Paths]))
|
||||||
|
else Log(Format('Error while adding the [%s] to PATH: [%s]', [Path, Paths]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure EnvRemovePath(Path: string);
|
||||||
|
var
|
||||||
|
Paths: string;
|
||||||
|
P: Integer;
|
||||||
|
begin
|
||||||
|
{ Skip if registry entry not exists }
|
||||||
|
if not RegQueryStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
{ Skip if string not found in path }
|
||||||
|
P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';');
|
||||||
|
if P = 0 then exit;
|
||||||
|
|
||||||
|
{ Update path variable }
|
||||||
|
Delete(Paths, P - 1, Length(Path) + 1);
|
||||||
|
|
||||||
|
{ Overwrite path environment variable }
|
||||||
|
if RegWriteStringValue(HKEY_LOCAL_MACHINE, EnvironmentKey, 'Path', Paths)
|
||||||
|
then Log(Format('The [%s] removed from PATH: [%s]', [Path, Paths]))
|
||||||
|
else Log(Format('Error while removing the [%s] from PATH: [%s]', [Path, Paths]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure CurStepChanged(CurStep: TSetupStep);
|
||||||
|
begin
|
||||||
|
if CurStep = ssPostInstall
|
||||||
|
then EnvAddPath(ExpandConstant('{app}'));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
||||||
|
begin
|
||||||
|
if CurUninstallStep = usPostUninstall
|
||||||
|
then EnvRemovePath(ExpandConstant('{app}'));
|
||||||
|
end;
|
||||||
24
dyn2py-installer.ps1
Normal file
24
dyn2py-installer.ps1
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
$InnoSetupPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
|
||||||
|
|
||||||
|
# Check if innosetup installed
|
||||||
|
if (-not (Test-Path -Path $InnoSetupPath -PathType Leaf)) {
|
||||||
|
throw "Innosetup not found!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy dyn2py.exe from default folder:
|
||||||
|
if (Test-Path -Path ".\dist\dyn2py.exe" -PathType Leaf) {
|
||||||
|
Copy-Item ".\dist\dyn2py.exe" -Destination "." -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if dyn2py.exe exists at all
|
||||||
|
if (-not(Test-Path -Path "dyn2py.exe" -PathType Leaf)) {
|
||||||
|
throw "dyn2py.exe not found!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Read version number from pyproject.toml and update in innosetup:
|
||||||
|
$regex = Select-String -Path pyproject.toml -Pattern '^version = "((?:\d\.){2}\d)"$'
|
||||||
|
$version = $regex.Matches.Groups[1].Value
|
||||||
|
(Get-Content dyn2py-installer.iss).Replace("x.x.x", $version) | Set-Content dyn2py-installer.iss
|
||||||
|
|
||||||
|
# Build:
|
||||||
|
& $InnoSetupPath -Qp $(Join-Path $PWD.Path dyn2py-installer.iss)
|
||||||
@@ -22,11 +22,7 @@ __all__ = [
|
|||||||
"File",
|
"File",
|
||||||
"DynamoFile",
|
"DynamoFile",
|
||||||
"PythonFile",
|
"PythonFile",
|
||||||
"PythonNode",
|
"PythonNode"
|
||||||
"DynamoFileException",
|
|
||||||
"PythonNodeNotFoundException",
|
|
||||||
"PythonNodeException",
|
|
||||||
"PythonFileException"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -45,6 +41,7 @@ def __command_line() -> None:
|
|||||||
The script by default overwrites older files with newer files.
|
The script by default overwrites older files with newer files.
|
||||||
Do not move the source Dynamo graphs, or update won't work with them later.
|
Do not move the source Dynamo graphs, or update won't work with them later.
|
||||||
Multiple sources are supported, separate them by spaces.
|
Multiple sources are supported, separate them by spaces.
|
||||||
|
HEADLESS loglevel only prints modified filenames.
|
||||||
""")
|
""")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,8 +114,13 @@ def run(options: Options) -> None:
|
|||||||
from_command_line = bool(inspect.stack()[1].function == "__command_line")
|
from_command_line = bool(inspect.stack()[1].function == "__command_line")
|
||||||
|
|
||||||
# Set up logging:
|
# Set up logging:
|
||||||
|
if options.loglevel == "HEADLESS":
|
||||||
|
loglevel = "CRITICAL"
|
||||||
|
else:
|
||||||
|
loglevel = options.loglevel
|
||||||
|
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s',
|
logging.basicConfig(format='%(levelname)s: %(message)s',
|
||||||
level=options.loglevel)
|
level=loglevel)
|
||||||
logging.debug(f"Run options: {vars(options)}")
|
logging.debug(f"Run options: {vars(options)}")
|
||||||
|
|
||||||
# Set up sources:
|
# Set up sources:
|
||||||
@@ -149,13 +151,13 @@ def run(options: Options) -> None:
|
|||||||
for f in source_files:
|
for f in source_files:
|
||||||
try:
|
try:
|
||||||
files.append(File(f))
|
files.append(File(f))
|
||||||
except DynamoFileException as e:
|
except DynamoFile.Error as e:
|
||||||
# It's a dynamo1 file
|
# It's a dynamo1 file
|
||||||
logging.warning(e)
|
logging.warning(f"This is a Dynamo 1 file! {e.file.filepath}")
|
||||||
continue
|
continue
|
||||||
except PythonNodeNotFoundException as e:
|
except DynamoFile.PythonNodeNotFound as e:
|
||||||
# No python node in this file
|
# No python nodes in this file
|
||||||
logging.warning(e)
|
logging.warning(f"This file has no Python nodes! {e.file.filepath} ")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Dynamo files come first, sort sources:
|
# Dynamo files come first, sort sources:
|
||||||
@@ -193,8 +195,13 @@ def run(options: Options) -> None:
|
|||||||
|
|
||||||
elif f.is_python_file():
|
elif f.is_python_file():
|
||||||
logging.debug("Source is a Python file")
|
logging.debug("Source is a Python file")
|
||||||
|
try:
|
||||||
f.update_dynamo(options)
|
f.update_dynamo(options)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.error(f"{f.filepath} Source Dynamo file not found! ")
|
||||||
|
|
||||||
# Write files at the end:
|
# Write files at the end:
|
||||||
for f in DynamoFile.open_files | PythonFile.open_files:
|
try:
|
||||||
f.write(options)
|
File.write_open_files(options)
|
||||||
|
except File.Error as e:
|
||||||
|
logging.error(f"Cannot save file! {e.file.filepath}")
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
class DynamoFileException(Exception):
|
|
||||||
"""Something wrong in this DynamoFile"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PythonNodeNotFoundException(Exception):
|
|
||||||
"""PythonNode not found"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PythonNodeException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PythonFileException(Exception):
|
|
||||||
pass
|
|
||||||
189
dyn2py/files.py
189
dyn2py/files.py
@@ -9,7 +9,6 @@ from decimal import Decimal
|
|||||||
from pathvalidate import sanitize_filename
|
from pathvalidate import sanitize_filename
|
||||||
from importlib_metadata import metadata
|
from importlib_metadata import metadata
|
||||||
|
|
||||||
from dyn2py.exceptions import *
|
|
||||||
from dyn2py.options import Options
|
from dyn2py.options import Options
|
||||||
|
|
||||||
|
|
||||||
@@ -20,6 +19,9 @@ HEADER_SEPARATOR = "*" * 60
|
|||||||
class File():
|
class File():
|
||||||
"""Base class for managing files"""
|
"""Base class for managing files"""
|
||||||
|
|
||||||
|
open_files: set[File] = set()
|
||||||
|
"""A set of open files."""
|
||||||
|
|
||||||
def __init__(self, filepath: pathlib.Path | str, read_from_disk: bool = True) -> None:
|
def __init__(self, filepath: pathlib.Path | str, read_from_disk: bool = True) -> None:
|
||||||
"""Generate a file object. If the path is correct it will become a DynamoFile or PythonFile object.
|
"""Generate a file object. If the path is correct it will become a DynamoFile or PythonFile object.
|
||||||
Calls DynamoFile.read_file() and PythonFile.read_file()
|
Calls DynamoFile.read_file() and PythonFile.read_file()
|
||||||
@@ -110,20 +112,26 @@ class File():
|
|||||||
"""
|
"""
|
||||||
return bool(self.extension == ".py")
|
return bool(self.extension == ".py")
|
||||||
|
|
||||||
def write(self, options: Options | None = None) -> None:
|
def write(self, options: Options | None = None, **option_args) -> None:
|
||||||
"""Prepare writing file to the disk:
|
"""Prepare writing file to the disk:
|
||||||
create backup, process dry-run, call filetype specific write_file() methods
|
create backup, process dry-run, call filetype specific write_file() methods
|
||||||
Should be called on subclasses!
|
Should be called on subclasses!
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
options (Options | None, optional): Run options. Defaults to None.
|
options (Options | None, optional): Run options. Defaults to None.
|
||||||
|
**option_args: Options() arguments
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
|
ValueError: Both options and other arguments given
|
||||||
TypeError: If called on a File object
|
TypeError: If called on a File object
|
||||||
|
File.Error: Target folder does not exist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
options = Options()
|
options = Options.from_kwargs(kwargs=option_args)
|
||||||
|
elif option_args:
|
||||||
|
# Should not give both options and arguments:
|
||||||
|
raise ValueError("Options object and extra arguments!")
|
||||||
|
|
||||||
# This should only work on subclasses:
|
# This should only work on subclasses:
|
||||||
if type(self).__name__ == "File":
|
if type(self).__name__ == "File":
|
||||||
@@ -136,18 +144,24 @@ class File():
|
|||||||
# Create backup:
|
# Create backup:
|
||||||
if not options.dry_run and self.filepath.exists() and options.backup:
|
if not options.dry_run and self.filepath.exists() and options.backup:
|
||||||
backup_filename = sanitize_filename(
|
backup_filename = sanitize_filename(
|
||||||
f"{self.basename}_{self.mtimeiso}{self.extension}")
|
filename=f"{self.basename}_{self.mtimeiso}{self.extension}")
|
||||||
backup_path = self.dirpath.joinpath(backup_filename)
|
backup_path = self.dirpath.joinpath(backup_filename)
|
||||||
logging.info(f"Creating backup to {backup_path}")
|
logging.info(f"Creating backup to {backup_path}")
|
||||||
self.filepath.rename(backup_path)
|
self.filepath.rename(backup_path)
|
||||||
|
if options.loglevel == "HEADLESS":
|
||||||
|
print(backup_path)
|
||||||
|
|
||||||
# Call filetype specific methods:
|
# Call filetype specific methods:
|
||||||
if options.dry_run:
|
if options.dry_run:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"Should write file, but it's a dry-run: {self.filepath}")
|
f"Should write file, but it's a dry-run: {self.filepath}")
|
||||||
else:
|
else:
|
||||||
|
if not self.dirpath.exists():
|
||||||
|
raise File.Error("File dir does not exist!", self)
|
||||||
logging.info(f"Writing file: {self.filepath}")
|
logging.info(f"Writing file: {self.filepath}")
|
||||||
self._write_file()
|
self._write_file()
|
||||||
|
if options.loglevel == "HEADLESS":
|
||||||
|
print(self.filepath)
|
||||||
|
|
||||||
def _write_file(self):
|
def _write_file(self):
|
||||||
"""Should be implemented in subclasses
|
"""Should be implemented in subclasses
|
||||||
@@ -158,6 +172,53 @@ class File():
|
|||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Should be called only on DynamoFile and PythonFile objects!")
|
"Should be called only on DynamoFile and PythonFile objects!")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_open_files(cls) -> set:
|
||||||
|
"""Get open files of this class and subclasses
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
set: A set of open files
|
||||||
|
"""
|
||||||
|
return {f for f in File.open_files if
|
||||||
|
isinstance(f, cls)}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def write_open_files(cls, options: Options | None = None, **option_args) -> None:
|
||||||
|
"""Write open files of this class and subclasses
|
||||||
|
|
||||||
|
Args:
|
||||||
|
options (Options | None, optional): Run options. Defaults to None.
|
||||||
|
**option_args: Options() arguments
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Both options and other arguments given
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not options:
|
||||||
|
options = Options.from_kwargs(kwargs=option_args)
|
||||||
|
elif option_args:
|
||||||
|
# Should not give both options and arguments:
|
||||||
|
raise ValueError("Options object and extra arguments!")
|
||||||
|
|
||||||
|
for f in cls.get_open_files():
|
||||||
|
f.write(options)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def close_open_files(cls) -> None:
|
||||||
|
"""Close open files of this class and subclasses"""
|
||||||
|
File.open_files = File.open_files - cls.get_open_files()
|
||||||
|
|
||||||
|
class Error(Exception):
|
||||||
|
def __init__(self, message: str, file: File) -> None:
|
||||||
|
"""There is some problem with this file
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message (str): The message to display
|
||||||
|
file (File): The problem File
|
||||||
|
"""
|
||||||
|
super().__init__(message)
|
||||||
|
self.file = file
|
||||||
|
|
||||||
|
|
||||||
class DynamoFile(File):
|
class DynamoFile(File):
|
||||||
"""A Dynamo file, subclass of File()"""
|
"""A Dynamo file, subclass of File()"""
|
||||||
@@ -171,21 +232,25 @@ class DynamoFile(File):
|
|||||||
python_nodes: set[PythonNode]
|
python_nodes: set[PythonNode]
|
||||||
"""Python node objects, read from this file."""
|
"""Python node objects, read from this file."""
|
||||||
|
|
||||||
open_files: set[DynamoFile] = set()
|
def extract_python(self, options: Options | None = None, **option_args) -> list[PythonFile]:
|
||||||
"""A set of open Dynamo files, before saving. Self added by read()"""
|
|
||||||
|
|
||||||
def extract_python(self, options: Options | None = None) -> list[PythonFile]:
|
|
||||||
"""Extract python files from Dynamo graphs, add them to open_files
|
"""Extract python files from Dynamo graphs, add them to open_files
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
options (Options | None, optional): Run options. Defaults to None.
|
options (Options | None, optional): Run options. Defaults to None.
|
||||||
|
**option_args: Options() arguments
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Both options and other arguments given
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[PythonFile]: List of PythonFile objects extracted from this DynamoFile
|
list[PythonFile]: List of PythonFile objects extracted from this DynamoFile
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
options = Options()
|
options = Options.from_kwargs(kwargs=option_args)
|
||||||
|
elif option_args:
|
||||||
|
# Should not give both options and arguments:
|
||||||
|
raise ValueError("Options object and extra arguments!")
|
||||||
|
|
||||||
logging.info(f"Extracting from file: {self.filepath}")
|
logging.info(f"Extracting from file: {self.filepath}")
|
||||||
python_files = []
|
python_files = []
|
||||||
@@ -222,9 +287,9 @@ class DynamoFile(File):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
FileNotFoundError: The file does not exist
|
FileNotFoundError: The file does not exist
|
||||||
DynamoFileException: If the file is a Dynamo 1 file
|
DynamoFile.Error: If the file is a Dynamo 1 file
|
||||||
json.JSONDecodeError: If there are any other problem with the file
|
json.JSONDecodeError: If there are any other problem with the file
|
||||||
PythonNodeNotFoundException: No python nodes in the file
|
DynamoFile.PythonNodeNotFound: No python nodes in the file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
@@ -242,7 +307,7 @@ class DynamoFile(File):
|
|||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
with open(self.filepath, "r", encoding="utf-8") as input_json:
|
with open(self.filepath, "r", encoding="utf-8") as input_json:
|
||||||
if input_json.readline().startswith("<Workspace Version="):
|
if input_json.readline().startswith("<Workspace Version="):
|
||||||
raise DynamoFileException("This is a Dynamo 1 file!")
|
raise self.Error("This is a Dynamo 1 file!", self)
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@@ -257,8 +322,8 @@ class DynamoFile(File):
|
|||||||
node_views = self.full_dict["View"]["NodeViews"]
|
node_views = self.full_dict["View"]["NodeViews"]
|
||||||
|
|
||||||
if not full_python_nodes:
|
if not full_python_nodes:
|
||||||
raise PythonNodeNotFoundException(
|
raise self.PythonNodeNotFound(
|
||||||
"No python nodes in this file!")
|
"No python nodes in this file!", self, "")
|
||||||
|
|
||||||
self.python_nodes = set()
|
self.python_nodes = set()
|
||||||
|
|
||||||
@@ -279,7 +344,7 @@ class DynamoFile(File):
|
|||||||
PythonNode: The PythonNode with the given id
|
PythonNode: The PythonNode with the given id
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
PythonNodeNotFoundException: No python node with this id
|
DynamoFile.PythonNodeNotFound: No python node with this id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
python_node = next((
|
python_node = next((
|
||||||
@@ -287,8 +352,8 @@ class DynamoFile(File):
|
|||||||
), None)
|
), None)
|
||||||
|
|
||||||
if not python_node:
|
if not python_node:
|
||||||
raise PythonNodeNotFoundException(
|
raise self.PythonNodeNotFound(
|
||||||
f"Node not found with id {node_id}")
|
"Node not found", self, node_id)
|
||||||
|
|
||||||
return python_node
|
return python_node
|
||||||
|
|
||||||
@@ -299,7 +364,7 @@ class DynamoFile(File):
|
|||||||
python_node (PythonNode): The new node
|
python_node (PythonNode): The new node
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
PythonNodeNotFoundException: Existing node not found
|
DynamoFile.PythonNodeNotFound: Existing node not found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Find the old node:
|
# Find the old node:
|
||||||
@@ -309,8 +374,9 @@ class DynamoFile(File):
|
|||||||
n for n in self.full_dict["Nodes"] if n["Id"] == python_node.id
|
n for n in self.full_dict["Nodes"] if n["Id"] == python_node.id
|
||||||
), {})
|
), {})
|
||||||
|
|
||||||
if not node_dict or not python_node_in_file:
|
if not node_dict:
|
||||||
raise PythonNodeNotFoundException()
|
raise self.PythonNodeNotFound(
|
||||||
|
"Existing node not found in file", self, python_node.id)
|
||||||
|
|
||||||
# Remove the old and add the new:
|
# Remove the old and add the new:
|
||||||
self.python_nodes.remove(python_node_in_file)
|
self.python_nodes.remove(python_node_in_file)
|
||||||
@@ -326,17 +392,24 @@ class DynamoFile(File):
|
|||||||
with open(self.filepath, "w", encoding="utf-8", newline="") as output_file:
|
with open(self.filepath, "w", encoding="utf-8", newline="") as output_file:
|
||||||
json.dump(self.full_dict, output_file, indent=2, use_decimal=True)
|
json.dump(self.full_dict, output_file, indent=2, use_decimal=True)
|
||||||
|
|
||||||
def get_related_python_files(self, options: Options | None = None) -> list[PythonFile]:
|
def get_related_python_files(self, options: Options | None = None, **option_args) -> list[PythonFile]:
|
||||||
"""Get python files exported from this Dynamo file
|
"""Get python files exported from this Dynamo file
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
options (Options | None, optional): Run options. Defaults to None.
|
options (Options | None, optional): Run options. Defaults to None.
|
||||||
|
**option_args: Options() arguments
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Both options and other arguments given
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[PythonFile]: A list of PythonFile objects
|
list[PythonFile]: A list of PythonFile objects
|
||||||
"""
|
"""
|
||||||
if not options:
|
if not options:
|
||||||
options = Options()
|
options = Options.from_kwargs(kwargs=option_args)
|
||||||
|
elif option_args:
|
||||||
|
# Should not give both options and arguments:
|
||||||
|
raise ValueError("Options object and extra arguments!")
|
||||||
|
|
||||||
# Find the folder of the python files
|
# Find the folder of the python files
|
||||||
if options.python_folder:
|
if options.python_folder:
|
||||||
@@ -361,11 +434,24 @@ class DynamoFile(File):
|
|||||||
Returns:
|
Returns:
|
||||||
DynamoFile: The file. None if not found
|
DynamoFile: The file. None if not found
|
||||||
"""
|
"""
|
||||||
f = next((d for d in DynamoFile.open_files if d.uuid == uuid), None)
|
f = next((d for d in DynamoFile.get_open_files() if d.uuid == uuid), None)
|
||||||
if f:
|
if f:
|
||||||
logging.debug(f"Found open file {f.uuid}")
|
logging.debug(f"Found open file {f.uuid}")
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
class PythonNodeNotFound(Exception):
|
||||||
|
def __init__(self, message: str, file: DynamoFile, node_id: str) -> None:
|
||||||
|
"""Python node not found with this id
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message (str): The message to display
|
||||||
|
file (DynamoFile): The problem DynamoFile
|
||||||
|
node_id (str): The missing id
|
||||||
|
"""
|
||||||
|
super().__init__(message)
|
||||||
|
self.file = file
|
||||||
|
self.node_id = node_id
|
||||||
|
|
||||||
|
|
||||||
class PythonFile(File):
|
class PythonFile(File):
|
||||||
"""A Python file, subclass of File()"""
|
"""A Python file, subclass of File()"""
|
||||||
@@ -377,9 +463,6 @@ class PythonFile(File):
|
|||||||
text: str
|
text: str
|
||||||
"""Full contents of the file."""
|
"""Full contents of the file."""
|
||||||
|
|
||||||
open_files: set[PythonFile] = set()
|
|
||||||
"""A set of open Python files."""
|
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
filepath: pathlib.Path | str,
|
filepath: pathlib.Path | str,
|
||||||
dynamo_file: DynamoFile | None = None,
|
dynamo_file: DynamoFile | None = None,
|
||||||
@@ -403,10 +486,11 @@ class PythonFile(File):
|
|||||||
"Do not edit this section, if you want to update the Dynamo graph!"
|
"Do not edit this section, if you want to update the Dynamo graph!"
|
||||||
])
|
])
|
||||||
|
|
||||||
# Double escape path:
|
# Calculate relative path, change to forward slash
|
||||||
dyn_path_string = str(dynamo_file.realpath)
|
dyn_path_string = os.path.relpath(
|
||||||
|
dynamo_file.filepath, self.dirpath)
|
||||||
if "\\" in dyn_path_string:
|
if "\\" in dyn_path_string:
|
||||||
dyn_path_string = dyn_path_string.replace("\\", "\\\\")
|
dyn_path_string = dyn_path_string.replace("\\", "/")
|
||||||
|
|
||||||
self.header_data = {
|
self.header_data = {
|
||||||
"dyn2py_version": METADATA["Version"],
|
"dyn2py_version": METADATA["Version"],
|
||||||
@@ -451,7 +535,7 @@ class PythonFile(File):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
FileNotFoundError: The file does not exist
|
FileNotFoundError: The file does not exist
|
||||||
PythonFileException: Some error reading the file
|
PythonFile.Error: Some error reading the file
|
||||||
"""
|
"""
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
raise FileNotFoundError
|
raise FileNotFoundError
|
||||||
@@ -486,7 +570,7 @@ class PythonFile(File):
|
|||||||
# Find the location of the separator
|
# Find the location of the separator
|
||||||
sl = line.find(":")
|
sl = line.find(":")
|
||||||
if sl == -1:
|
if sl == -1:
|
||||||
raise PythonFileException("Error reading header!")
|
raise self.Error("Error reading header!", self)
|
||||||
self.header_data[line[0:sl]] = line[sl+1:]
|
self.header_data[line[0:sl]] = line[sl+1:]
|
||||||
|
|
||||||
self.code = python_lines[code_start_line:]
|
self.code = python_lines[code_start_line:]
|
||||||
@@ -495,15 +579,23 @@ class PythonFile(File):
|
|||||||
logging.debug(f"Header data from python file: {self.header_data}")
|
logging.debug(f"Header data from python file: {self.header_data}")
|
||||||
# logging.debug(f"Code from python file: {self.code}")
|
# logging.debug(f"Code from python file: {self.code}")
|
||||||
|
|
||||||
def update_dynamo(self, options: Options | None = None) -> None:
|
def update_dynamo(self, options: Options | None = None, **option_args) -> None:
|
||||||
"""Update a the source Dynamo graph from this python script
|
"""Update a the source Dynamo graph from this python script
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
options (Options | None, optional): Run options. Defaults to None.
|
options (Options | None, optional): Run options. Defaults to None.
|
||||||
|
**option_args: Options() arguments
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Both options and other arguments given
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
options = Options()
|
options = Options.from_kwargs(kwargs=option_args)
|
||||||
|
elif option_args:
|
||||||
|
# Should not give both options and arguments:
|
||||||
|
raise ValueError("Options object and extra arguments!")
|
||||||
|
|
||||||
dynamo_file = self.get_source_dynamo_file()
|
dynamo_file = self.get_source_dynamo_file()
|
||||||
|
|
||||||
@@ -528,7 +620,7 @@ class PythonFile(File):
|
|||||||
"""Get the source Dynamo file of this PythonFile
|
"""Get the source Dynamo file of this PythonFile
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
DynamoFileException: The uuid of the dynamo file changed
|
DynamoFile.Error: The uuid of the dynamo file changed
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
DynamoFile: The DynamoFile
|
DynamoFile: The DynamoFile
|
||||||
@@ -541,12 +633,21 @@ class PythonFile(File):
|
|||||||
# Open if it's the first time:
|
# Open if it's the first time:
|
||||||
if not dynamo_file:
|
if not dynamo_file:
|
||||||
|
|
||||||
dynamo_file = DynamoFile(
|
cwd = pathlib.Path(os.getcwd()).resolve()
|
||||||
pathlib.Path(self.header_data["dyn_path"]))
|
# Change to pythonfiles' dir:
|
||||||
|
os.chdir(self.dirpath)
|
||||||
|
|
||||||
|
dynpath = os.path.realpath(self.header_data["dyn_path"])
|
||||||
|
logging.debug(f"Resolved path: {dynpath}")
|
||||||
|
|
||||||
|
# Change back to the original path:
|
||||||
|
os.chdir(cwd)
|
||||||
|
dynamo_file = DynamoFile(pathlib.Path(dynpath))
|
||||||
|
|
||||||
# Check if uuid is ok:
|
# Check if uuid is ok:
|
||||||
if not dynamo_file.uuid == self.header_data["dyn_uuid"]:
|
if not dynamo_file.uuid == self.header_data["dyn_uuid"]:
|
||||||
raise DynamoFileException(f"Dynamo graph uuid changed!")
|
raise DynamoFile.Error(
|
||||||
|
"Dynamo graph uuid changed!", dynamo_file)
|
||||||
|
|
||||||
return dynamo_file
|
return dynamo_file
|
||||||
|
|
||||||
@@ -587,7 +688,7 @@ class PythonNode():
|
|||||||
python_file (PythonFile, optional): The python file to be converted to node. Defaults to None.
|
python_file (PythonFile, optional): The python file to be converted to node. Defaults to None.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
PythonNodeException: Wrong arguments were given
|
PythonNode.Error: Wrong arguments were given
|
||||||
"""
|
"""
|
||||||
# Initialize from dynamo file:
|
# Initialize from dynamo file:
|
||||||
if node_dict_from_dyn and dynamo_file and not python_file:
|
if node_dict_from_dyn and dynamo_file and not python_file:
|
||||||
@@ -627,9 +728,19 @@ class PythonNode():
|
|||||||
self.filename = python_file.basename + ".py"
|
self.filename = python_file.basename + ".py"
|
||||||
self.filepath = python_file.filepath
|
self.filepath = python_file.filepath
|
||||||
|
|
||||||
|
elif python_file and node_dict_from_dyn and dynamo_file:
|
||||||
|
raise self.Error("Too much arguments given!")
|
||||||
|
|
||||||
|
elif not python_file and not node_dict_from_dyn and not dynamo_file:
|
||||||
|
raise self.Error("No arguments given!")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise PythonNodeException
|
raise self.Error("Something wrong!")
|
||||||
|
|
||||||
# Calculate checksum:
|
# Calculate checksum:
|
||||||
checksums = [hashlib.md5(l.encode()).hexdigest() for l in self.code]
|
checksums = [hashlib.md5(l.encode()).hexdigest() for l in self.code]
|
||||||
self.checksum = hashlib.md5("".join(checksums).encode()).hexdigest()
|
self.checksum = hashlib.md5("".join(checksums).encode()).hexdigest()
|
||||||
|
|
||||||
|
class Error(Exception):
|
||||||
|
"""Something wrong with this node"""
|
||||||
|
pass
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import argparse
|
|||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
LOGLEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
|
LOGLEVELS = ["HEADLESS", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
|
||||||
DEFAULT_LOGLEVEL = "INFO"
|
DEFAULT_LOGLEVEL = "INFO"
|
||||||
FILTERS = ["py", "dyn"]
|
FILTERS = ["py", "dyn"]
|
||||||
|
|
||||||
@@ -26,16 +26,13 @@ class Options(argparse.Namespace):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
source (list[pathlib.Path | str], optional): List of files to run on. Defaults to [].
|
source (list[pathlib.Path | str], optional): List of files to run on. Defaults to [].
|
||||||
loglevel (str, optional): log level. Defaults to DEFAULT_LOGLEVEL.
|
loglevel (str, optional): Log level. Defaults to DEFAULT_LOGLEVEL.
|
||||||
dry_run (bool, optional): If it's a dry run. Defaults to False.
|
dry_run (bool, optional): Dry run, do not save files. Defaults to False.
|
||||||
force (bool, optional): Overwrite files, even if they are older. Defaults to False.
|
force (bool, optional): Overwrite files, even if they are older. Defaults to False.
|
||||||
backup (bool, optional): Create backup of modified files. Defaults to False.
|
backup (bool, optional): Create backup of modified files. Defaults to False.
|
||||||
filter (str, optional): 'dyn' or 'py' file filter for running on folders. Defaults to "".
|
filter (str, optional): 'dyn' or 'py' file filter for running on folders. Defaults to "".
|
||||||
update (bool, optional): Update mode, like inverse on Dynamo files. Defaults to False.
|
update (bool, optional): Update mode, like inverse on Dynamo files. Defaults to False.
|
||||||
python_folder (pathlib.Path | str | None, optional): Path to export python files to, or import from there. Defaults to None.
|
python_folder (pathlib.Path | str | None, optional): Path to export python files to, or import from there. Defaults to None.
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: If loglevel or filter is invalid
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.source = []
|
self.source = []
|
||||||
@@ -45,23 +42,58 @@ class Options(argparse.Namespace):
|
|||||||
else:
|
else:
|
||||||
self.source.append(s)
|
self.source.append(s)
|
||||||
|
|
||||||
if loglevel.upper() in LOGLEVELS:
|
self.loglevel = self.sanitize_option_string("loglevel", loglevel)
|
||||||
self.loglevel = loglevel.upper()
|
|
||||||
else:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
self.force = force
|
self.force = force
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
|
self.filter = self.sanitize_option_string("filter", filter)
|
||||||
if not filter or filter in FILTERS:
|
|
||||||
self.filter = filter
|
|
||||||
else:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
self.update = update
|
self.update = update
|
||||||
|
|
||||||
if isinstance(python_folder, str):
|
if isinstance(python_folder, str):
|
||||||
self.python_folder = pathlib.Path(python_folder)
|
self.python_folder = pathlib.Path(python_folder)
|
||||||
else:
|
else:
|
||||||
self.python_folder = python_folder
|
self.python_folder = python_folder
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def sanitize_option_string(arg: str, value: str) -> str:
|
||||||
|
"""Sanitize string option values
|
||||||
|
|
||||||
|
Args:
|
||||||
|
arg (str): The name of the argument
|
||||||
|
value (str): The value
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: if the value is invalid
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The correct string
|
||||||
|
"""
|
||||||
|
|
||||||
|
if arg == "loglevel":
|
||||||
|
if value.upper() in LOGLEVELS:
|
||||||
|
sanitized_value = value.upper()
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid loglevel!")
|
||||||
|
elif arg == "filter":
|
||||||
|
if not value or value in FILTERS:
|
||||||
|
sanitized_value = value
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid filter!")
|
||||||
|
else:
|
||||||
|
sanitized_value = value
|
||||||
|
|
||||||
|
return sanitized_value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_kwargs(cls, **kwargs) -> Options:
|
||||||
|
"""Initialize an Options object from kwargs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Options: The initialized object
|
||||||
|
"""
|
||||||
|
o = cls()
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if isinstance(value, str):
|
||||||
|
value = cls.sanitize_option_string(key, value)
|
||||||
|
setattr(o, key, value)
|
||||||
|
return o
|
||||||
|
|||||||
27
pre-commit
Normal file
27
pre-commit
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Create a list of files from staged files:
|
||||||
|
mapfile -t NEW_FILES <<<$(git diff --name-only --cached)
|
||||||
|
|
||||||
|
# Go through staged files:
|
||||||
|
for f in "${NEW_FILES[@]}"; do
|
||||||
|
|
||||||
|
# Export python files, only from Dynamo files.
|
||||||
|
# On Windows line ending is always CRLF, so remove CR with tr.
|
||||||
|
mapfile -t PY_FILES <<<$(dyn2py --force --filter dyn --loglevel HEADLESS "$f" | tr -d "\r")
|
||||||
|
|
||||||
|
# Check if something was exported:
|
||||||
|
if [[ "${PY_FILES[@]}" ]]; then
|
||||||
|
|
||||||
|
# Go through exported files:
|
||||||
|
for p in "${PY_FILES[@]}"; do
|
||||||
|
|
||||||
|
# Check if file exists:
|
||||||
|
if [ -f "$p" ]; then
|
||||||
|
|
||||||
|
# Stage file:
|
||||||
|
git add "$p"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "dyn2py"
|
name = "dyn2py"
|
||||||
version = "0.3.1"
|
version = "0.3.3"
|
||||||
description = "Extract python code from Dynamo graphs"
|
description = "Extract python code from Dynamo graphs"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.8"
|
requires-python = ">=3.8"
|
||||||
@@ -34,3 +34,6 @@ dyn2py = "dyn2py:__command_line"
|
|||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools", "wheel"]
|
requires = ["setuptools", "wheel"]
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
packages = ["dyn2py"]
|
||||||
|
|||||||
@@ -3,15 +3,17 @@ import dyn2py
|
|||||||
|
|
||||||
INPUT_DIR = "tests/input_files"
|
INPUT_DIR = "tests/input_files"
|
||||||
OUTPUT_DIR = "tests/output_files"
|
OUTPUT_DIR = "tests/output_files"
|
||||||
|
TEMP_DIR = "tests/temp_files"
|
||||||
|
|
||||||
|
|
||||||
def cleanup_output_dir():
|
def cleanup_dirs():
|
||||||
output_dir = pathlib.Path(OUTPUT_DIR)
|
for p in [OUTPUT_DIR, TEMP_DIR]:
|
||||||
if output_dir.exists():
|
the_dir = pathlib.Path(p)
|
||||||
for f in output_dir.iterdir():
|
if the_dir.exists():
|
||||||
|
for f in the_dir.iterdir():
|
||||||
f.unlink()
|
f.unlink()
|
||||||
else:
|
else:
|
||||||
output_dir.mkdir()
|
the_dir.mkdir()
|
||||||
|
|
||||||
|
|
||||||
def extract_single_node_dyn(modify_py: bool = False):
|
def extract_single_node_dyn(modify_py: bool = False):
|
||||||
@@ -23,7 +25,7 @@ def extract_single_node_dyn(modify_py: bool = False):
|
|||||||
modify_py (bool, optional): Also do some changes on the exported file. Defaults to False.
|
modify_py (bool, optional): Also do some changes on the exported file. Defaults to False.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
# Extract py:
|
# Extract py:
|
||||||
options = dyn2py.Options(python_folder=OUTPUT_DIR)
|
options = dyn2py.Options(python_folder=OUTPUT_DIR)
|
||||||
@@ -31,8 +33,7 @@ def extract_single_node_dyn(modify_py: bool = False):
|
|||||||
pythonfiles = dyn.extract_python(options)
|
pythonfiles = dyn.extract_python(options)
|
||||||
pythonfiles[0].write()
|
pythonfiles[0].write()
|
||||||
|
|
||||||
dyn2py.PythonFile.open_files.clear()
|
dyn2py.File.open_files.clear()
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
|
||||||
|
|
||||||
if modify_py:
|
if modify_py:
|
||||||
# Open the extracted file and replace a string:
|
# Open the extracted file and replace a string:
|
||||||
|
|||||||
@@ -36,8 +36,12 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
self.assertFalse(p.stderr)
|
self.assertFalse(p.stderr)
|
||||||
|
|
||||||
dyn_sources = [
|
dyn_sources = [
|
||||||
{"filename": "python_nodes.dyn", "py_file_count": 6},
|
{"filename": "python_nodes.dyn", "output_file_count": 6},
|
||||||
{"filename": "single_node.dyn", "py_file_count": 1}
|
{"filename": "single_node.dyn", "output_file_count": 1}
|
||||||
|
]
|
||||||
|
|
||||||
|
py_sources = [
|
||||||
|
{"filename": "single_node_mod.py"},
|
||||||
]
|
]
|
||||||
|
|
||||||
dyn_sources_error = ["dynamo1file.dyn",
|
dyn_sources_error = ["dynamo1file.dyn",
|
||||||
@@ -46,6 +50,15 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_command(args: list = []) -> dict:
|
def run_command(args: list = []) -> dict:
|
||||||
|
"""_summary_
|
||||||
|
|
||||||
|
Args:
|
||||||
|
args (list, optional): list of arguments to run. Defaults to [].
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict["stderr"]: error message
|
||||||
|
dict["python_file_mtimes"]: exported file in the output dir, and modification times
|
||||||
|
"""
|
||||||
argstring = " ".join(args)
|
argstring = " ".join(args)
|
||||||
process = subprocess.run(f"dyn2py -l WARNING {argstring}",
|
process = subprocess.run(f"dyn2py -l WARNING {argstring}",
|
||||||
capture_output=True, shell=True)
|
capture_output=True, shell=True)
|
||||||
@@ -76,7 +89,7 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
|
|
||||||
test_dicts[0]["filenames"] = [
|
test_dicts[0]["filenames"] = [
|
||||||
test_dicts[0]["filename"]]
|
test_dicts[0]["filename"]]
|
||||||
if i == 0:
|
if i == 0 and len(source_dict) > 1:
|
||||||
# Create a multi file version on the first file:
|
# Create a multi file version on the first file:
|
||||||
d = {}
|
d = {}
|
||||||
for key in source_dict:
|
for key in source_dict:
|
||||||
@@ -91,7 +104,7 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
for test_dict in test_dicts:
|
for test_dict in test_dicts:
|
||||||
|
|
||||||
if pfolder_option:
|
if pfolder_option:
|
||||||
file_dir = INPUT_DIR
|
file_dir = TEMP_DIR
|
||||||
pfolder_arg = f"{pfolder_option} {OUTPUT_DIR}"
|
pfolder_arg = f"{pfolder_option} {OUTPUT_DIR}"
|
||||||
else:
|
else:
|
||||||
file_dir = OUTPUT_DIR
|
file_dir = OUTPUT_DIR
|
||||||
@@ -113,7 +126,7 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
def test_dyn_error(self):
|
def test_dyn_error(self):
|
||||||
for s in self.dyn_sources_error:
|
for s in self.dyn_sources_error:
|
||||||
|
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
if pathlib.Path(f"{INPUT_DIR}/{s}").exists():
|
if pathlib.Path(f"{INPUT_DIR}/{s}").exists():
|
||||||
shutil.copy(f"{INPUT_DIR}/{s}",
|
shutil.copy(f"{INPUT_DIR}/{s}",
|
||||||
@@ -131,29 +144,40 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
dyn_tests = self.generate_test_args(self.dyn_sources)
|
dyn_tests = self.generate_test_args(self.dyn_sources)
|
||||||
|
|
||||||
for s in dyn_tests:
|
for s in dyn_tests:
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
|
# if no pythonfolder, everything should be in output ddir
|
||||||
if not s["pfolder_arg"]:
|
if not s["pfolder_arg"]:
|
||||||
|
source_dir = OUTPUT_DIR
|
||||||
|
else:
|
||||||
|
source_dir = TEMP_DIR
|
||||||
|
|
||||||
|
# copy source files:
|
||||||
for filename in s["filenames"]:
|
for filename in s["filenames"]:
|
||||||
shutil.copy(f"{INPUT_DIR}/{filename}",
|
shutil.copy(f"{INPUT_DIR}/{filename}",
|
||||||
f"{OUTPUT_DIR}/{filename}")
|
f"{source_dir}/{filename}")
|
||||||
|
|
||||||
|
|
||||||
|
# Open files normally
|
||||||
file_open = self.run_command(
|
file_open = self.run_command(
|
||||||
[s["pfolder_arg"], s['filepath']])
|
[s["pfolder_arg"], s['filepath']])
|
||||||
|
|
||||||
|
# Open without error:
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
bool(file_open["stderr"]), msg=file_open["stderr"])
|
bool(file_open["stderr"]), msg=file_open["stderr"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(file_open["python_file_mtimes"]), s["py_file_count"])
|
len(file_open["python_file_mtimes"]), s["output_file_count"])
|
||||||
|
|
||||||
# Test no overwrite
|
# Test no overwrite
|
||||||
file_no_overwrite = self.run_command(
|
file_no_overwrite = self.run_command(
|
||||||
[s["pfolder_arg"], s['filepath']])
|
[s["pfolder_arg"], s['filepath']])
|
||||||
|
|
||||||
|
# Should give error, because they already exist:
|
||||||
self.assertTrue(bool(file_no_overwrite["stderr"]))
|
self.assertTrue(bool(file_no_overwrite["stderr"]))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(file_no_overwrite["python_file_mtimes"]), s["py_file_count"])
|
len(file_no_overwrite["python_file_mtimes"]), s["output_file_count"])
|
||||||
|
|
||||||
|
# The modify time shouldn't change as they were not overwritten:
|
||||||
for p in file_no_overwrite["python_file_mtimes"]:
|
for p in file_no_overwrite["python_file_mtimes"]:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
file_no_overwrite["python_file_mtimes"][p], file_open["python_file_mtimes"][p])
|
file_no_overwrite["python_file_mtimes"][p], file_open["python_file_mtimes"][p])
|
||||||
@@ -162,10 +186,12 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
file_force = self.run_command(
|
file_force = self.run_command(
|
||||||
[s["pfolder_arg"], s["force_arg"], s['filepath']])
|
[s["pfolder_arg"], s["force_arg"], s['filepath']])
|
||||||
|
|
||||||
|
# Should not have an error:
|
||||||
self.assertFalse(bool(file_force["stderr"]))
|
self.assertFalse(bool(file_force["stderr"]))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(file_force["python_file_mtimes"]), s["py_file_count"])
|
len(file_force["python_file_mtimes"]), s["output_file_count"])
|
||||||
|
|
||||||
|
# Modify time should be higher as they were replaced
|
||||||
for p in file_force["python_file_mtimes"]:
|
for p in file_force["python_file_mtimes"]:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
file_force["python_file_mtimes"][p] > file_open["python_file_mtimes"][p]
|
file_force["python_file_mtimes"][p] > file_open["python_file_mtimes"][p]
|
||||||
@@ -178,18 +204,52 @@ class TestCommandLine(unittest.TestCase):
|
|||||||
self.assertFalse(bool(file_backup["stderr"]))
|
self.assertFalse(bool(file_backup["stderr"]))
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(file_backup["python_file_mtimes"]), s["py_file_count"] * 2)
|
len(file_backup["python_file_mtimes"]
|
||||||
|
), s["output_file_count"] * 2,
|
||||||
|
msg=f""
|
||||||
|
)
|
||||||
|
|
||||||
for p in file_force["python_file_mtimes"]:
|
for p in file_force["python_file_mtimes"]:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
file_backup["python_file_mtimes"][p] > file_force["python_file_mtimes"][p]
|
file_backup["python_file_mtimes"][p] > file_force["python_file_mtimes"][p]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# def test_py(self):
|
||||||
|
# py_tests = self.generate_test_args(self.py_sources)
|
||||||
|
|
||||||
|
# # TODO add more python files!
|
||||||
|
# self.assertEqual(len(py_tests), 1)
|
||||||
|
|
||||||
|
# for s in py_tests:
|
||||||
|
# cleanup_dirs()
|
||||||
|
|
||||||
|
# extract_single_node_dyn(modify_py=True)
|
||||||
|
|
||||||
|
|
||||||
|
# # if pythonfolder, python should be in the temp folder:
|
||||||
|
# if s["pfolder_arg"]:
|
||||||
|
# for filename in s["filenames"]:
|
||||||
|
# shutil.move(f"{OUTPUT_DIR}/{filename}",
|
||||||
|
# f"{TEMP_DIR}/{filename}")
|
||||||
|
|
||||||
|
# # Open files normally
|
||||||
|
# file_open = self.run_command(
|
||||||
|
# [s["pfolder_arg"], s['filepath']])
|
||||||
|
|
||||||
|
|
||||||
|
# # Open without error:
|
||||||
|
# self.assertFalse(
|
||||||
|
# bool(file_open["stderr"]), msg=file_open["stderr"])
|
||||||
|
# self.assertEqual(
|
||||||
|
# len(file_open["python_file_mtimes"]), s["output_file_count"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_single_dyn_dryrun(self):
|
def test_single_dyn_dryrun(self):
|
||||||
for s in self.dyn_sources:
|
for s in self.dyn_sources:
|
||||||
for arg in ["-n", "--dry-run"]:
|
for arg in ["-n", "--dry-run"]:
|
||||||
|
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
shutil.copy(f"{INPUT_DIR}/{s['filename']}",
|
shutil.copy(f"{INPUT_DIR}/{s['filename']}",
|
||||||
f"{OUTPUT_DIR}/{s['filename']}")
|
f"{OUTPUT_DIR}/{s['filename']}")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
self.assertTrue(dyn in dyn2py.DynamoFile.open_files)
|
self.assertTrue(dyn in dyn2py.DynamoFile.open_files)
|
||||||
|
|
||||||
# Dynamo 1 file:
|
# Dynamo 1 file:
|
||||||
with self.assertRaises(dyn2py.DynamoFileException):
|
with self.assertRaises(dyn2py.DynamoFile.Error):
|
||||||
dyn1 = dyn2py.DynamoFile(f"{INPUT_DIR}/dynamo1file.dyn")
|
dyn1 = dyn2py.DynamoFile(f"{INPUT_DIR}/dynamo1file.dyn")
|
||||||
|
|
||||||
# Not existing file:
|
# Not existing file:
|
||||||
@@ -27,7 +27,7 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
dyn2 = dyn2py.DynamoFile(f"{INPUT_DIR}/not_existing.dyn")
|
dyn2 = dyn2py.DynamoFile(f"{INPUT_DIR}/not_existing.dyn")
|
||||||
|
|
||||||
# No python nodes:
|
# No python nodes:
|
||||||
with self.assertRaises(dyn2py.PythonNodeNotFoundException):
|
with self.assertRaises(dyn2py.DynamoFile.PythonNodeNotFound):
|
||||||
dyn2 = dyn2py.DynamoFile(f"{INPUT_DIR}/no_python.dyn")
|
dyn2 = dyn2py.DynamoFile(f"{INPUT_DIR}/no_python.dyn")
|
||||||
|
|
||||||
def test_get_python_nodes(self):
|
def test_get_python_nodes(self):
|
||||||
@@ -39,21 +39,20 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
self.assertIn(py_node, dyn.python_nodes)
|
self.assertIn(py_node, dyn.python_nodes)
|
||||||
self.assertEqual(py_node.checksum, "e830a6ae6b395bcfd4e5a40da48f3bfc")
|
self.assertEqual(py_node.checksum, "e830a6ae6b395bcfd4e5a40da48f3bfc")
|
||||||
|
|
||||||
with self.assertRaises(dyn2py.PythonNodeNotFoundException):
|
with self.assertRaises(dyn2py.DynamoFile.PythonNodeNotFound):
|
||||||
dyn.get_python_node_by_id("wrongid")
|
dyn.get_python_node_by_id("wrongid")
|
||||||
|
|
||||||
def test_extract_python(self):
|
def test_extract_python(self):
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
dyn2py.PythonFile.open_files.clear()
|
dyn2py.PythonFile.open_files.clear()
|
||||||
|
|
||||||
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
||||||
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
||||||
dyn.extract_python(options=opt)
|
dyn.extract_python(options=opt)
|
||||||
|
|
||||||
self.assertEqual(len(dyn2py.PythonFile.open_files), 6)
|
self.assertEqual(len(dyn2py.PythonFile.get_open_files()), 6)
|
||||||
|
|
||||||
for f in dyn2py.PythonFile.open_files:
|
dyn2py.PythonFile.write_open_files()
|
||||||
f.write()
|
|
||||||
|
|
||||||
output_dir = pathlib.Path(OUTPUT_DIR)
|
output_dir = pathlib.Path(OUTPUT_DIR)
|
||||||
self.assertEqual(len(list(output_dir.iterdir())), 6)
|
self.assertEqual(len(list(output_dir.iterdir())), 6)
|
||||||
@@ -70,7 +69,7 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
dyn2py.DynamoFile.get_open_file_by_uuid("76de5c79-17c5-4c74-9f90-ad99a213d339"))
|
dyn2py.DynamoFile.get_open_file_by_uuid("76de5c79-17c5-4c74-9f90-ad99a213d339"))
|
||||||
|
|
||||||
def test_get_related_python_files(self):
|
def test_get_related_python_files(self):
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
||||||
dyn1 = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
dyn1 = dyn2py.DynamoFile(f"{INPUT_DIR}/python_nodes.dyn")
|
||||||
@@ -92,7 +91,7 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
self.assertFalse(no_python_files)
|
self.assertFalse(no_python_files)
|
||||||
|
|
||||||
def test_write_same(self):
|
def test_write_same(self):
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
|
|
||||||
shutil.copy(f"{INPUT_DIR}/python_nodes.dyn",
|
shutil.copy(f"{INPUT_DIR}/python_nodes.dyn",
|
||||||
f"{OUTPUT_DIR}/python_nodes.dyn")
|
f"{OUTPUT_DIR}/python_nodes.dyn")
|
||||||
@@ -139,6 +138,6 @@ class TestDynamoFile(unittest.TestCase):
|
|||||||
self.assertTrue(node2)
|
self.assertTrue(node2)
|
||||||
self.assertEqual(node1.checksum, node2.checksum)
|
self.assertEqual(node1.checksum, node2.checksum)
|
||||||
|
|
||||||
with self.assertRaises(dyn2py.PythonNodeNotFoundException):
|
with self.assertRaises(dyn2py.DynamoFile.PythonNodeNotFound):
|
||||||
node2.id = "wrong_id"
|
node2.id = "wrong_id"
|
||||||
dyn2.update_python_node(node2)
|
dyn2.update_python_node(node2)
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ from tests.support import *
|
|||||||
|
|
||||||
class TestFile(unittest.TestCase):
|
class TestFile(unittest.TestCase):
|
||||||
|
|
||||||
# Write methods should be tested in subclasses!
|
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
paths = [
|
paths = [
|
||||||
f"{INPUT_DIR}/python_nodes.dyn",
|
f"{INPUT_DIR}/python_nodes.dyn",
|
||||||
@@ -71,7 +69,7 @@ class TestFile(unittest.TestCase):
|
|||||||
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.py")
|
nonexisting_file = dyn2py.File(f"{INPUT_DIR}/new_file.py")
|
||||||
|
|
||||||
# Extract a python file so it is always newer than the others:
|
# Extract a python file so it is always newer than the others:
|
||||||
cleanup_output_dir()
|
cleanup_dirs()
|
||||||
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
opt = dyn2py.Options(python_folder=OUTPUT_DIR)
|
||||||
older_file.extract_python(options=opt) # type: ignore
|
older_file.extract_python(options=opt) # type: ignore
|
||||||
for f in dyn2py.PythonFile.open_files:
|
for f in dyn2py.PythonFile.open_files:
|
||||||
@@ -103,3 +101,15 @@ class TestFile(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(file.is_dynamo_file(), f == "dyn")
|
self.assertEqual(file.is_dynamo_file(), f == "dyn")
|
||||||
self.assertEqual(file.is_python_file(), f == "py")
|
self.assertEqual(file.is_python_file(), f == "py")
|
||||||
|
|
||||||
|
def test_write(self):
|
||||||
|
|
||||||
|
# new empty file:
|
||||||
|
empty_filepath = pathlib.Path(f"{OUTPUT_DIR}/empty.txt")
|
||||||
|
empty_filepath.touch()
|
||||||
|
|
||||||
|
empty_file = dyn2py.File(f"{OUTPUT_DIR}/empty.txt")
|
||||||
|
|
||||||
|
self.assertTrue(empty_file.exists)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
empty_file.write()
|
||||||
@@ -12,9 +12,10 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
def test_init(self):
|
def test_init(self):
|
||||||
extract_single_node_dyn()
|
extract_single_node_dyn()
|
||||||
|
|
||||||
py1 = dyn2py.PythonFile(f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
dyn2py.File.open_files.clear()
|
||||||
|
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
py1 = dyn2py.PythonFile(
|
||||||
|
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
||||||
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
dyn = dyn2py.DynamoFile(f"{INPUT_DIR}/single_node.dyn")
|
||||||
node = list(dyn.python_nodes)[0]
|
node = list(dyn.python_nodes)[0]
|
||||||
py2 = dyn2py.PythonFile(filepath=node.filepath,
|
py2 = dyn2py.PythonFile(filepath=node.filepath,
|
||||||
@@ -23,9 +24,10 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
for py in [py1, py2]:
|
for py in [py1, py2]:
|
||||||
|
|
||||||
self.assertEqual(len(py.code), 17)
|
self.assertEqual(len(py.code), 17)
|
||||||
self.assertEqual(len(py.text.split(os.linesep)), 32, msg=py.filepath)
|
self.assertEqual(len(py.text.split(os.linesep)),
|
||||||
|
32, msg=py.filepath)
|
||||||
self.assertIs(type(py.header_data), dict)
|
self.assertIs(type(py.header_data), dict)
|
||||||
self.assertTrue(py in dyn2py.PythonFile.open_files)
|
self.assertTrue(py in dyn2py.PythonFile.get_open_files())
|
||||||
|
|
||||||
def test_update_dynamo(self):
|
def test_update_dynamo(self):
|
||||||
extract_single_node_dyn(modify_py=True)
|
extract_single_node_dyn(modify_py=True)
|
||||||
@@ -68,14 +70,13 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_source_dynamo_file(self):
|
def test_get_source_dynamo_file(self):
|
||||||
extract_single_node_dyn()
|
extract_single_node_dyn()
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
dyn2py.File.open_files.clear()
|
||||||
dyn2py.PythonFile.open_files.clear()
|
|
||||||
|
|
||||||
py1 = dyn2py.PythonFile(
|
py1 = dyn2py.PythonFile(
|
||||||
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
||||||
|
|
||||||
dyn1 = py1.get_source_dynamo_file()
|
dyn1 = py1.get_source_dynamo_file()
|
||||||
self.assertEqual(len(dyn2py.DynamoFile.open_files), 1)
|
self.assertEqual(len(dyn2py.DynamoFile.get_open_files()), 1)
|
||||||
self.assertIn(dyn1, dyn2py.DynamoFile.open_files)
|
self.assertIn(dyn1, dyn2py.DynamoFile.open_files)
|
||||||
|
|
||||||
dyn2 = py1.get_source_dynamo_file()
|
dyn2 = py1.get_source_dynamo_file()
|
||||||
@@ -83,14 +84,13 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
|
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
dyn2py.DynamoFile.open_files.clear()
|
||||||
|
|
||||||
with self.assertRaises(dyn2py.DynamoFileException):
|
with self.assertRaises(dyn2py.DynamoFile.Error):
|
||||||
py1.header_data["dyn_uuid"] = "wrong-uuid"
|
py1.header_data["dyn_uuid"] = "wrong-uuid"
|
||||||
py1.get_source_dynamo_file()
|
py1.get_source_dynamo_file()
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
extract_single_node_dyn()
|
extract_single_node_dyn()
|
||||||
dyn2py.DynamoFile.open_files.clear()
|
dyn2py.File.open_files.clear()
|
||||||
dyn2py.PythonFile.open_files.clear()
|
|
||||||
|
|
||||||
py1 = dyn2py.PythonFile(
|
py1 = dyn2py.PythonFile(
|
||||||
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
f"{OUTPUT_DIR}/single_node_1c5d99792882409e97e132b3e9f814b0.py")
|
||||||
@@ -98,7 +98,7 @@ class TestPythonFile(unittest.TestCase):
|
|||||||
dyn1 = py1.get_source_dynamo_file()
|
dyn1 = py1.get_source_dynamo_file()
|
||||||
node = list(dyn1.python_nodes)[0]
|
node = list(dyn1.python_nodes)[0]
|
||||||
py2 = dyn2py.PythonFile(
|
py2 = dyn2py.PythonFile(
|
||||||
node.filepath, dynamo_file=dyn1, python_node=node)
|
f"{OUTPUT_DIR}/{node.filename}", dynamo_file=dyn1, python_node=node)
|
||||||
self.assertIsNot(py1, py2)
|
self.assertIsNot(py1, py2)
|
||||||
self.assertEqual(py1.code, py2.code)
|
self.assertEqual(py1.code, py2.code)
|
||||||
for d in py1.header_data:
|
for d in py1.header_data:
|
||||||
|
|||||||
@@ -48,11 +48,12 @@ class TestPythonNode(unittest.TestCase):
|
|||||||
|
|
||||||
py = dyn2py.PythonFile(f"{OUTPUT_DIR}/single_node_mod.py")
|
py = dyn2py.PythonFile(f"{OUTPUT_DIR}/single_node_mod.py")
|
||||||
|
|
||||||
with self.assertRaises(dyn2py.PythonNodeException):
|
with self.assertRaises(dyn2py.PythonNode.Error):
|
||||||
node1 = dyn2py.PythonNode(
|
node1 = dyn2py.PythonNode(
|
||||||
node_dict_from_dyn=node_dict,
|
node_dict_from_dyn=node_dict,
|
||||||
dynamo_file=dyn,
|
dynamo_file=dyn,
|
||||||
python_file=py
|
python_file=py
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(dyn2py.PythonNode.Error):
|
||||||
node2 = dyn2py.PythonNode()
|
node2 = dyn2py.PythonNode()
|
||||||
|
|||||||
Reference in New Issue
Block a user