JamesParrott / sDNA_GH

Spatial Design Network Analysis from sDNA, in Grasshopper and Rhino3D
Other
6 stars 1 forks source link

Rhino 8 bug. Error on first running of sDNA_Integral in Rhino 8.5 #117

Closed JamesParrott closed 8 months ago

JamesParrott commented 9 months ago
sDNA_GH.sDNA_Integral: INFO: Tools == [<ShapefileWriter object at 0x0000000000000140>, <sDNA_ToolWrapper object at 0x000000000000013D>, <ShapefileReader object at 0x0000000000000141>] 
sDNA_GH.custom.tools: INFO: Using automatically generated file name: C:\Users\drjam\Coding\Grasshopper\sDNA_GH_Rhino_8.shp
sDNA_GH.custom.tools.sDNA_ToolWrapper: INFO: repr(tool_opts['advanced']): '' 
sDNA_GH.custom.tools.sDNA_ToolWrapper: INFO: repr(tool_opts['advanced']): 'juncformula=0' 
sDNA_GH.custom.tools.sDNA_ToolWrapper: INFO: sDNA command run: C:\Python27\python.exe -u "C:\Program Files (x86)\sDNA\bin\sdnaintegral.py" --im "tables=;net=%userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8.shp" --om "net=%userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8_output.shp" "start_gs=;end_gs=;metric=EUCLIDEAN;custommetric=;disable=;intermediates=;oneway=;juncformula=0;origweight=;destweight=;weight_type=Link;radii=n;radmetric=EUCLIDEAN;;nojunctions;nohull"
sDNA_GH.custom.tools.sDNA_ToolWrapper: INFO: 
sDNA_GH.custom.tools.sDNA_ToolWrapper: ERROR: error.output: 
sDNA_GH.custom.tools.sDNA_ToolWrapper: ERROR: error.returncode: 1
Runtime error (Exception): CalledProcessError

Traceback:
  line 1356, in __call__, "%appdata%\Grasshopper\UserObjects\sdna-gh\sDNA_GH\custom\tools.py"
  line 130, in run_tools, "%appdata%\Grasshopper\UserObjects\sdna-gh\sDNA_GH\custom\skel\tools\runner.py"
  line 1263, in script, "%appdata%\Grasshopper\UserObjects\sdna-gh\sDNA_GH\main.py"
  line 375, in RunScript, "%appdata%\Grasshopper\UserObjects\sdna-gh\sDNA_GH\custom\skel\basic\smart_comp.py"

The shapefiles weren't deleted so the same command ran just fine from the command line:

C:\Python27\python.exe -u "C:\Program Files (x86)\sDNA\bin\sdnaintegral.py" --im "tables=;net=%userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8.shp" --om "net=%userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8_output.shp" "start_gs=;end_gs=;metric=EUCLIDEAN;custommetric=;disable=;intermediates=;oneway=;juncformula=0;origweight=;destweight=;weight_type=Link;radii=n;radmetric=EUCLIDEAN;;nojunctions;nohull"
sDNA sdnaintegral config: start_gs=;end_gs=;metric=EUCLIDEAN;custommetric=;disable=;intermediates=;oneway=;juncformula=0;origweight=;destweight=;weight_type=Link;radii=n;radmetric=EUCLIDEAN;;nojunctions;nohull
Loading DLL C:\Program Files (x86)\sDNA\\x64\\sdna_vs2008.dll
  Using default of euclidean link centres for euclidean analysis
  Using xytolerance=0, ztolerance=0
Input has 199 rows
Creating geometry output %userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8_output.shp
Adding fields:
    ID         - ID
    LConn      - Line Connectivity
    LLen       - Line Length
    LFrac      - Link Fraction
    LAC        - Line Ang Curvature
    LSin       - Line Sinuosity
    LBear      - Line Bearing
    MEDn       - Mean Euc Dist Rn
    NQPDEn     - NetQuantPD Euc Rn
    BtEn       - Betweenness Euc Rn
    TPBtEn     - TPBetweenness Euc Rn
    TPDn       - TPDestination Rn
    Lnkn       - Links Rn
    Lenn       - Length Rn
    AngDn      - Ang Dist Rn
    Wtn        - Weight Rn
    MGLEn      - MeanGeoLen Euc Rn
    MCFn       - Mean Crow Flight Rn
    DivEn      - Diversion Ratio Euc Rn
Field names saved to %userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8_output.shp.names.csv
Reading features from %userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8.shp
Reading features from %userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8.shp
Progress: 100%%
sDNA processing
Progress: 0.0%
  sDNA is running in 64-bit mode
  Building network and checking for tolerance errors...
  Running sDNA Integral calculation...
