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

Validating CLI arguments #561

Merged
merged 25 commits into from
Jun 8, 2023
Merged

Validating CLI arguments #561

merged 25 commits into from
Jun 8, 2023

Conversation

tl3119
Copy link

@tl3119 tl3119 commented May 31, 2023

Describe your changes

Add checking for unrecognized arguments and a test

Issue number

Closes #531

Checklist before requesting a review


📚 Documentation preview 📚: https://jupysql--561.org.readthedocs.build/en/561/

@edublancas edublancas marked this pull request as draft June 1, 2023 00:16
src/tests/test_magic.py Outdated Show resolved Hide resolved
src/tests/test_magic.py Show resolved Hide resolved
src/sql/magic.py Outdated Show resolved Hide resolved
Copy link

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

hey @mehtamohit013, can you give @tl3119 a hand? he's a bit stuck on how to approach this. you can meet on Slack and brainstorm do some pair programming session

all the relevant info is in the issue description: #531

@mehtamohit013
Copy link

mehtamohit013 commented Jun 1, 2023

hey @mehtamohit013, can you give @tl3119 a hand? he's a bit stuck on how to approach this. you can meet on Slack and brainstorm do some pair programming session

all the relevant info is in the issue description: #531

Yeah sure.

Btw @tl3119 are you on Slack, I can't seem to find you in Direct Messages?

@tl3119
Copy link
Author

tl3119 commented Jun 1, 2023

hey @mehtamohit013, can you give @tl3119 a hand? he's a bit stuck on how to approach this. you can meet on Slack and brainstorm do some pair programming session
all the relevant info is in the issue description: #531

Yeah sure.

Btw @tl3119 are you on Slack, I can't seem to find you in Direct Messages?

Yeah, I am on Slack, I have sent you a message!

Copy link

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

once your PR is ready for review, please mark it as so (this one is still marked as a draft)

doc/intro.md Outdated Show resolved Hide resolved
doc/environment.yml Outdated Show resolved Hide resolved
src/sql/magic.py Outdated Show resolved Hide resolved
src/tests/test_magic.py Outdated Show resolved Hide resolved
@tl3119 tl3119 mentioned this pull request Jun 5, 2023
@tl3119 tl3119 marked this pull request as ready for review June 5, 2023 19:56
Copy link

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

@tl3119 please request a review only when all the comments have been addressed. there are still some comments where I don't see an answer

doc/intro.md Outdated Show resolved Hide resolved
@tl3119
Copy link
Author

tl3119 commented Jun 6, 2023

All the comments and issues have been addressed now

src/tests/test_magic.py Show resolved Hide resolved
src/sql/magic.py Outdated Show resolved Hide resolved
@tl3119 tl3119 requested a review from mehtamohit013 June 6, 2023 19:22
@mehtamohit013
Copy link

@edublancas lgtm

src/sql/magic.py Outdated
def check_random_arguments(self, line="", cell=""):
# check only for cell magic
if cell != "":
tokens = line.split()

Choose a reason for hiding this comment

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

better to use shlex insted of line.split: https://docs.python.org/3/library/shlex.html#shlex.split

Choose a reason for hiding this comment

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

I just noticed we have to call if like this: shlex.split('--hello "--another"', posix=False)

so it doesn't remove any quotes inside the string

Copy link
Author

@tl3119 tl3119 Jun 7, 2023

Choose a reason for hiding this comment

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

Sure, update it to use shlex now

src/sql/magic.py Outdated
# If the token starts with "--", it is an argument
breakLoop = False
for token in tokens:
if token.startswith("--"):

Choose a reason for hiding this comment

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

there are short options as well, so we also need to check if the options start with a single dash

Copy link
Author

Choose a reason for hiding this comment

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

update it now

src/tests/test_magic.py Show resolved Hide resolved
src/tests/test_magic.py Show resolved Hide resolved
src/sql/magic.py Outdated
def check_random_arguments(self, line="", cell=""):
# check only for cell magic
if cell != "":
tokens = line.split()

Choose a reason for hiding this comment

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

I just noticed we have to call if like this: shlex.split('--hello "--another"', posix=False)

so it doesn't remove any quotes inside the string

src/tests/test_magic.py Show resolved Hide resolved
tl3119 and others added 2 commits June 7, 2023 19:38
@tl3119 tl3119 requested a review from edublancas June 8, 2023 13:01
@edublancas edublancas merged commit 3877a53 into ploomber:master Jun 8, 2023
@edublancas
Copy link

great work @tl3119 - this is gonna help users a lot!

@anupam-tiwari
Copy link

🙌🙌🙌

@tl3119
Copy link
Author

tl3119 commented Jun 8, 2023

I am happy it can help users a lot!

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.

Validating CLI arguments
4 participants