Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Ryven from python script fails if node packages are passed as arguments #179

Open
pfjarschel opened this issue Jan 5, 2024 · 0 comments

Comments

@pfjarschel
Copy link

Got a simple one here:

If Ryven is run from a python script, AND some node packages are passed as arguments, AND the startup screen is enabled, the startup fails due to some Path/str confusion.

To reproduce, I give you a simple code:

import os
import ryven

# File paths
main_path = os.path.dirname(os.path.realpath(__file__))

ryven.run_ryven(qt_api='pyside6', 
                show_dialog=True, 
                nodes=['std',
                f'{main_path}/ryv_pckg',
                f'{main_path}/ryv_PFJVirtualSG'], 
                project=f'{main_path}/PFJVSG.json',
)

The two node packages are personal packages I am testing. The problem is also present if only 'std' is used, for example.

The error shown is this:

File "C:\Users\pfjar\AppData\Local\Programs\Python\Python311\Lib\site-packages\ryven\gui\startup_dialog\StartupDialog.py", line 647, in update_packages_lists
    if pkg_path.stem == node_item.text():
       ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'stem'

`
It is clear that the problem arises because the script treats the node packages as Paths, but when Ryven is run from a python script (and maybe from the command line?) the passed packages are only strings, not Paths yet. Now, I dug through the code, and couldn't easily find the place where string paths are converted to Paths, when packages are passed as arguments. Not sure if there is a place? So i have come up with a simple solution that works, but a better one can probably be easily implemented.

Proposed solution:
Include the following lines before each pkg_path.stem call in StartupDialog.py (there are 4):

if isinstance(pkg_path, str):
    pkg_path = pathlib.Path(pkg_path)

Hope this helps leon-thomm and anyone having this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant