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

Per directory yaml #1759

Merged
merged 5 commits into from
Apr 19, 2022
Merged

Per directory yaml #1759

merged 5 commits into from
Apr 19, 2022

Conversation

jorgeecardona
Copy link
Collaborator

@jorgeecardona jorgeecardona commented May 15, 2020

The present requests add the option of reading a yaml-formatted file in the current working directory loading the title of a tab.

@zeusintuivo
Copy link

How would the sample .guake.yml file look like? And where could it be located?

@jorgeecardona
Copy link
Collaborator Author

@zeusintuivo right now guake.yml could be on any directory, when you land in the directory guake reads the file and extract the title.

I guess it could be extended or modified.

In my own machine, I have now some directories I frequently used with .guake.yml files with only a title, e.g.

title: "backend"

and when I get into that directory the tab has "backed" as title, it's very simple at the moment.

@zeusintuivo
Copy link

I see, this is an original idea. It could be even better if could perfom custom commands. Like set node version or rbenv or rvm or php version. Perhaps have a command line execution section. And also following that topic a autostart section. Something that would only run once vs command line execution that would run every time you go in the folder?

@jorgeecardona
Copy link
Collaborator Author

I am glad you like it ;) I am honestly just interested in the title. I am aware more things are possible as you said, but some seem a bit dangerous to me, or at least it seems it should the responsibility of a different component, like .bashrc or something like that.

Also, the API used for the proof-of-concept seems a bit poor to me honestly, and I would be afraid of adding too many options. Like is ok to set the name of the label twice in less than a second, but you could easily get into problems if you run a large command.

I would leave it just as a way to configure Guake on a per-directory basis.

@gsemet
Copy link
Member

gsemet commented Mar 4, 2021

Closing old PR

@jorgeecardona
Copy link
Collaborator Author

Hi, is there a way to reopen this and consider merging this feature?

@gsemet
Copy link
Member

gsemet commented Mar 4, 2021

You can reopen but please update the pull request description and the Reno chunk

@Davidy22
Copy link
Collaborator

Davidy22 commented Sep 9, 2021

Going back through issues, found this through an old issue and it looks like it could be nice, reopening and will check later. For now, you may need to rebase your branch to pass test cases.

@Davidy22 Davidy22 reopened this Sep 9, 2021
@Davidy22
Copy link
Collaborator

Alright, I've gone and done some quick fixing up with the build errors so now we can look at the content of this. For one, we're going to need some docs written so people can actually know how to format the yaml files

@gsemet
Copy link
Member

gsemet commented Sep 16, 2021

can you confirm if this PR is still ok?

@Davidy22
Copy link
Collaborator

Pull request has good stuff but needs a little bit more written before it's a feature to add. We need docs so that people can know that this is a thing that guake will look for, maybe some nice controls in the UI for creating these files and then some testing.

@jorgeecardona
Copy link
Collaborator Author

I added a small explanation with an example in the Feature section of the documentation. I imagine we could use this file for more than just the title.

So far I have been using this for over a year and I love it, it makes it really easy to navigate my tabs, though I only get lost when I am in a remote machine via ssh. I haven't thought too much about that case anyway or similar: opening another shell from the original shell.

Copy link
Collaborator

@Davidy22 Davidy22 left a comment

Choose a reason for hiding this comment

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

Alright, tested the branch and it works as expected, so going in a little more in depth now. First order of business, the checks seem to be failing again, so those need to be dealt with. Some structural things as well for potential future development of the file as well.

guake/guake_app.py Outdated Show resolved Hide resolved
def compute_tab_title(self, vte):
"""Compute the tab title"""

guake_yml = self.read_current_guake_yaml(vte)
if guake_yml is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can move these checks into the yaml read function? So if there's more added to the yaml file in the future, there's a bit less boilerplate checking that needs to be rewritten each time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved the is not None internally to the read_current_guake_yaml method. That method is returning a dictionary with the file's content, not just a string with the title, so a minimal check is still required here. I did this thinking that the .guake.yml file might contain more than a title.

@jorgeecardona
Copy link
Collaborator Author

Great, I added the encoding. I am not sure how much effor to put on checking in the read_guake_yaml I would like this function to simply return a dataclass with the content of the file and maybe keep it cached somewhere in the parent class, until a change of cwd is detected. That class can be accesed then for some of its content, still some minor checks are required at every step where the content is intended to be used.

