-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
"""Add "lint" action for the "gepetuto" program.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
from subprocess import check_call | ||
from typing import List | ||
|
||
LOG = logging.getLogger("gepetuto.lint") | ||
|
||
|
||
def lint(tp_id: List[int], **kwargs): | ||
def lint(files, **kwargs): | ||
"""Lint python scripts.""" | ||
LOG.info("linting tutorial sources.") | ||
for n in tp_id: | ||
LOG.debug(f"Looking for tp {n}") | ||
lint_tp_folder(n) | ||
for f in files: | ||
lint_folder(f) | ||
LOG.info("lint done.") | ||
|
||
|
||
def lint_tp_folder(tp_number): | ||
"""Lint python scripts for a given tp_number.""" | ||
LOG.debug(f"Looking for tp {tp_number}") | ||
folder = Path(f"tp{tp_number}") | ||
for python_file in folder.glob("*.py"): | ||
LOG.debug(f"Checking {python_file}") | ||
check_call(["isort", python_file]) | ||
check_call(["black", python_file]) | ||
check_call(["ruff", "--fix", python_file]) | ||
def lint_folder(file): | ||
"""Lint python scripts in folder.""" | ||
LOG.debug(f"Checking {file}") | ||
check_call(["isort", file]) | ||
check_call(["black", file]) | ||
check_call(["ruff", "--fix", file]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,28 @@ | |
import logging | ||
from pathlib import Path | ||
from subprocess import check_call | ||
from typing import List | ||
|
||
LOG = logging.getLogger("gepetuto.test") | ||
|
||
|
||
def test(tp_id: List[int], **kwargs): | ||
def test(files, **kwargs): | ||
"""Test python scripts.""" | ||
python_interpreter = kwargs["python"] | ||
LOG.info("testing tutorial sources.") | ||
for n in tp_id: | ||
LOG.debug(f"Looking for tp {n}") | ||
folder = Path(f"tp{n}") | ||
for python_file in folder.glob("*.py"): | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, we'll probably want to move to a |
||
check_ipynb(tp_id, python_interpreter) | ||
for f in files: | ||
LOG.debug(f"Checking {f}") | ||
check_call([python_interpreter, f]) | ||
current_tp_id = int(str(f)[2]) | ||
if tp_id != current_tp_id: | ||
tp_id = current_tp_id | ||
check_ipynb(current_tp_id, python_interpreter) | ||
LOG.info("test passed.") | ||
|
||
|
||
def check_ipynb(tp_number, python_interpreter): | ||
"""Check .ipynb files from given tp_number and move it in temporary folder.""" | ||
"""Check .ipynb files from given tp_number.""" | ||
ipynb = next(Path().glob(f"{tp_number}_*.ipynb")) | ||
check_call(["jupyter", "nbconvert", "--to", "script", f"{ipynb}"]) | ||
converted_ipynb = next(Path().glob(f"{tp_number}_*.py")) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 aget_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 runget_ipython().run_line_magic(magic)
with the correct noqa only once, and use this method in the other places.