Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

vite-falcon
Copy link
Contributor

It wasn't set previously because importlib searches for the distribution name and not the module's top-level name. Fallbacks are in place to revert to searching for 'pdl', and if that fails, it fallsback to the hardcoded version in _version.py

The value of pdl.__version__ shows "0.6.0" in my Python package which depends on prompt-declaration-language library.

Notes

Unit-test

The unit-test added with this change doesn't pick up the public version. It returned 0.1.dev1051+ga202a3d as the version, which is different from the one hardcoded in _version.py file; 0.1.dev1060+g3e3e31c.d20250408.

To avoid test failures, for now and in the near future, the checks I added were to make sure that pdl.__version__ was not None, and that it started with "0.1.dev".

Testing Done

Unit-test in my package:

from packaging.version import Version

import pdl


def test_pdl_version():
    """Test PDL version is correct."""
    assert Version(pdl.__version__) >= Version("0.6.0")

The test passed.

Pre-commit in prompt-declaration-language library

uv run pre-commit run --all-files

check for case conflicts.................................................Passed
check for merge conflicts................................................Passed
debug statements (python)................................................Passed
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Passed
pylint...................................................................Passed
bandit...................................................................Passed
mypy.....................................................................Passed
- hook id: mypy
- duration: 0.25s

Success: no issues found in 62 source files

pyright..................................................................Passed

Pytest in prompt-declaration-language library

NOTE: Any litellm related tests fail.

uv run pytest tests/

=========================================================================== test session starts ===========================================================================platform linux -- Python 3.12.3, pytest-8.3.5, pluggy-1.5.0
rootdir: /home/user/prompt-declaration-language
configfile: pyproject.toml
plugins: langsmith-0.3.27, anyio-4.9.0
collected 265 items                                                                                                                                                       

tests/test_array.py ...                                                                                                                                             [  1%]
tests/test_ast_utils.py .                                                                                                                                           [  1%]
tests/test_code.py ..............                                                                                                                                   [  6%]
tests/test_cond.py ........                                                                                                                                         [  9%]
tests/test_data.py .......                                                                                                                                          [ 12%]
tests/test_defaults.py .......                                                                                                                                      [ 15%]
tests/test_defs.py ...                                                                                                                                              [ 16%]
tests/test_dump.py .                                                                                                                                                [ 16%]
tests/test_errors.py ...                                                                                                                                            [ 17%]
tests/test_examples_parse.py .                                                                                                                                      [ 18%]
tests/test_examples_run.py F                                                                                                                                        [ 18%]
tests/test_expr.py ...............                                                                                                                                  [ 24%]
tests/test_fallback.py .......                                                                                                                                      [ 26%]
tests/test_for.py .........                                                                                                                                         [ 30%]
tests/test_function.py .......                                                                                                                                      [ 32%]
tests/test_include.py ..                                                                                                                                            [ 33%]
tests/test_input.py ...                                                                                                                                             [ 34%]
tests/test_lib_version.py .                                                                                                                                         [ 35%]
tests/test_line_table.py ............................                                                                                                               [ 45%]
tests/test_linter.py ...........................                                                                                                                    [ 55%]
tests/test_match.py ............................                                                                                                                    [ 66%]
tests/test_messages.py .....                                                                                                                                        [ 68%]
tests/test_model.py .......                                                                                                                                         [ 70%]
tests/test_object.py ..                                                                                                                                             [ 71%]
tests/test_parse.py .                                                                                                                                               [ 72%]
tests/test_parser.py ...........                                                                                                                                    [ 76%]
tests/test_repeat.py ......................                                                                                                                         [ 84%]
tests/test_role.py .                                                                                                                                                [ 84%]
tests/test_runtime_errors.py ..........                                                                                                                             [ 88%]
tests/test_schema.py .                                                                                                                                              [ 89%]
tests/test_type_checking.py .......................                                                                                                                 [ 97%]
tests/test_var.py ......                                                                                                                                            [100%]

