13 Commits

Author SHA1 Message Date
1e48aa144e Fix installer 2023-03-28 00:53:35 +02:00
233fd5742d Update readme, release workflow 2023-03-28 00:29:13 +02:00
7d1a9e6310 Bump version 2023-03-28 00:22:39 +02:00
7194a335dd Windows installer, reorganize workflows 2023-03-28 00:12:32 +02:00
b3834edaee Windows Installer 2023-03-27 21:59:45 +02:00
14e1a3b7a2 Update Readme 2023-03-27 13:43:38 +02:00
a71979c6ac Update Readme 2023-03-27 13:22:05 +02:00
7ec513feb4 Fix release workflow 2023-03-27 11:49:44 +02:00
f7a2dc2d41 Fix release workflow 2023-03-27 11:39:40 +02:00
025b50ecf3 Fix release workflow 2023-03-27 11:32:53 +02:00
2553d84d91 Update workflows 2023-03-27 11:23:30 +02:00
6ee8c7fe75 Reusable tests 2023-03-27 11:13:38 +02:00
6675c003e7 Update docs, workflows 2023-03-25 22:11:16 +01:00
13 changed files with 383 additions and 61 deletions

28
.github/workflows/build-exe.yml vendored Normal file
View 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

34
.github/workflows/build-installer.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
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: Update version number
run: |
$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
- name: Build installer
run: |
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" -Qp $(Join-Path $PWD.Path dyn2py-installer.iss)
- uses: actions/upload-artifact@v3
name: Upload artifact
with:
name: dyn2py-installer.exe
path: Output/dyn2py-installer.exe

View File

@@ -9,29 +9,72 @@ permissions:
contents: write
jobs:
build-and-release:
runs-on: windows-latest
test:
name: Test
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
uses: ./.github/workflows/test.yml
with:
python-version: ${{ vars.PYTHON_VERSION }}
os: ${{ matrix.os }}
build-exe:
name: Build Windows exe
needs: test
uses: ./.github/workflows/build-exe.yml
build-installer:
name: Build Windows installer
needs: build-exe
uses: ./.github/workflows/build-installer.yml
release:
name: Create Github release
runs-on: ubuntu-latest
needs: build-installer
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Checkout
- name: Generate changelog
id: changelog
uses: metcalfc/changelog-generator@v4.1.0
with:
python-version: "3.11"
- name: Install deps
run: |
python -m pip install --upgrade pip
pip install .[build]
- name: Build
run: pyinstaller dyn2py.spec
- uses: actions/upload-artifact@v3
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Download exe
uses: actions/download-artifact@v3
with:
name: dyn2py.exe
path: dist/dyn2py.exe
- name: Download installer
uses: actions/download-artifact@v3
with:
name: dyn2py-installer.exe
- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/dyn2py.exe
files: |
dyn2py.exe
dyn2py-installer.exe
body: ${{ steps.changelog.outputs.changelog }}
pip:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: test
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 package
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

29
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
on:
workflow_call:
inputs:
python-version:
required: true
type: string
os:
required: true
type: string
name: Workflow - Test
jobs:
test:
name: Run tests
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install deps
run: |
python -m pip install --upgrade pip
pip install .
- name: Run tests
run: python -m unittest discover -v -s ./tests -p "test_*.py"

View File

@@ -11,24 +11,13 @@ permissions:
jobs:
tests:
name: Unit tests
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", 3.11]
runs-on: ${{ matrix.os }}
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: ./.github/workflows/test.yml
with:
python-version: ${{ matrix.python-version }}
- name: Install deps
run: |
python -m pip install --upgrade pip
pip install .
- name: Test
run: python -m unittest discover -v -s ./tests -p "test_*.py"
os: ${{ matrix.os }}

View File

@@ -2,11 +2,9 @@ name: Deploy website
on:
push:
# Only build for tags.
tags:
- "*"
branches:
- main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# security: restrict permissions for CI jobs.
@@ -19,19 +17,22 @@ concurrency:
cancel-in-progress: true
jobs:
# Build the documentation and upload the static HTML files as an artifact.
build:
name: Build documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout
- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: "3.11"
python-version: ${{ vars.PYTHON_VERSION }}
- run: pip install -e .[doc]
name: Install deps
- run: pdoc -d google -o docs dyn2py
name: Generate docs
- uses: actions/upload-pages-artifact@v1
name: Upload artifact
with:
path: docs/
@@ -39,6 +40,7 @@ jobs:
# This is a separate job so that only actions/deploy-pages has the necessary permissions.
deploy:
needs: build
name: Publish documentation
runs-on: ubuntu-latest
permissions:
pages: write
@@ -48,4 +50,5 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
name: Deploy page
uses: actions/deploy-pages@v1

17
.github/workflows/windows-build.yml vendored Normal file
View 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
View File

@@ -6,3 +6,5 @@ build
dist
docs
tests/output_files
Output
dyn2py.exe

