-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
[automation] Sort by filename instead of path #724
Conversation
Currently, the scripts are loaded based on the lexicographical order of the absolute paths of the scripts. This makes it difficult to control the load order. This change bases the load order solely on the filename, as was originally used before eclipse-archived/smarthome#3855, and preserves the ability to use scripts with the same filename. Signed-off-by: Scott Rushworth <openhab@5iver.com>
I cannot judge, which sort order makes most sense, but I would expect (what reason ever) a sort order like:
So, go down the directory hierarchy after the files of that directory has been checked. Your example:
But I am not an user of the scripting engine, yet. So perhaps there could be some answers of other ones. |
A script loading order based on the directory structure (absolute path) is a lot harder to work with. Currently, with the load order based on the absolute path, the only way to have certain scripts load before any others, is to manipulate the directory names, or put them in the root directory and manipulate the file name. So, scripts in This PR allows for me to distibute solutions that are contained in their own directories, which can be easily copy/pasted, and the load order, relative to other directories that have been distributed, are preserved because the load order is based off of the file name. The openhab-jython repo relies on a specific directory structure. Without this PR, users will have to modify the directory and file names so that the script load order works properly with their implementation. Specific example... Currently, the owm_daily_forecast.py will load first, and fail, since the 000_starup_delay.py is required to run first and delay the loading of all other scripts until the environment is full loaded. The script will also fail since it uses a module that depends on 200_JythonItemProvider.py being loaded. ├── automation/jsr223 In reading through this several times, it all still looks like it would be confusing for someone who is not using scripted automation. I'll see if I can't drum up some others to help communicate the benefits of this change. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/proposed-change-to-the-jsr223-script-loading-order/72548/1 |
We definitely need a reliable way to ensure scripts are loaded in the correct order. The proposed naming convention solves this problem without worrying about directory names or structure. |
Don't get me wrong, I don't argue for a specific sorting algorithm, I just want to understand why the one is better then the other.
Hm, I don't understand.
Same here. If my script is named You could also state that the script you provide needs to be placed in a directory "000" and the user must not use the root directory of |
I understand your position. You want to be certain that the best solution is chosen, but don't have experience with scripted automation. You are the gatekeeper and we need and appreciate you!
The openhab2-jython repo contains community provided modules and scripts, which a user can install by "cherry picking" them out of the directory structure and copying to their OH installation. This is just a stepping stone until we have an automation extension service. The organization is about to be renamed to openHAB Scripters, and separate repos will be created for each scripting language and their helper libraries, using the same directory format. In a test environent, setup the Jython helper libraires and scripts and you might see what I mean. I have not added much to the doc for the Community stuff, mainly because it doesn't work due to the current load order. I've also held up submitting LOTS of examples until we get something like this PR merged. The alternative is to add numeric prefixes to the directory names, which is rather ugly and does not solve the issue in all cases. Say that we have renamed the core script directory with a numeric prefix so that these scripts will load first using the current load order. But there is a community script that needs to load in the middle of the core scripts... ├── automation/jsr223 With the current load order, these scripts would load...
There is currently no way to interweave the load order of scripts from separate directories. This PR provides this functionality by sorting by file name. |
...org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java
Show resolved
Hide resolved
...org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no one that complains about the changed loading order and if it is better for you...
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/preparation-for-2-5m2/75738/1 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/problems-after-install-of-jsr223-scripts/81969/2 |
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Currently, the scripts are loaded based on the lexicographical order of the absolute paths of the scripts. This makes it difficult to control the load order. This change bases the load order solely on the filename, as was originally used before eclipse-archived/smarthome#3855, and preserves the ability to use scripts with the same filename. Signed-off-by: Scott Rushworth <openhab@5iver.com> GitOrigin-RevId: 77992e7
Currently, the scripts are loaded by ScriptFileWatcher based on the lexicographical order of the absolute paths of the scripts. This makes it difficult to control the load order. This change bases the load order solely on the filename, as was originally used before ESH/#3855, and preserves the ability to use scripts with the same filename. This PR resolves openhab-scripters/openhab-helper-libraries#76.
Current load order
After this PR
Scripts will be loaded based on the filename. If more than one script have the same filename, their paths will also be taken into account for the sorting. This is especially helpful with the direcotry structure adopted by the Jython helper libraries. Currently, Community scripts (in a community directory), are being loaded before the Core scripts (in a core directory).
Directory structure and scripts
Load order
@lewie, I'm curious what your thoughts are about this change.
Signed-off-by: Scott Rushworth openhab@5iver.com