================================================================================ FAILURES =================================================================================___________________________________________________________________________ test_valid_programs ___________________________________________________________________________
capsys = <_pytest.capture.CaptureFixture object at 0x78121ad12ff0>, monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x781223337620>

    def test_valid_programs(capsys: CaptureFixture[str], monkeypatch: MonkeyPatch) -> None:
        actual_parse_error: set[str] = set()
        actual_runtime_error: set[str] = set()
        wrong_results = {}
    
        files = pathlib.Path(".").glob("**/*.pdl")
    
        for pdl_file_name in files:
    
            scope: ScopeType = PdlDict({})
            if str(pdl_file_name) in TO_SKIP:
                continue
            if str(pdl_file_name) in TESTS_WITH_INPUT:
                inputs = TESTS_WITH_INPUT[str(pdl_file_name)]
                if inputs.stdin is not None:
                    monkeypatch.setattr(
                        "sys.stdin",
                        io.StringIO(inputs.stdin),
                    )
                if inputs.scope is not None:
                    scope = inputs.scope
            try:
                random.seed(11)
                output = pdl.exec_file(
                    pdl_file_name,
                    scope=scope,
                    output="all",
                    config=pdl.InterpreterConfig(batch=0),
                )
                actual_result = output["result"]
    
                block_to_dict(output["trace"], json_compatible=True)
                result_dir_name = (
                    pathlib.Path(".") / "tests" / "results" / pdl_file_name.parent
                )
    
                if not __find_and_compare_results(pdl_file_name, str(actual_result)):
    
                    if OLLAMA_GHACTIONS_RESULTS:
                        print(
                            f"Program {str(pdl_file_name)} requries updating its result on GitHub Actions"
                        )
                        print(f"Actual results: {str(actual_result)}")
                        result_file_name = f"{pdl_file_name.stem}.ollama_ghactions.result"
                        __write_to_results_file(
                            result_dir_name, result_file_name, str(actual_result)
                        )
    
                        # Evaluate the results again. If fails again, then consider this program as failing
                        if not __find_and_compare_results(
                            pdl_file_name, str(actual_result)
                        ):
                            print(
                                f"Program {str(pdl_file_name)} failed second time even after generating results from Github Actions. Consider this failing!"
                            )
                            wrong_results[str(pdl_file_name)] = {
                                "actual": str(actual_result),
                            }
                        # If evaluating results produces correct result, then this is considered passing
                        else:
                            continue
    
                    if UPDATE_RESULTS:
                        result_file_name = (
                            f"{pdl_file_name.stem}.{str(RESULTS_VERSION)}.result"
                        )
                        __write_to_results_file(
                            result_dir_name, result_file_name, str(actual_result)
                        )
    
                    wrong_results[str(pdl_file_name)] = {
                        "actual": str(actual_result),
                    }
            except PDLParseError:
                actual_parse_error |= {str(pdl_file_name)}
            except Exception as exc:
                if str(pdl_file_name) not in set(str(p) for p in EXPECTED_RUNTIME_ERROR):
                    print(f"{pdl_file_name}: {exc}")  # unexpected error: breakpoint
                actual_runtime_error |= {str(pdl_file_name)}
                print(exc)
    
        # Parse errors
        expected_parse_error = set(str(p) for p in EXPECTED_PARSE_ERROR)
        unexpected_parse_error = sorted(list(actual_parse_error - expected_parse_error))
        assert (
            len(unexpected_parse_error) == 0
        ), f"Unexpected parse error: {unexpected_parse_error}"
    
        # Runtime errors
        expected_runtime_error = set(str(p) for p in EXPECTED_RUNTIME_ERROR)
        unexpected_runtime_error = sorted(
            list(actual_runtime_error - expected_runtime_error)
        )
>       assert (
            len(unexpected_runtime_error) == 0
        ), f"Unexpected runtime error: {unexpected_runtime_error}"
