diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000000000000000000000000000000000..eb8bd95f41a5715a8a87db4d084fb82a589deab4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf + +[*.bat] +indent_style = tab +end_of_line = crlf + +[LICENSE] +insert_final_newline = false + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..368edd3a10f8f67111c36eef89b6dd7200340c05 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0e40fe8f57160b43f9ea8e200b1a5d9f91f4aed9 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/auto_py2to3.iml b/.idea/auto_py2to3.iml new file mode 100644 index 0000000000000000000000000000000000000000..121cd10e67018128c00049a3d7cf1dbad5f5091c --- /dev/null +++ b/.idea/auto_py2to3.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..abf7b39653d6d6b012e2a54f9693c1250f8ce346 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..67953d0891c04acbd22d967858e116ccf4c6ceeb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..9661ac713428efbad557d3ba3a62216b5bb7d226 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000000000000000000000000000000000000..4ddfd295c869bb2fcda0b95a1782ae5bd2cbac22 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,13 @@ +======= +Credits +======= + +Development Lead +---------------- + +* 61Duke + +Contributors +------------ + +None yet. Why not be the first? diff --git a/HISTORY.rst b/HISTORY.rst new file mode 100644 index 0000000000000000000000000000000000000000..331f2ff0a5dd0cf2e0586095311f3299a37ee591 --- /dev/null +++ b/HISTORY.rst @@ -0,0 +1,7 @@ +======= +History +======= + +0.1.0 (2020-06-08) - unknown +------------------ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..1c322ce1772c9c4fbb77337bae5b95e94234eeed --- /dev/null +++ b/LICENSE @@ -0,0 +1,60 @@ +Mulan Permissive Software License,Version 2 (Mulan PSL v2) + +January 2020 http://license.coscl.org.cn/MulanPSL2 + +Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + +0. Definition + +Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + +Contribution means the copyrightable work licensed by a particular Contributor under this License. + +Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + +Legal Entity means the entity making a Contribution and all its Affiliates. + +Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + +1. Grant of Copyright License + +Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + +2. Grant of Patent License + +Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + +3. No Trademark License + +No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4. + +4. Distribution Restriction + +You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + +5. Disclaimer of Warranty and Limitation of Liability + +THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +6. Language + +THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + +END OF THE TERMS AND CONDITIONS + +How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + +To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + +Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; +Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package; +Attach the statement to the appropriate annotated syntax at the beginning of each source file. +Copyright (c) [Year] [name of copyright holder] +[Software Name] is licensed under Mulan PSL v2. +You can use this software according to the terms and conditions of the Mulan PSL v2. +You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PSL v2 for more details. \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index d788ab63364948e39137b4a932c2056199fa4854..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# auto_py2to3 - -#### Description -The ultimate purpose of the library is to enable automated and rapid code migration and provide automated testing. - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index f0b2c7659e6c79fc9b18dd1e5d870cbecf468efd..ae9db6ff375b467985a02ee7e8525961a5f28e7e 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,50 @@ # auto_py2to3 #### 介绍 -The ultimate purpose of the library is to enable automated and rapid code migration and provide automated testing. + +2020年1月1日,Python 2代码库被冻结。从那天开始,Python 2不再有进一步的移植,这实际上使该语言和运行时环境过时了。 +核心开发人员Nick Coghlan在常见问题解答中进行了解释,从而结束了“核心开发团队同时维护Python 2和3作为参考解释器大约13年的情况”。 +Python 2的最终版本目前正在通过beta测试和候选发布阶段,并且最终的生产级版本python 2.7.18有望在2020年4月发布。 +尽管Python社区中的大多数人都认为Python需要急切更改-尤其是因为已经存在急需的Unicode支持。 +但是许多人对Python 2代码运行良好感到沮丧。因此,需要代码迁移,并且该库的最终目的是实现自动化和快速的代码迁移并提供自动化测试。 +在此过程中,尽管在代码迁移过程中可能存在一些不令人满意的地方,但库将继续进行迭代和维护。 + #### 软件架构 -软件架构说明 +* TODO 预计2020年6月20日完成软件架构流程搭建文档,6月底完成代码架构搭建。 -#### 安装教程 +#### 版本支持 -1. xxxx -2. xxxx -3. xxxx +* TODO 2.7 to 3.7 -#### 使用说明 +#### 开发计划流程 -1. xxxx -2. xxxx -3. xxxx +* TODO -#### 参与贡献 +1. 单文件的2to3,跑测试用例。 +2. 单文件2to3,依赖库版本检索和分析,跑测试用例。 +3. 单文件2to3, 依赖库版本升级以及对应函数升级,跑测试用例。 +4. 简单项目架构所有py文件整体转,跑测试用例。 +5. 测试几个主流库的转换效果,并修改优化bug。 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +语法层面转换Tips + 1. Print + 2. 除法运算 + 3. Unicode + 4. Import + 5. range and xrange + 6. 迭代器的next()方法 + 7. For-loop variables + 8. 比较不可比较的类型 + 9. 四舍五入 + 10. Classes -#### 码云特技 +#### 安装教程 + +暂无 + +#### 使用说明 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 -5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +暂无 diff --git a/auto_py2to3/__init__.py b/auto_py2to3/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c681971446ca9fd102a736411df7914f47fc9166 --- /dev/null +++ b/auto_py2to3/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +"""Top-level package for auto_py2to3.""" + +__author__ = """61Duke""" +__email__ = 'loveweihaitong@foxmail.com' +__version__ = '0.1.0' diff --git a/auto_py2to3/parse/__init__.py b/auto_py2to3/parse/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..eb3a059251f1927d10a46da80aaf8497492c8e82 --- /dev/null +++ b/auto_py2to3/parse/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# auto_py2to3 is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2020-8-1 + +from .parse import ParsePyFiles diff --git a/auto_py2to3/parse/parse.py b/auto_py2to3/parse/parse.py new file mode 100644 index 0000000000000000000000000000000000000000..ae79553e67a270baf2a57e15b79cf3a7602358da --- /dev/null +++ b/auto_py2to3/parse/parse.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# auto_py2to3 is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2020-8-1 + +__all__ = ['ParsePyFiles'] + + +class ParsePyFiles(object): + """ + 解析Py文件类 + """ + def __init__(self, file_path): + """ + 读入文件内容 + :param file_path: + """ + with open(file_path, 'r') as f: + self.content = f.readlines() + + def rows_next(self): + """ + 遍历每一行内容 + :return: + """ + for con in self.content: + yield con diff --git a/auto_py2to3/py2to3.py b/auto_py2to3/py2to3.py new file mode 100644 index 0000000000000000000000000000000000000000..3b1cbf27bd7b522a9cad923e8f0e23c2bad0fb18 --- /dev/null +++ b/auto_py2to3/py2to3.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# auto_py2to3 is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2020-8-1 + +"""Main module.""" +import os + +from utils import find_all_py_files +from parse import ParsePyFiles + +transfer_abs_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/tests/test_project/" + +for file_path in find_all_py_files(path=transfer_abs_path): + for row_content in ParsePyFiles(file_path=file_path).rows_next(): + print(row_content) diff --git a/auto_py2to3/utils.py b/auto_py2to3/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..fd4080bf914712d11c75ad93680b794211eece7f --- /dev/null +++ b/auto_py2to3/utils.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# auto_py2to3 is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2020-8-1 + + +import os + + +def find_all_py_files(path): + """ + :param path: + :return: + """ + for base_path, dir_names, file_names in os.walk(path): + for real_path in [ + os.path.join(base_path, p).replace("\\", "/") for p in dir_names + file_names if ".py" in p + ]: + if real_path: + yield real_path diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000000000000000000000000000000000000..513001215430bd150147cbb73e0cb08159b50042 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,12 @@ +pip==19.2.3 +bump2version==0.5.11 +wheel==0.33.6 +watchdog==0.9.0 +flake8==3.7.8 +tox==3.14.0 +coverage==4.5.4 +Sphinx==1.8.5 +twine==1.14.0 +Click==7.0 +pytest==4.6.5 +pytest-runner==5.1 \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..d80bf5b4a377d1dcc6f89aa48c1b6b761530782b --- /dev/null +++ b/setup.py @@ -0,0 +1,70 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# auto_py2to3 is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. +# Create: 2020-8-1 + +"""The setup script.""" + +from setuptools import setup, find_packages + +with open('README.md') as readme_file: + readme = readme_file.read() + +with open('HISTORY.rst') as history_file: + history = history_file.read() + +requirements = ['Click>=7.0', ] + +setup_requirements = ['pytest-runner', ] + +test_requirements = ['pytest>=3', ] + +setup( + author="61Duke", + author_email='loveweihaitong@foxmail.com', + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Mulan PSL v2', + 'Natural Language :: English', + 'Programming Language :: Python :: 3.7', + ], + description="On January 1, 2020, the Python 2 code base was frozen. Since that day, there has been no further " + "backport of Python 2, which actually makes this language and runtime environment obsolete. Nick " + "Coghlan, the core developer, explained in the FAQ, thus ending the situation of “the core " + "development team maintains Python 2 and 3 at the same time as a reference interpreter for about 13 " + "years”. The final version of Python 2 is currently passing the beta testing and release candidate " + "stage, and the last production-level version of Python 2.7.18 is expected to be launched in April " + "2020. Although most people in the Python community agree that Python needs drastic " + "changes—especially because of the much-needed Unicode support that was already there. But many " + "people are frustrated that Python 2 code works well. Therefore, code migration is required, " + "and the ultimate purpose of the library is to enable automated and rapid code migration and provide " + "automated testing. In this process, although there may be some unsatisfactory places in the code " + "migration process, the library will continue to iterate and maintain.", + entry_points={ + 'console_scripts': [ + 'auto_py2to3=auto_py2to3.cli:main', + ], + }, + install_requires=requirements, + license="Mulan PSL v2", + long_description=readme + '\n\n' + history, + include_package_data=True, + keywords='auto_py2to3', + name='auto_py2to3', + packages=find_packages(include=['auto_py2to3', 'auto_py2to3.*']), + setup_requires=setup_requirements, + test_suite='tests', + tests_require=test_requirements, + url='https://gitee.com/weihaitong/auto_py2to3', + version='0.1.0', + zip_safe=False, +) diff --git a/tests/test_project/test_basic_27_file.py b/tests/test_project/test_basic_27_file.py new file mode 100644 index 0000000000000000000000000000000000000000..577b53813b0555a13721608d546ce6e94e6a5f3d --- /dev/null +++ b/tests/test_project/test_basic_27_file.py @@ -0,0 +1,2 @@ +if __name__ == '__main__': + print "2312312313"