Progress: 100%
TIME 0.2 for start_gs=;end_gs=;metric=EUCLIDEAN;custommetric=;disable=;intermediates=;oneway=;juncformula=0;origweight=;destweight=;weight_type=Link;radii=n;radmetric=EUCLIDEAN;;nojunctions;nohull
Writing %userprofile%/Coding/Grasshopper/sDNA_GH_Rhino_8_output.shp
Progress: 100%%
JamesParrott commented 8 months ago

This issue is not caused by sDNA_GH. The test code below fails to call out to any external executable from Rhino 8.5, neither from CPython nor IronPython

import subprocess
import re
import os

from collections import OrderedDict

def run(*args, **kwargs):
    # return subprocess.check_output(*args, **kwargs)
    # return str(subprocess.call(*args, **kwargs))
    return str(subprocess.check_call(*args, **kwargs))

names = ('python',) #, 'node', 'git', 'hadolint', 'yak')

def test_progs(progs, args):

    for prog in progs:
        command = r'%s %s' % (prog, ' '.join('"%s"' % arg 
                                             for arg in args
                                            )
                             )
        try:
            print(run(command).rstrip())
        except subprocess.CalledProcessError as e:
            print('Error.  command: %s \nError info: %s' % (command, vars(e)))

PATH = os.getenv('path')

exes = OrderedDict()
for name in names:
    for dir_ in PATH.split(';'):
        path = os.path.join(dir_, '%s.exe' % name)
        if os.path.isfile(path):
            exes[name] ='"%s"' % path
            break  # inner loop

test_progs(names, ['--version'])
print()
test_progs(exes.values(), ['--version'])
print()

working_dir = r'%appdata%\McNeel\Rhinoceros\8.0\scripts'

args = []
for arg in ('hello_world.py', 
            'hello_world.js',
            'Dockerfile'
            ):
    file_ = os.path.join(working_dir, arg) 
    if os.path.isfile(file_):
        args.append(file_)

assert args

test_progs([exes['python']],args[:1])
# test_progs([exes['node']],args[1:2])
# test_progs([exes['hadolint']],args[2:])

produces:

Running: python "--version"
Python 3.11.4
Running: node "--version"
v18.16.0
Running: hadolint "--version"
Haskell Dockerfile Linter 2.12.0
()
Running: "C:\Users\drjam\AppData\Local\Programs\Python\Python311\python.exe" "--version"
Python 3.11.4
Running: "C:\Program Files\nodejs\node.exe" "--version"
v18.16.0
Running: "C:\Program Files (x86)\Hadolint\hadolint.exe" "--version"
Haskell Dockerfile Linter 2.12.0
()
Running: "C:\Program Files\nodejs\node.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.js"
Hello, World!
Running: "C:\Program Files (x86)\Hadolint\hadolint.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\Dockerfile"

Running: "C:\Users\drjam\AppData\Local\Programs\Python\Python311\python.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.py"
Error.  Info: {'returncode': 1, 'cmd': '"C:\\Users\\drjam\\AppData\\Local\\Programs\\Python\\Python311\\python.exe" "C:\\Users\\drjam\\AppData\\Roaming\\McNeel\\Rhinoceros\\8.0\\scripts\\hello_world.py"', 'output': ''}
Running: python "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.py"
Error.  Info: {'returncode': 1, 'cmd': 'python "C:\\Users\\drjam\\AppData\\Roaming\\McNeel\\Rhinoceros\\8.0\\scripts\\hello_world.py"', 'output': ''}

Where as from the command line (as in the zip file):

Running: python "--version"
b'Python 3.11.4'
Running: node "--version"
b'v18.16.0'
Running: hadolint "--version"
b'Haskell Dockerfile Linter 2.12.0'

Running: "C:\Users\drjam\AppData\Local\Programs\Python\Python311\python.exe" "--version"
b'Python 3.11.4'
Running: "C:\Program Files\nodejs\node.exe" "--version"
b'v18.16.0'
Running: "C:\Program Files (x86)\Hadolint\hadolint.exe" "--version"
b'Haskell Dockerfile Linter 2.12.0'

Running: "C:\Program Files\nodejs\node.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.js"
b'Hello, World!'
Running: "C:\Program Files (x86)\Hadolint\hadolint.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\Dockerfile"
b''
Running: "C:\Users\drjam\AppData\Local\Programs\Python\Python311\python.exe" "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.py"
b'Bonjour le Monde!'
Running: python "C:\Users\drjam\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts\hello_world.py"
b'Bonjour le Monde!'
JamesParrott commented 8 months ago

test.zip

This is fixable by specifying env=os.environ in subprocess.check_output

image

subprocess_bug.zip