-
I would like to call another tool to run on the directory where I just created an environment. Specifically, after running The TemplateInterface is great, but is entirely isolated as far as where the project is going to go as far as I can tell. This is a good design pattern. I have poked around the code and I am not sure the exact execution order of different interfaces. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I haven't designed templates well enough yet to expose the API. One day that will happen but it is low priority |
Beta Was this translation helpful? Give feedback.
-
I found a way to accomplish my desires, but it is cursed. Behold, the offspring of my brain: class PycharmTemplate(TemplateInterface):
PLUGIN_NAME = "pycharm"
@staticmethod
def copy_what_new_does(name, location, initialize):
"""Copy pasted the load bearing parts from the hatch code. Shamelessly."""
if location:
location = Path(location).resolve()
if initialize:
location = location or Path.cwd()
if not location:
from hatch.project.core import Project
normalized_name = Project.canonicalize_name(name, strict=False)
location = Path(normalized_name).resolve()
return location
def finalize_files(self, config, files):
"""We aren't finalizing anything, we are just registering a call on close hook"""
from click import get_current_context
# Get the execution context from Click
ctx = get_current_context()
# Get the params we need from the context
name = ctx.params.get("name")
location = ctx.params.get("location")
initialize = ctx.params.get("initialize")
# Get the processed version of location based on one reading of the code one time
# This isn't fragile!!!
location = self.copy_what_new_does(name, location, initialize)
# Tell Click to call us when this context is done (When the new command is closed out)
ctx.call_on_close(partial(open_pycharm, location))
I wouldn't call this a good idea, but I may end up there. I wonder if there are better ways to inform click of my existence than this. |
Beta Was this translation helpful? Give feedback.
-
Also thank you for the quick response, I didn't expect such a quick reply! haha! |
Beta Was this translation helpful? Give feedback.
I haven't designed templates well enough yet to expose the API. One day that will happen but it is low priority