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

🐛 Handle Boolean Arg Parsing in Compiler #354

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

MFA-X-AI
Copy link
Member

@MFA-X-AI MFA-X-AI commented Aug 26, 2024

Description

The current way the compiler handles boolean arguments looks like this:

parser.add_argument('--testArgs', type=bool)

Unfortunately, this means that regardless of what is passed to --testArgs, whether it's False or 0, it's first converted to a string and then passed to the bool() function, hence always evaluating to True.

This PR adds parse_bool to base.py to handle this issue. The new implementation looks like this:

parser.add_argument('--testArgs', type=parse_bool, default=None, nargs='?', const=True)

What this does:

  • It will return False if provided with 'false', 'f', 'no', 'n', or '0' (not case-sensitive).
  • If the argument is not provided at all, it will be None.
  • If the flag is provided without a value (like just --testArgs), it will be True.

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Tests

Create a workflow that accepts a boolean argument and prints it, eg

image

Test that:

  • It will return False if provided with 'false', 'f', 'no', 'n', or '0' (not case-sensitive).
  • If the argument is not provided at all, it will be None.
  • If the flag is provided without a value (like just --testArgs), it will be True.

Test for both CLI and in Xircuits execute runner interface.

Tested on?

  • Windows
  • Linux Ubuntu
  • Centos
  • Mac
  • Others (State here -> xxx )

Copy link

Binder 👈 Launch a binder notebook on branch XpressAI/xircuits/fahreza-fix-args-bool

@MFA-X-AI MFA-X-AI merged commit e6ecc46 into master Sep 9, 2024
9 checks passed
@MFA-X-AI MFA-X-AI deleted the fahreza-fix-args-bool branch September 9, 2024 08:41
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.

1 participant