Skip to content

Conversation

@spyke7
Copy link
Contributor

@spyke7 spyke7 commented Nov 8, 2025

hi maintainers
@orbeckst @lilyminium @hejamu @joaomcteixeira @PicoCentauri
This PR is related to issue #37
I have implemented the argcomplete library for tab-completion, please check this.
I have updated the cli.py file, and tox.ini, README.rst, pyproject.toml, and also test_cli.py
in the test_cli.py I have added a function test_subparser_setup_for_tab_completion - it checks the setup for argcomplete.
Please check this and if any issue please tell me.

@PicoCentauri please check this


📚 Documentation preview 📚: https://mdacli--127.org.readthedocs.build/en/127/

Copy link
Collaborator

@PicoCentauri PicoCentauri 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 @spyke7!

Looks like a good start. If it just works with one line without further setup even better. I left some firs comments and will try it locally soon.

The docs are the linter are not happy. You can see the errors by clicking on the link in the discussion and also run these locally for better debugging.

The linter should be easily please by running the formatting tox -e format.

For the docs there seemed to be a doubled defined label.

Let me know if you encounter any problems fixing the issues.

Comment on lines 102 to 103
argcomplete.autocomplete(ap)
setup_clients(ap, title=f"{name} Analysis Modules", members=modules)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be swapped? After we registered all modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this will still work as it is just a hook
But I will just swap the lines, and then also it will work.
There is no problem in both I guess

# Check if it still works if the module name is not the second argument
subprocess.check_call(["mda", "--debug", args, "-h"])

def test_subparser_setup_for_tab_completion():
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nice test. But I think we should also have a test that the argcompletion is really setup. Maybe check the argcomplete repo how they do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@spyke7
Copy link
Contributor Author

spyke7 commented Nov 10, 2025

okk
Will be solving the issues soon

@spyke7
Copy link
Contributor Author

spyke7 commented Nov 10, 2025

Ya please check now
please check whether the docs are passing or not
if anything I need to change please tell

@PicoCentauri
Copy link
Collaborator

I did some minor cleanup. But the completion does not work on my machine.

@spyke7
Copy link
Contributor Author

spyke7 commented Nov 11, 2025

Wait checking it again @PicoCentauri

@spyke7
Copy link
Contributor Author

spyke7 commented Nov 11, 2025

@PicoCentauri
please look at this screenshots and videos
There is one important thing that is to add

# PYTHON_ARGCOMPLETE_OK

write the above inside the environment created
for ex - "path"/mdacli/env/bin/mda

If inside a virtual env -

activate-global-python-argcomplete --user

Here is the video -

https://github.com/user-attachments/assets/3f649c75-38ef-41cd-8378-0511dc37e2c0
Screenshot (54)
Screenshot (57)
Screenshot (53)

pip install -e .
First do the activation
restart terminal
then write python_argcomplete_ok
then do the eval one

@PicoCentauri
Copy link
Collaborator

Thanks! I will test it again tomorrow!

Copy link
Collaborator

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. It now also works for me!!!

However, it would be nice if we could avoid having this in the __main__ function. Since this will be used also by downstream projects they now also have to copy this argcomplete logic which will ad some additional boilerplate. Maybe there is a way to avoid having this in the main...

Also, is there a way to do file completion for the -s and -f option only for the files that are supported by MDAnalysis. There are of course fixed choices but want choices only based on the file extension. Not sure if argcomplete can do it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the tests you added didn't really fail even when before the completion was not working we should maybe think about more robust test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous one was checking for setup
Setup was perfect before and after also
PYTHON_ARGCOMPLETE_OK was the main thing
It was not related with test cases, but crucial for bash completion

@spyke7
Copy link
Contributor Author

spyke7 commented Nov 15, 2025

Screenshot (60)

Check this for file completion
and also removed the autocomplete from main.py, but everything works fine.
Please check the add_cli_universe function
and also a new function completer I have added. Just review them

Copy link
Collaborator

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

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

Very nice. I think we are almost there!

)


def _create_mda_file_completer(format_dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you don't need the whole dictionary but just the list of keys. Maybe passing a list of file extension makes this function a bit clearer

Suggested change
def _create_mda_file_completer(format_dict):
def _create_extension_completer(extension_list):

We could also make this public as this might be useful in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok please check now, I think previously also, the list was passing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you loop through a dictionary what you get are the keys.

Copy link
Collaborator

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

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

Very nice. I have two last minor comments and we can merge.

Comment on lines 269 to 276
# Determine directory and file prefix
if os.path.sep in prefix:
prefix_path = Path(prefix)
directory = prefix_path.parent if prefix_path.parent != Path() else Path()
file_prefix = prefix_path.name
else:
directory = Path()
file_prefix = prefix
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks to me like a bit complicated LLM code.

I think one can do it without pulling os in and directly converting the prefix to Path object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm.
Yeah it's looks a bit complicated,, let me do something about it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the os
just used the prefix_path only
previously, I thought that using os will be good, but this also works

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean if you use pathlib you can do everything with it. I usually try either use the newer object style pathlib exclusively or exclusively stick to os.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah indeed

@PicoCentauri PicoCentauri merged commit 6333fdf into MDAnalysis:main Nov 18, 2025
11 checks passed
@PicoCentauri
Copy link
Collaborator

Thanks again @spyke7 for the nice work! 🚀

@PicoCentauri PicoCentauri mentioned this pull request Nov 18, 2025
@spyke7
Copy link
Contributor Author

spyke7 commented Nov 18, 2025

Thanks @PicoCentauri for guiding me to make a clean PR. And also I will be working on other issue in MDanalysis.

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.

2 participants