Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

  • Understand the codebase and current verb registration mechanism
  • Create a simple helper function get_verb_ast_fallback() to read environment variables
  • Use pipda's register_verb directly with the helper function
  • Update all verb decorators to pass ast_fallback=get_verb_ast_fallback("verb_name")
  • Update tests to work with the new approach
  • Verify backward compatibility
  • Fix linting issues
  • Add ENV_VARS.md documentation to mkdocs navigation
  • Link ENV_VARS.md from options.md page
  • Improve integration tests to use exec() and test actual AST fallback behavior
Original prompt

This section details on the original issue you should resolve

<issue_title>[ENH] Add environment variables to control the fallback for verbs when ast is not reachable</issue_title>
<issue_description>> It is not implemented yet, but should be easy to implement.

The proposal is like this:

Set up the following environment variable (e.g. in your .bashrc file)

export DATAR_VERB_AST_FALLBACK="piping"

Then all calls for datar verbs (e.g. select, mutate, etc) will be assumed that data is piped in (data >> select(...), instead of select(data, ...)), where AST (source code) is not retrieveable.

We can also use the environment variable for an individual verb:

# assuming select is called like: data >> select(...)
export DATAR_SELECT_AST_FALLBACK="piping"
# assuming mutate is called like: mutate(data, ...)
export DATAR_MUTATE_AST_FALLBACK="normal"

Originally posted by @pwwang in #217

Also refer to https://github.com/pwwang/pipda/blob/b03be47df24f5fbd8fdda1ff3194c6f4d8926109/pipda/verb.py#L83
for the register_verb() function.

For implementation, we just pass the value of the environment variable to register_verb(), which should implement the proposal.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codesandbox
Copy link

codesandbox bot commented Nov 6, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copilot AI changed the title [WIP] Add environment variables for verb fallback control Add environment variables to control verb AST fallback behavior Nov 6, 2025
Copilot AI requested a review from pwwang November 6, 2025 04:40
Copilot finished work on behalf of pwwang November 6, 2025 04:40
@pwwang
Copy link
Owner

pwwang commented Nov 6, 2025

@copilot We don't need to reimplement the register_verb function. We just need a helper function to get the value of the environment varable, first DATAR_MUTATE_AST_FALLBACK then DATAR_VERB_AST_FALLBACK.

For example,

def _get_verb_ast_fallback_from_env(verb):
    # first try DATAR_{verb.upper()}_AST_FALLBAK, then DATAR_VERB_AST_FALLBACK
    pass
    
# then register a verb
@register_verb(ast_fallback=_get_verb_ast_fallback_from_env("mutate"))
def mutate(...):
    ...

Copy link
Contributor Author

Copilot AI commented Nov 6, 2025

@copilot We don't need to reimplement the register_verb function. We just need a helper function to get the value of the environment varable, first DATAR_MUTATE_AST_FALLBACK then `DATAR_VERB_AST_FAL...

Done! I've simplified the implementation to use a simple helper function get_verb_ast_fallback(verb) that reads environment variables, and now we're using pipda's register_verb directly with ast_fallback=get_verb_ast_fallback("verb_name") at each verb registration.

The wrapper has been removed, and all verbs in dplyr.py, tidyr.py, tibble.py, and misc.py now use the helper function directly as you suggested.

Commit: aa8b40d

Copilot finished work on behalf of pwwang November 6, 2025 04:55
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot We should add this to either mkdocs.yml or some pages that link to this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added ENV_VARS.md to the mkdocs navigation (placed after "Options" in the nav menu) and also added a cross-reference link from the options.md page to ENV_VARS.md for better discoverability.

Commit: cfba7c4

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot The integration test is not ideal. We can have some simple verb registered:

@register_verb(ast_fallback=get_verb_ast_fallback("plus")
def plus(x, y):
  return x + y

Then test it with `DATAR_PLUS_AST_FALLBACK="piping":

# use exec to disable source code being detected at runtime
exec("plus(1, 1)")  # error
exec("1 >> plus(1)")  # 2

You can also add more verbs to test DATAR_VERB_AST_FALLBACK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved the integration tests as suggested! Now using simple registered verbs (plus, minus, multiply, divide, power, modulo) with exec() to disable AST detection at runtime. The tests verify:

  1. Piping mode (DATAR_PLUS_AST_FALLBACK="piping") - piping calls work, normal calls return placeholder
  2. Normal mode (DATAR_MINUS_AST_FALLBACK="normal") - normal calls work, piping calls raise TypeError
  3. Global fallback (DATAR_VERB_AST_FALLBACK="piping") - applies to multiple verbs
  4. Precedence - per-verb env vars override global setting

All 11 tests passing with 100% coverage on verb_env.py.

Commit: 5cc103d

Copilot AI requested a review from pwwang November 6, 2025 05:12
Copilot finished work on behalf of pwwang November 6, 2025 05:12
Copilot finished work on behalf of pwwang November 6, 2025 05:17
@pwwang pwwang marked this pull request as ready for review November 6, 2025 05:24
@pwwang pwwang merged commit 9b46e00 into master Nov 6, 2025
20 checks passed
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.

[ENH] Add environment variables to control the fallback for verbs when ast is not reachable

2 participants