112
README.md
View File

@@ -1,3 +1,10 @@
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/infeeeee/dyn2py?style=flat-square)](https://github.com/infeeeee/dyn2py/releases/latest)
[![PyPI](https://img.shields.io/pypi/v/dyn2py?style=flat-square)](https://pypi.org/project/dyn2py/)
[![GitHub Release Date](https://img.shields.io/github/release-date/infeeeee/dyn2py?style=flat-square)](https://github.com/infeeeee/dyn2py/releases/latest)
[![GitHub last commit (branch)](https://img.shields.io/github/last-commit/infeeeee/dyn2py/main?style=flat-square)](https://github.com/infeeeee/dyn2py/commits/main)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/infeeeee/dyn2py/unittests.yml?label=tests&style=flat-square)](https://github.com/infeeeee/dyn2py/actions/workflows/unittests.yml)
[![GitHub](https://img.shields.io/github/license/infeeeee/dyn2py?style=flat-square)](https://github.com/infeeeee/dyn2py/blob/main/LICENSE)
# dyn2py
Extract python code from Dynamo graphs
@@ -5,19 +12,30 @@ Extract python code from Dynamo graphs
Use cases:
- 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
### With pip from Github
### Windows portable and installer
Requirements: git, python, pip
Prebuilt portable exe and installer available from github releases.
No requirements, just download `dyn2py.exe` or `dyn2py-installer.exe` from release assets:
https://github.com/infeeeee/dyn2py/releases/latest
Installer automatically adds the install folder to the path, so simply `dyn2py` can be called from anywhere.
### 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
### As a standalone command line program
@@ -52,11 +70,39 @@ Do not move the source Dynamo graphs, or update won't work with them later.
Multiple sources are supported, separate them by spaces.
```
#### 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.*
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
```
### As a python module
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
import dyn2py
@@ -86,11 +132,27 @@ python_files = dynamo_file.get_related_python_files(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
### Installation
Requirements: git, pip
Requirements: git, python, pip
```
git clone https://github.com/infeeeee/dyn2py
@@ -108,16 +170,50 @@ venv .venv
pip install -e .
```
### Build
### Build for Windows
```
pip install -e .[build]
pyinstaller dyn2py.spec
```
### Create installer for Windows
- Install Inno Setup: https://jrsoftware.org/isdl.php
- The already built exe should be in the root folder
- Run this in powershell:
```powershell
# 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:
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" -Qp $(Join-Path $PWD.Path dyn2py-installer.iss)
```
### Live module documentation
```
pip install -e .[doc]
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

View File

@@ -14,17 +14,17 @@
- [x] Tests on Linux
- [x] Tests on Windows
- [x] Windows Build
- [ ] Pip
- [x] Pip
- [x] Windows Installer
## Documentation
- [x] API docs
- [ ] Installation in readme
- [ ] Terminal examples in readme
- [x] Installation in readme
- [x] Terminal examples in readme
- [ ] About git hooks in readme
## Extra features maybe later
- [ ] Windows Installer
- [ ] Autocomplete
- [ ] Winget

82
dyn2py-installer.iss Normal file
View 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;

View File

@@ -371,7 +371,7 @@ class PythonFile(File):
"""A Python file, subclass of File()"""
code: list[str]
"""The python code."""
"""The python code. Lines as list items, without newlines."""
header_data: dict
"""Parsed dict from the header of a python file."""
text: str
@@ -564,7 +564,7 @@ class PythonNode():
engine: str
"""The engine of the node, IronPython2 or CPython3"""
code: list[str]
"""The full code"""
"""The full code. Lines as list items, without newlines."""
checksum: str
"""The checksum of the code, for checking changes"""
name: str
@@ -572,7 +572,7 @@ class PythonNode():
filename: pathlib.Path | str
"""The filename the node should be saved as, including the .py extension"""
filepath: pathlib.Path
"""The path is shoul"""
"""The full path the node should be saved as"""
def __init__(self,
node_dict_from_dyn: dict = {},

View File

@@ -1,6 +1,6 @@
[project]
name = "dyn2py"
version = "0.3.0"
version = "0.3.2"
description = "Extract python code from Dynamo graphs"
readme = "README.md"
requires-python = ">=3.8"
@@ -11,7 +11,7 @@ license = { file = "LICENSE" }
authors = [{ name = "infeeeee", email = "gyetpet@mailbox.org" }]
maintainers = [{ name = "infeeeee", email = "gyetpet@mailbox.org" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
]
@@ -23,7 +23,6 @@ build = ["pyinstaller"]
doc = ["pdoc"]
[project.urls]
homepage = "https://github.com/infeeeee/dyn2py"
documentation = "https://infeeeee.github.io/dyn2py"
repository = "https://github.com/infeeeee/dyn2py"
changelog = "https://github.com/infeeeee/dyn2py/releases"