E       AssertionError: Unexpected runtime error: ['examples/chatbot/chatbot.pdl', 'examples/code/code-eval.pdl', 'examples/code/code-json.pdl', 'examples/code/code.pdl', 'examples/demo/1-hello.pdl', 'examples/demo/10-sdg.pdl', 'examples/demo/2-model-chaining.pdl', 'examples/demo/3-def-use.pdl', 'examples/demo/4-function.pdl', 'examples/demo/5-code-eval.pdl', 'examples/demo/6-code-json.pdl', 'examples/demo/7-chatbot-roles.pdl', 'examples/demo/8-tools.pdl', 'examples/demo/9-react.pdl', 'examples/fibonacci/fib.pdl', 'examples/gsm8k/gsm8k-plan-few-shots.pdl', 'examples/rag/tfidf_rag.pdl', 'examples/react/demo.pdl', 'examples/sdk/hello.pdl', 'examples/teacher/teacher.pdl', 'examples/tools/calc.pdl', 'examples/tutorial/calling_llm.pdl', 'examples/tutorial/calling_llm_chaining.pdl', 'examples/tutorial/calling_llm_with_input.pdl', 'examples/tutorial/calling_llm_with_input_messages.pdl', 'examples/tutorial/calling_llm_with_input_messages_var.pdl', 'examples/tutorial/code_pdl.pdl', 'examples/tutorial/defs.pdl', 'examples/tutorial/function_definition.pdl', 'examples/tutorial/function_empty_context.pdl', 'examples/tutorial/muting_block_output.pdl', 'examples/tutorial/parser-regex.pdl', 'examples/tutorial/parser_regex_code.pdl', 'examples/tutorial/programs/chatbot.pdl', 'examples/tutorial/programs/code-json.pdl', 'examples/tutorial/programs/tfidf_rag.pdl', 'examples/tutorial/programs/weather.pdl', 'examples/tutorial/variable_def_use.pdl', 'pdl-live-react/src-tauri/tests/cli/model-input-array.pdl', 'pdl-live-react/src-tauri/tests/cli/model-input-string.pdl', 'pdl-live-react/src-tauri/tests/cli/read-stdin.pdl']
E       assert 41 == 0
E        +  where 41 = len(['examples/chatbot/chatbot.pdl', 'examples/code/code-eval.pdl', 'examples/code/code-json.pdl', 'examples/code/code.pdl', 'examples/demo/1-hello.pdl', 'examples/demo/10-sdg.pdl', ...])

tests/test_examples_run.py:259: AssertionError

It wasn't set previously because importlib searches for the distribution
name and not the module's top-level name. Fallbacks are in place to
revert to searching for 'pdl', and if that fails, it fallsback to the
hardcoded version in _version.py

Signed-off-by: Abi Ullattil <[email protected]>
@vite-falcon
Copy link
Contributor Author

@mandel Sorry for the direct ping. Any chance you could help with reviewing this change?

@starpit
Copy link
Member

starpit commented Apr 16, 2025

thanks for this work! louis is on vacation right now, hence the delay on this one. thank you for the patience!

@vite-falcon
Copy link
Contributor Author

Thank you for the update @starpit!

@mandel mandel merged commit 19349ab into IBM:main Apr 30, 2025
7 checks passed
@mandel
Copy link
Collaborator

mandel commented Apr 30, 2025

Sorry for the slow answer. Thank you for the fix!

claudiosv pushed a commit that referenced this pull request May 10, 2025
It wasn't set previously because importlib searches for the distribution
name and not the module's top-level name. Fallbacks are in place to
revert to searching for 'pdl', and if that fails, it fallsback to the
hardcoded version in _version.py

Signed-off-by: Abi Ullattil <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>
claudiosv added a commit that referenced this pull request May 19, 2025
* feat: remove tauri cli support for running python interpreter

