python-trio / unasync

The async transformation code.
Other
91 stars 13 forks source link

Add unasync.unasync_files() API #58

Closed pquentin closed 4 years ago

pquentin commented 4 years ago

It allows to run unasync on multiple files using multiples rules if needed, without being tied to setuptools.

@sethmlarson Now that you taught me that using Rule.unasync_files directly made sense, I'm not sure if this is such a good idea. Right now, I have a proof-of-concept that works in hip using this API:

import unasync

unasync.unasync_files(
    [
        "test/with_dummyserver/sync/__init__.py",
        "test/with_dummyserver/async/test_poolmanager.py",
    ],
    rules=[
        unasync.Rule(
            "test/with_dummyserver/async",
            "test/with_dummyserver/sync",
            replacements={
                "AsyncPoolManager": "PoolManager",
                "test_all_backends": "test_sync_backend",
            },
        )
    ],
)

Since I have only a single rule, I guess I could use Rule.unasync_file and loop over files. This pull request feels more general, and since I already had the code, I submitted it. Please tell me what you think.

codecov[bot] commented 4 years ago

Codecov Report

Merging #58 into master will increase coverage by 0.03%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   97.60%   97.63%   +0.03%     
==========================================
  Files           2        2              
  Lines         125      127       +2     
  Branches       31       31              
==========================================
+ Hits          122      124       +2     
  Misses          1        1              
  Partials        2        2              
Impacted Files Coverage Δ
src/unasync/__init__.py 97.61% <100.00%> (+0.03%) :arrow_up:
pquentin commented 4 years ago

Maybe we can transition the Rule interface to be private with this PR :)

Will open another PR for that + switch back to additional_replacements, then we can cut a release.