Also, I am using the extension .yml but I am unsure if everyone is used to have a `.yaml' instead.

I am happy to hear also if adding typings is in the future plans, fro vte in particular I guess I need to add an import on Vte and the vte argument is a 'Vte.Terminal' right?

Best.

@Davidy22
Copy link
Collaborator

The merge from master seems to be failing checks, I'll fix that real quick.

@mlouielu
Copy link
Collaborator

I would like to have description of this PR update at the OP description.

Copy link
Collaborator

@mlouielu mlouielu left a comment

Choose a reason for hiding this comment

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

We should add option to reduce disk load, and audit yaml.safe_load to prevent arbitrary code

@@ -1070,9 +1071,37 @@ def recompute_tabs_titles(self):
page_num = self.get_notebook().page_num(terminal.get_parent())
self.get_notebook().rename_page(page_num, self.compute_tab_title(terminal), False)

def read_current_guake_yaml(self, vte) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

read_current_directory_guake_yaml()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or load_current..., more suitable for describing what is has done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed for load_cwd_guake_yaml seems better to me since is shorter.

try:
if guake_yaml.is_file():
with guake_yaml.open(encoding="utf-8") as fd:
content = yaml.safe_load(fd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should audit yaml.safe_load() as this could be a point to include arbitrary code.

Copy link
Collaborator

@Davidy22 Davidy22 Sep 24, 2021

Choose a reason for hiding this comment

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

safe_load() should be the safe version of load()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with David. I am not planning in going deep into the yaml implementation to check if safe_load is as safe as they advertise it.

def compute_tab_title(self, vte):
"""Compute the tab title"""

guake_yml = self.read_current_guake_yaml(vte)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add config option (enable, disable) to reduce reading from disk.

guake/guake_app.py Outdated Show resolved Hide resolved
@jorgeecardona
Copy link
Collaborator Author

I still have to add a flag in the configuration to activate reading from this file. I will try to finish that during the week.

Regarding caching the content to prevent unnecessary reads, I honestly would first implement a very simple time() based control to prevent accessing the file if it has been accessed less than certain seconds ago. Would that be ok for you guys?

@Davidy22
Copy link
Collaborator

Davidy22 commented Oct 2, 2021

Yeah sure that'll probably be fine, generally should use monotonic() instead of time() though for the safety.

@Davidy22
Copy link
Collaborator

Davidy22 commented Oct 2, 2021

Back because build failed. For future reference, you can just run make black to handle formatting for you after you're done writing code, I'll make the check pass here for now. Also you can probably squash commits down if you have a couple with the same name

@jorgeecardona jorgeecardona force-pushed the per-directory-yaml branch 5 times, most recently from 961853b to aa147f1 Compare April 18, 2022 18:38
@jorgeecardona
Copy link
Collaborator Author

I added an options in prefs and a way to cache the content of the yaml files and prevent reloading too often. I honestly don't like to have the two properties _guake_yml and _guake_yml_load_monotonic but this is a simple solution I guess.

@Davidy22
Copy link
Collaborator

CI failing, you might need to rebase your branch onto latest git to resolve the weird dependency thing because I'm not seeing this issue crop up in any of the other active PRs. Looking at the things deepsource is complaining about, you can ignore the second one because it doesn't have anything to do with your changes but this one is relevant.

@jorgeecardona
Copy link
Collaborator Author

Hi @Davidy22 I did the rebase to master, but the error is still there. I honestly don't know what's the problem since make test runs for me. Could you suggest a way I can check on my end what's the problem?

@jorgeecardona
Copy link
Collaborator Author

The PR is now "ok" according to the last run. The tests are not passing in th CI, but they pass on my machine.

Regarding the code, I was planning to just add a FileManager class in utils.py to handle the cache for file content instead of the two properties in the Guake class. What do you thik about that?

@Davidy22
Copy link
Collaborator

Oh, I see you added a pyyaml line to the pipfile, so that probably changes the dependency graph and I suspect that's where the issue is coming from. You can do a pipenv lock to regenerate the lock file from your local setup if you have a working setup and that'll probably clear this up.

@jorgeecardona jorgeecardona force-pushed the per-directory-yaml branch 4 times, most recently from 8a9baed to 83ae070 Compare April 19, 2022 13:29
Copy link
Collaborator

@Davidy22 Davidy22 left a comment

Choose a reason for hiding this comment

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

Looks like we finally got all checks passing, looks good and works fine, merging.

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

Successfully merging this pull request may close these issues.

None yet

5 participants