This also updates the tauri cli to rename runr -> run (run previously invoked the python interpreter).
And adds stub support for --data, --data-file, --trace command line options (not implemented yet).

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump rust dependencies to resolve alert

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* test: tauri github actions test should apt install the deb

This also removes the beeai compiler test in that workflow, as we now cover that in the core rust interpreter tests.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: support for --data and --data-file in rust interpreter

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Add optimizer module

Signed-off-by: Claudio Spiess <[email protected]>

* Remove BAM

Signed-off-by: Claudio Spiess <[email protected]>

* Initial prompt library

Signed-off-by: Claudio Spiess <[email protected]>

* Clean up & bring in changes

Signed-off-by: Claudio Spiess <[email protected]>

* AST dump fixes

Signed-off-by: Claudio Spiess <[email protected]>

* Documentation and fixes

Signed-off-by: Claudio Spiess <[email protected]>

* Finish prompt lib docs

Signed-off-by: Claudio Spiess <[email protected]>

* Address feedback

Signed-off-by: Claudio Spiess <[email protected]>

* Lint

Signed-off-by: Claudio Spiess <[email protected]>

* fix: begin phasing in Metadata (common defs, etc. attrs) into rust AST

Rather than duplicating this "metadata" logic -- the stuff common to all non-literal blocks. This just starts the migration. The main trick is to use the serde `flatten` capability, so that we can maintain a separate Metadata struct in Rust, but have it flattened into the enclosing object for serde.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: update granite-io dependency (#896)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* refactor: move def attr into Metadata (rust interpreter)

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: introduce Expr typing and apply it to IfBlock.condition

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: update rust Call AST to use Expr for condition attr

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump to rust 2024 edition

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: continue to flesh out block metadata structure in rust

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* refactor: add metadata attr to remaining rust block asts

This also adds initial scaffolding for timing, and adds a ModelBlock and ArrayBlockBuilder.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: update rust Repeat AST to use Expr for `for` attr (#904)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* refactor: introduce Advanced enum to rust AST

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* refactor: refactor rust ast to place metadata in common struct

And start populating the timing info (incomplete).

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: improve deserialization of python-generated model block traces

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: in rust ast, allow ModelBlock model to be an expr

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: initial pdl__id and --trace support for rust interpreter

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: update rust interpreter to create Data blocks for expr eval, and model_input trace field

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: populate trace context field in rust interpreter

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Update stop sequences in parameters (#861)

* Stop sequence parameter update to align with ollama

Signed-off-by: Jing Chen <[email protected]>

* Update results

Signed-off-by: Jing Chen <[email protected]>

---------

Signed-off-by: Jing Chen <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* refactor: extract platform-generic logic from run_ollama_model() handler

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: rust interpreter was not handling pdl__context for re-runs of traces

This only covers the run_model code path, but it's a start.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: improve support for importing stdlib in python code blocks

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* skeleton-of-thought example (#919)

Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Bump litellm and openai versions (#920)

Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: improve support for rust interpreter python imports from venv

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump tauri and npm dependencies

And leverage the new prevent overflow feature of tauri.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump ui to 0.6.1 (#921)

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: rust ast support for gsm8k, including jsonl parser

The program may not run 100% yet, but it parses now.

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump rust dependencies

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: improve support for tool calling in ollama-rs

We need to send a system prompt to some models. Plus add some stubs for pydantic for python tool execution.

This also includes nascent support for openai-rs (not fully funcitonal yet).

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Fully qualify import (#930)

Signed-off-by: Ed Snible <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: some regex parser support for rust interpreter

Split mode TODO!

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Change to sys.path for python code block (#931)

Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* granite-io hallucination demo example and notebook (#932)

Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Lint

Signed-off-by: Claudio Spiess <[email protected]>

* Refactor

Signed-off-by: Claudio Spiess <[email protected]>

* Tests

Signed-off-by: Claudio Spiess <[email protected]>

* Formatting

Signed-off-by: Claudio Spiess <[email protected]>

* Lint

Signed-off-by: Claudio Spiess <[email protected]>

* Skip tests for now

Signed-off-by: Claudio Spiess <[email protected]>

* Update schema

Signed-off-by: Claudio Spiess <[email protected]>

* Add contrib. prompt library (#927)

* Initial prompt library

Signed-off-by: Claudio Spiess <[email protected]>

* Documentation and fixes

Signed-off-by: Claudio Spiess <[email protected]>

* Finish prompt lib docs

Signed-off-by: Claudio Spiess <[email protected]>

* Address feedback

Signed-off-by: Claudio Spiess <[email protected]>

---------

Signed-off-by: Claudio Spiess <[email protected]>

* Fixed the bug where pdl.__version__ was not set (#882)

It wasn't set previously because importlib searches for the distribution
name and not the module's top-level name. Fallbacks are in place to
revert to searching for 'pdl', and if that fails, it fallsback to the
hardcoded version in _version.py

Signed-off-by: Abi Ullattil <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* chore: update pre-commit tools (#937)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Use granite-io async interface (#936)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Lint

Signed-off-by: Claudio Spiess <[email protected]>

* chore: bump ui dependences

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* fix: skip failing execution tests (#938)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* independent implementation (#934)

* independent implementation

Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* feat: add a `parse_dict` function to `pdl_parser` (#943)

Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>

* Address feedback 1

Signed-off-by: Claudio Spiess <[email protected]>

* Address feedback 2

Signed-off-by: Claudio Spiess <[email protected]>

* Lint & fix mypy module warning

Signed-off-by: Claudio Spiess <[email protected]>

* Skip tests again

Signed-off-by: Claudio Spiess <[email protected]>

* Try to resolve wikipedia package in ci

Signed-off-by: Claudio Spiess <[email protected]>

* Fix rebase

Signed-off-by: Claudio Spiess <[email protected]>

* Fix pyproject

Signed-off-by: Claudio Spiess <[email protected]>

* Move multiprocess to optional

Signed-off-by: Claudio Spiess <[email protected]>

* Add ipython to pdl-live

Signed-off-by: Claudio Spiess <[email protected]>

* Fix trace metadata

Signed-off-by: Claudio Spiess <[email protected]>

* Add documentation

Signed-off-by: Claudio Spiess <[email protected]>

* Add optimizer test PDL

Signed-off-by: Claudio Spiess <[email protected]>

* Add config and expand docs

Signed-off-by: Claudio Spiess <[email protected]>

---------

Signed-off-by: Nick Mitchell <[email protected]>
Signed-off-by: Claudio Spiess <[email protected]>
Signed-off-by: Louis Mandel <[email protected]>
Signed-off-by: Jing Chen <[email protected]>
Signed-off-by: Mandana Vaziri <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
Signed-off-by: Abi Ullattil <[email protected]>
Co-authored-by: Nick Mitchell <[email protected]>
Co-authored-by: Louis Mandel <[email protected]>
Co-authored-by: Jing Chen <[email protected]>
Co-authored-by: Mandana Vaziri <[email protected]>
Co-authored-by: Nick Mitchell <[email protected]>
Co-authored-by: Ed Snible <[email protected]>
Co-authored-by: Abi Ullattil <[email protected]>
mandel pushed a commit that referenced this pull request Jun 3, 2025
It wasn't set previously because importlib searches for the distribution
name and not the module's top-level name. Fallbacks are in place to
revert to searching for 'pdl', and if that fails, it fallsback to the
hardcoded version in _version.py

Signed-off-by: Abi Ullattil <[email protected]>
mandel pushed a commit that referenced this pull request Jun 3, 2025
It wasn't set previously because importlib searches for the distribution
name and not the module's top-level name. Fallbacks are in place to
revert to searching for 'pdl', and if that fails, it fallsback to the
hardcoded version in _version.py

Signed-off-by: Abi Ullattil <[email protected]>
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.

3 participants