Skip to main content

Upgrade python project from paddle-1.x to paddle-2.0

Project description

Upgrade your python model from paddle-1.x to paddle-2.0

Change Spec

change_spec is a python dict defined in spec.py, it defines the rules to refactor your code.

change_spec = {
    "path.to.old_api": {
        "alias": [
            "path.to.old_api_alias1",
            "path.to1.to2.old_api_alias2",
            ],
        "update_to": "path.to.new_api",
        "warning": "this api is deprecated.",
        "args_list": ["arg1", "arg2"],
        "args_change": [
                ["arg2", "arg2_rename"],
                ["arg3", ""],
                ["", "new_arg", "default_value"],
            ],
        "args_warning": {"arg1":"warning message"},
        "args_transformer": "_default_transformer",
    },
}
  • alias: a list of alias of main alias path.to.old_api, all alias will be replaced with main alias.
  • update_to: path.to.old_api will be replaced with this new api if specified.
  • warning: print specified warning message when path.to.old_api is found. This field will be ignored if update_to is specified.
  • args_list: is argument list of path.to.old_api.
  • args_change: a list of list. It contains following format:
    • ["arg", "new_arg"]: rename a argument, e.g. func(arg=value) -> func(new_arg=value)
    • ["arg", ""]: remove a argument, e.g. func(arg=value) -> func()
    • ["", "new_arg", "default_value"]: add a new argument, e.g. func(arg=value) -> func(arg=value, new_arg=default_value)
  • args_warning: print specified warning message for specified argument after apply args_change.
  • args_transformer: execute customized transformer on an AST node, it will be called after applying args_change to do further refactor.

Install

  1. install with pip
pip install -U paddle1to2
paddle1to2 --help # show help
paddle1to2 --inpath /path/to/model.py # upgrade your model from paddle-1.x to paddle-2.0
  1. install from source
git clone https://github.com/T8T9/paddle1to2.git
cd paddle1to2
python setup.py sdist bdist_wheel
pip install -U ./dist/paddle1to2-*.whl
paddle1to2 --help # show help
paddle1to2 --inpath /path/to/model.py # upgrade your model from paddle-1.x to paddle-2.0

Develop

If you are a develop, and you want to test your code quickly, you can run the following command in project directory:

python -m paddle1to2 --inpath /path/to/model.py

#or 

python paddle1to2/main.py --inpath /path/to/model.py

Moreover, if you want to run a specific refactor, you can use the following command:

python -m paddle1to2 --inpath /path/to/model.py --refactor <refactor_name>

use python -m paddle1to2 -h to see full list of all refactors.

if you want to run all unittest, use command:

python -m unittest discover paddle1to2/tests/

or use command:

python -m unittest paddle1to2/tests/test_refactor.py

to run specific test file.

Other Tools

  1. find pattern of specific code snippet, usage:
find_pattern 'import paddle'

find_pattern command will traverse all nodes in AST, if you see code snippet you want, type in 'y' to get pattern.

  1. find match node in specific code for specific pattern, usage:
find_match_node -ss 'import paddle' -ps 'any'

you can also specify "--print-results" option to got representation of matched node, specify "--print-lineno" to got line number of matched code.

Acknowledgements

  • Bowler: Safe code refactoring for modern Python projects.
  • lib2to3: A built-in python library to refactor python code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paddle1to2-0.0.5.tar.gz (158.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paddle1to2-0.0.5-py3-none-any.whl (207.2 kB view details)

Uploaded Python 3

File details

Details for the file paddle1to2-0.0.5.tar.gz.

File metadata

  • Download URL: paddle1to2-0.0.5.tar.gz
  • Upload date:
  • Size: 158.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.10

File hashes

Hashes for paddle1to2-0.0.5.tar.gz
Algorithm Hash digest
SHA256 71c0d7d51ba658e9e6b343e6c2e33f16d31e92791c20c966d8f8123bcb978ded
MD5 d2aeb4756c7f188af7bb6c9937d63398
BLAKE2b-256 dd152560a057ac5ea4e67bccac666d3e554a43e677bd5a29013931cfe372a570

See more details on using hashes here.

File details

Details for the file paddle1to2-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: paddle1to2-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 207.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.10

File hashes

Hashes for paddle1to2-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d2467fb938f2272a2f1082c9fbe46fda7bd6c1f2bdb09d115770475bb9cdaeee
MD5 bc5d88f9fc436b6be32eb524585c2ed6
BLAKE2b-256 770ed3da4546f2513aecefecc01d1fe97d8b5c2548ba7e851e0897ffdb92e0e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page