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

add file argument #24

Merged
merged 2 commits into from
Aug 8, 2023
Merged

add file argument #24

merged 2 commits into from
Aug 8, 2023

Conversation

TheoMF
Copy link
Contributor

@TheoMF TheoMF commented Aug 2, 2023

fix #10

@nim65s
Copy link
Member

nim65s commented Aug 2, 2023

This is now in conflict with the main branch. Could you rebase your commit and fix this ?

@TheoMF
Copy link
Contributor Author

TheoMF commented Aug 2, 2023

done

gepetuto/lint.py Outdated
Comment on lines 16 to 20
folder = Path(f"tp{n}")
for python_file in folder.glob("*.py"):
lint_file(python_file)
for f in file:
lint_file(f)
Copy link
Member

Choose a reason for hiding this comment

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

The idea here is to filter files. Here you are adding new ones.
I guess we should iterate over file or glob for *.py when it is empty,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean that there may be file that aren't .py ones and we should filter them ?

Copy link
Member

@nim65s nim65s Aug 2, 2023

Choose a reason for hiding this comment

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

I was not clear, sorry for that.
I mean that if we have the following structure:

├── 1_example_notebook.ipynb
├── 2_other_notebook.ipynb
├── tp1
│   ├── cholesky.py
│   └── example_script.py
└── tp2
    ├── cholesky.py
    └── something.py
  • with no tp_id and no file, we should find all 4 python files
  • with tp_id=1 and no file, we should get the 2 python files in tp1
  • with no tp_id and file=tp1/cholesky.py, we should get 1 python file in tp1
  • with tp_id=1 and file=tp1/cholesky.py, we should get 1 python file in tp1
  • with tp_id=2 and file=tp1/cholesky.py, we should get 0 python files

We'll also have to add -F / --filter to allow:

  • with no tp_id and no file and filter=cholesky, we should get 2 python files, one in each tp

But that's for a separate future PR I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem, understood

gepetuto/test.py Outdated
Comment on lines 18 to 23
LOG.debug(f"Checking {python_file}")
check_call(["python", python_file])
check_ipynb(n)
for f in file:
LOG.debug(f"Checking {f}")
check_call(["python", f])
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Member

@nim65s nim65s left a comment

Choose a reason for hiding this comment

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

This is not easy. I think we'll need to unit test this behaviour. For just the sake of this PR, we can merge it if you run manual tests with debug on a test folder and check that the logs correspond to what we want.

gepetuto/lint.py Outdated
lint_file(python_file)
elif python_file in file:
lint_file(python_file)
if tp_id == []:
Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this condition can be true. tp_id wil either be defined by the user to not the empty list, or not be defined by the user and auto-populated from get_tp_id()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if someone has no tp folder and doesn't specify tp_id it could happen but i agree it shouldn't, should I still remove it ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think the logic between this if and its previous block should be changed. Probably we don't want to glob on *.py if -f is provided.

This was referenced Aug 7, 2023
@TheoMF TheoMF force-pushed the script_args_#10 branch 4 times, most recently from ea76c66 to 6ddcfa6 Compare August 7, 2023 12:48
Copy link
Member

@nim65s nim65s left a comment

Choose a reason for hiding this comment

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

This looks better, thanks !

@@ -7,6 +7,7 @@ repos:
rev: v0.0.281
hooks:
- id: ruff
exclude: gepetuto/magic.py
Copy link
Member

Choose a reason for hiding this comment

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

This won't prevent manual runs of ruff . to fail. I think you should instead add hints in the file : either a # noqa: F821 in the end of each line where there is a get_ipython, or a # ruff: noqa: F821 at the begining of the file.

A better solution might be to add a def run(self, magic) method, which run get_ipython().run_line_magic(magic) with the correct noqa only once, and use this method in the other places.

LOG.debug(f"Checking {python_file}")
check_call([python_interpreter, python_file])
check_ipynb(n, python_interpreter)
tp_id = int(str(files[0])[2]) # get the tp id of the first file
Copy link
Member

Choose a reason for hiding this comment

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

Ok, we'll probably want to move to a {tp_number: [list of files in this tp]} structure at some point, but this is fine for now

@nim65s nim65s merged commit d2040ce into Gepetto:main Aug 8, 2023
1 check passed
@nim65s nim65s mentioned this pull request Aug 8, 2023
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.

Add python script selection in argparse
2 participants