It was fun while it lasted, everyone. async2rewrite will remain here as an archived repo. It will still be on pip (for the time being), and it will still work for converting some of async to rewrite. This project will receive no more updates.
Automatically convert discord.py async branch code to rewrite branch code.
async2rewrite does not complete 100% of the necessary conversions. It is a tool designed to minimize the amount of tedious work required. async2rewrite will warn upon changes that it cannot make itself. Make sure to read the migration documentation for rewrite when using this tool.
Migration Documentation Commercial 1
python -m pip install -U async2rewrite
When converting files via the command line, async2rewrite will create a new Python file with the specified suffix. If no suffix is specified, the default suffix is used.
For file paths, a path to a directory may also be passed. The library will locate all Python files recursively inside of the passed directory.
python -m async2rewrite file/path
async2rewrite can automatically convert multiple files at once.
python -m async2rewrite file/path1 file/path2 ...
Use the --suffix
flag to denote a custom suffix to add the the new file.
The default suffix is .a2r.py
.
Example:
python -m async2rewrite file/path --suffix .my_suffix.py
If you would like to print the output instead of writing to a new file,
the --print
flag can be used.
Example:
python -m async2rewrite file/path --print
The from_file()
method returns a dictionary. The dictionary keys are the file names,
and the values can either be a tuple or a string. If stats=True
or include_ast=True
, then
from_file()
will return a tuple. The 0th index in the tuple will always be the converted code.
import async2rewrite
file_result = async2rewrite.from_file('file/path')
print(file_result['file/path']) # file_result contains the converted code.
Multiple files can be converted by passing an unpacked list into from_file()
.
Example:
results = async2rewrite.from_file('file/path', 'file/path2', 'file/path3', ...)
for converted_file in results: # from_file() returns a dictionary.
print(converted_file) # Print out the result of each file.
import async2rewrite
text_result = async2rewrite.from_text('async def on_command_error(ctx, error): pass')
print(text_result) # text_result contains the converted code.
import async2rewrite
stats = async2rewrite.from_file('file/path', stats=True)
print(stats['file/path']) # stats=True makes from_x return a collections Counter.
- Pantsu for forking and editing astunparse to not insert unnecessary parentheses.
- Reina for the logo idea
- Beta for making sweet commercials