akaihola / darker

Apply black reformatting to Python files only in regions changed since a given commit. For a practical usage example, see the blog post at https://dev.to/akaihola/improving-python-code-incrementally-3f7a
https://pypi.org/project/darker/
Other
633 stars 55 forks source link

flynt checks breaking with package update to flynt-0.78 #472

Closed bdperkin closed 7 months ago

bdperkin commented 1 year ago

Describe the bug TypeError when executing darker --flynt which had been working with flynt-0.77

To Reproduce Steps to reproduce the behavior:

  1. In a fresh virtualenv, pip3 install darker[flynt]
  2. Verify versions: pip3 freeze | grep -E "^(darker|flynt)" (currently: darker==1.7.0 and flynt==0.78)
  3. Run Darker with darker --flynt
  4. Get Traceback:
    
    $ pip3 freeze | grep -E "^(darker|flynt)"
    darker==1.7.0
    flynt==0.78
    $ darker --flynt
    Traceback (most recent call last):
    File "${PWD}/venv/bin/darker", line 8, in <module>
    sys.exit(main_with_error_handling())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 630, in main_with_error_handling
    return main()
           ^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 586, in main
    for path, old, new in sorted(
                          ^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 107, in format_edited_parts
    ) = future.result()
        ^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/concurrency.py", line 48, in submit
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 151, in _modify_and_reformat_single_file
    content_after_reformatting = _blacken_and_flynt_single_file(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 202, in _blacken_and_flynt_single_file
    fstringified = _maybe_flynt_single_file(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/__main__.py", line 264, in _maybe_flynt_single_file
    return apply_flynt(rev2_isorted, relpath_in_rev2, edited_linenums_differ)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/fstring.py", line 59, in apply_flynt
    return _call_flynt_fstringify(content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "${PWD}/venv/lib64/python3.11/site-packages/darker/fstring.py", line 70, in _call_flynt_fstringify
    result, _ = flynt_fstringify_code_by_line(content.string)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: fstringify_code_by_line() missing 1 required positional argument: 'state'


**Expected behavior**
No traceback and functioning as it did with flynt==0.78

**Environment**
 - LSB Version:  :core-4.1-amd64:core-4.1-noarch
 - Distributor ID:       Fedora
 - Description:  Fedora release 37 (Thirty Seven)
 - Release:      37
 - Codename:     ThirtySeven
 - Python version: Python 3.11.2
 - Git version: git version 2.39.2
 - Darker version: 1.7.0
 - Black version: black, 23.1.0 (compiled: yes); Python (CPython) 3.11.2
 - isort version: VERSION 5.10.1
 - flynt version: 0.78

**Additional context**
Running flynt standalone with this version is working.
Seems this may be the change that caused the issue: https://github.com/ikamensh/flynt/commit/e66e7f6dc00863b838b0f04faf55ec473a703964
akaihola commented 1 year ago

Thanks @bdperkin for the heads-up! This seems easy enough to fix.

I'll also consider adding similar similar automated "future" tests as we already have for upcoming Black versions (see #382 and #430).

Update: I added #473 to track this.

jedie commented 1 year ago

(currently: darker==1.7.0 and flynt==0.78)

I ran into the same problem with darker==1.7.1 and flynt==0.78 :(

jedie commented 1 year ago

Oh it's my fault: The fix is to install flynt/isort/Pygments via darker "extras", to get always compatibility version combinations, isn't it?

akaihola commented 1 year ago

Hi @jedie; yes, Flynt 0.78 compatibility will be fixed soon (see #480), and meanwhile pip install 'darker[flynt]' will ensure a compatible version of Flynt is used.