Skip to content

Conversation

@john-craig
Copy link

Implement User Defined Macros as per #125

@john-craig john-craig requested a review from najohnsn as a code owner October 4, 2024 14:09
@najohnsn najohnsn added the enhancement New feature or request label Oct 4, 2024
Copy link
Member

@najohnsn najohnsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! This looks really good! I still wanted to think about some things. In the meantime, I have some comments for you to consider.

@john-craig john-craig force-pushed the feature/user-macros branch from 92b7ec8 to e9775fe Compare October 7, 2024 15:30
tnz/zti.py Outdated
# function
setattr(Zti, f"do_{macro_name}",
types.MethodType(
getattr(macro_module, f"do_{macro_name}"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have noticed that many of the do_<command> methods call self.__bg_wait_end(). That is because a background thread runs while the user is at the prompt and that call shuts down that background thread so that the session(s) can be used in a thread-safe manner. That is something that is definitely needed here. Without it. both the thread running the do_<command> method and the background thread could be using tnz methods that are not thread-safe. I suggest you define a method that wraps the macro method in order to accomplish this. See do_plugin() as an example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to model after do_plugin() ...

                    with ati.ati.new_program(share_sessions=True):
                        plugin(arg, **kwargs)

That helps ensure that the ati environment provided to the plugin is clean and that any variables set by the plugin do not leak into the current environment. Unless your use case requires non-shared/global ati variables as input to or output from the macro, I suggest being consistent with do_plugin().

@john-craig john-craig force-pushed the feature/user-macros branch 2 times, most recently from 73b6992 to f5c42ca Compare April 17, 2025 15:31
@john-craig john-craig closed this Apr 17, 2025
@john-craig john-craig force-pushed the feature/user-macros branch from 2fb401f to bcde0d4 Compare April 17, 2025 17:03
@john-craig
Copy link
Author

My mistake, running into issue rebasing on the latest changes. All should be ready for review now.

@john-craig john-craig reopened this Apr 17, 2025
@john-craig john-craig force-pushed the feature/user-macros branch from 2ae4bda to 05377d4 Compare April 17, 2025 17:18
@john-craig john-craig force-pushed the feature/user-macros branch from 05377d4 to 8ab4e78 Compare April 17, 2025 17:54
Signed-off-by: John Craig <[email protected]>
@john-craig john-craig force-pushed the feature/user-macros branch from f10bac6 to bb31a5b Compare April 21, 2025 14:09
tnz/zti.py Outdated
if not macro_file.endswith(".py"):
continue

if len(macro_file.split('.')) > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest the use of pathlib for inspecting the filename and it's parts - this does not look right

@@ -0,0 +1,30 @@
from tnz.ati import ati
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would actually be better to do from tnz import ati. that way the sample uses the current global ati object - which is what zti works with. when from tnz.ati import ati is used, the code here is bound the the global ati object at the time of import - there are situations in which that object can change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants