mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Compare commits
13 Commits
0.3.1
...
2a6c42829f
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||||
51
.github/workflows/release.yml
vendored
51
.github/workflows/release.yml
vendored
@@ -10,39 +10,29 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
name: Test
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
uses: ./.github/workflows/test.yml
|
uses: ./.github/workflows/test.yml
|
||||||
with:
|
with:
|
||||||
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,26 +41,33 @@ 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
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
name: Setup Python
|
name: Setup Python
|
||||||
with:
|
with:
|
||||||
python-version: ${{ vars.PYTHON_VERSION}}
|
python-version: ${{ vars.PYTHON_VERSION }}
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
|
|||||||
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"
|
||||||
1
.github/workflows/unittests.yml
vendored
1
.github/workflows/unittests.yml
vendored
@@ -11,6 +11,7 @@ permissions:
|
|||||||
|
|
||||||
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
|
||||||
105
README.md
105
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,13 +68,42 @@ 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 graph. 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 check changed lines in a diff tool!
|
||||||
|
|
||||||
### 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:
|
Most basic example to extract all nodes next to a Dynamo file:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import dyn2py
|
import dyn2py
|
||||||
@@ -94,11 +133,27 @@ python_files = dynamo_file.get_related_python_files(options)
|
|||||||
dynamo_file.write(options)
|
dynamo_file.write(options)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## 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
|
||||||
@@ -116,16 +171,42 @@ venv .venv
|
|||||||
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 a publish a git tag with that number
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
GPL-3.0
|
||||||
|
|
||||||
|
|||||||
8
TODO.md
8
TODO.md
@@ -15,16 +15,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
|
||||||
82
dyn2py-installer.iss
Normal file
82
dyn2py-installer.iss
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
[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=yes
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
[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)
|
||||||
@@ -45,6 +45,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 +118,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:
|
||||||
@@ -197,4 +203,7 @@ def run(options: Options) -> None:
|
|||||||
|
|
||||||
# Write files at the end:
|
# Write files at the end:
|
||||||
for f in DynamoFile.open_files | PythonFile.open_files:
|
for f in DynamoFile.open_files | PythonFile.open_files:
|
||||||
f.write(options)
|
try:
|
||||||
|
f.write(options)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.error(f"Cannot save file! {f.filepath}")
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ class File():
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TypeError: If called on a File object
|
TypeError: If called on a File object
|
||||||
|
FileNotFoundError: Target folder does not exist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
@@ -140,14 +141,20 @@ class File():
|
|||||||
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 FileNotFoundError("File dir does not exist!")
|
||||||
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
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|
||||||
|
|||||||
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"]
|
||||||
|
|||||||
Reference in New Issue
Block a user