-
Notifications
You must be signed in to change notification settings - Fork 635
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
Provide a strategy for host integrator's to set the python template at startup #9533
Conversation
…t startup programmatically
src/DynamoCore/Models/DynamoModel.cs
Outdated
// To supply a custom python template host integrators should supply a 'DefaultStartConfiguration' config file | ||
// or create a new struct that inherits from 'DefaultStartConfiguration' making sure to set the 'PythonTemplatePath' | ||
// while passing the config to the 'DynamoModel' constructor. | ||
var configCast = (DefaultStartConfiguration)config; |
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.
This is done because the DynamoModel
constructor takes a IStartConfiguration
config as its only param. I believe modifying the interface (even adding a new property) would be an API breaking change, but feel free to correct me if I am wrong on this or there is a better strategy.
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.
I think you should do something like:
defaultConfig = config as DefaultStartConfiguration
and then check for null because it's possible that the concreteType is NOT a DefaultStartConfiguration ... and that needs to be handled. (ie missing the python template field you just added)
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.
alternatively you can add a second interface and check if the object implements that interface, if it does - do the right thing and set the path.
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.
👍 Same options in https://jira.autodesk.com/browse/DYN-1644
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.
in general, I don't think casting like this is a great idea for the problem we are discussing as casting can throw - as
and is
should not.
https://docs.microsoft.com/en-us/dotnet/api/system.invalidcastexception?view=netframework-4.7.2
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.
Thanks for the feedback guys. I was not happy with this approach either but as
cannot be used with a non-nullable value type which DefaultStartConfiguration
is as a struct. This is why I wrapped this logic in a try/catch returning the default template if an exception is thrown. However, performing a check such as
if(config is DefaultStartConfiguration)
{
// Proceed in checking if a custom template path is available and valid
}
else
{
// Use default template
}
is possible but does not guaranteed the PythonTemplatePath has been set. Attempting to retrieve the PythonTemplatePath
property will simply return null if it was not set and I verify this is not the case below before proceeding. Long story short we can probably use is
to verify the config
is of the DefaultStartConfiguration
type or of a type that inherits from it. I don't think adding another struct is necessary just for this property. If the config
is of another type we return the default template. I believe the try/catch can also be removed with is
as @mjkkirschner suggested since it will not throw. What do you guys think about this approach? @QilongTang
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.
Sounds good to me.
@alfarok Once you wrap this up, please also attach the screen shot of console with this change so clients know what to expect from console. Thanks |
@QilongTang I just added one new logging statement for when a custom template is loaded via the config, however it turns out none of the old statements ever successfully logged to the console or log file. Possibly because the |
@alfarok Sure, could be related to the sequence of how preference setting and logger are initialized |
@QilongTang Added screenshots for all the logging statements. There were a couple issues with the previous logging logic which took me a little while to uncover. It appeared the logging wasn't working because the localized strings were embedded only in the |
Added unit tests verifying API usage for valid and invalid template paths. I think this should be ready to go |
Look perfect on my side! |
…t startup (DynamoDS#9533) * provide a strategy for host integrators to set Python node template at startup programmatically * use 'is' as opposed to 'try/catch' * Fix several bugs around previously existing logging statements * add unit tests verifying valid and invalid API usage
Purpose
DYN-1507
This PR provides a strategy for a Dynamo host integrator to programmatically set the path of the Python nodes default template at startup. This is accomplished by setting the
PythonTemplatePath
on the configuration file that will be passed as a parameter to theDynamoModel
when instantiated. It is required that the host integrator uses either theDefaultStartConfiguration
struct or creates a struct that inherits fromDefaultStartConfiguration
. For example...Users are still able to override this file if desired by modifying the
<PythonTemplateFilePath>
attribute in theDynamoSettings.xml
file or adding a a new template file in the appropriateAppData
location (see below). To fallback to either host integrator path or the hard-coded template provided in Dynamo Core simply remove the path from the settings xml or delete the template file from theAppData
location. Lastly, if a invalid path is provided the default Core template will be applied.Logging
(In sequential order)
Loaded from DynamoSettings.xml
Loaded from Host Integrator
Loaded from AppData
Loaded Default Template
Overriding the default or a host integrator template as a USER
Users looking to override the template can do so in the following ways introduced in #8122:
Option 1 - Default AppData Location
Add a new python file named
PythonTemplate.py
to theC:\Users\alfarok\AppData\Roaming\Dynamo\Dynamo Core\2.2
directoryOption 2 - Custom Location using DynamoSettings.xml
Add a custom path to the
DynamoSetting.xml
under thePythonTemplateFilePath
tag such as<PythonTemplateFilePath>C:\Users\alfarok\Desktop\PythonTemplate.py</PythonTemplateFilePath>
(Does NOT require
PythonTemplate.py
naming)Testing
Unit tests have been added to verify API usage for valid and invalid template paths. Additionally, this has been manually tested by modifying the DynamoSandbox startup config to include a
PythonTemplatePath
which is set here and invoked here. Testing coverage for loading the default template as well as a user template already has coverage.Declarations
Check these if you believe they are true
*.resx
filesReviewers
@QilongTang @mjkkirschner