diff --git a/.gitignore b/.gitignore index f097971f69e49f436b9460fc3e2ae81c5a442e0e..4d48f6b90eacb9e5732069c757d4138f445d2d9a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ pyporter.egg-info .idea/ .pytest_cache/ .mypy_cache/ -*.spec \ No newline at end of file +*.spec diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..39b4e9e51ad8ccfca2fad57879751fcbe8da7bae --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + name: End-of-file fixer + - id: trailing-whitespace + name: Remove trailing whitespaces + - id: check-toml + name: Check toml + - id: check-yaml + name: Check yaml + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: Sort imports + + - repo: https://github.com/google/yapf + rev: v0.40.0 + hooks: + - id: yapf + name: Format code + additional_dependencies: [toml] diff --git a/.styple.yapf b/.styple.yapf new file mode 100644 index 0000000000000000000000000000000000000000..bb30eb93025d6c89c2ee3d06c160399dec00a0eb --- /dev/null +++ b/.styple.yapf @@ -0,0 +1,4 @@ +[style] +based_on_style = pep8 +spaces_before_comment = 4 +split_before_logical_operator = true diff --git a/LICENSE b/LICENSE index ee5839968a2bf86c93283efc09d40fd050b7cfa2..5729580d9f3e175ba53043d1a8e07170ac25d4fc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ 木兰宽松许可证, 第2版 - 木兰宽松许可证, 第2版 + 木兰宽松许可证, 第2版 2020年1月 http://license.coscl.org.cn/MulanPSL2 @@ -36,15 +36,15 @@ 5. 免责声明与责任限制 - “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 6. 语言 “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 - 条款结束 + 条款结束 如何将木兰宽松许可证,第2版,应用到您的软件 - + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; @@ -55,11 +55,11 @@ 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 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. + 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. Mulan Permissive Software License,Version 2 @@ -67,25 +67,25 @@ 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: - + 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). - + + 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 + 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. @@ -111,7 +111,7 @@ To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: - i 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; + i 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; ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; @@ -120,8 +120,8 @@ 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 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. + 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. diff --git a/README.md b/README.md index 34c5cf08bac5d3403446d5cdb1a7accadeaf0828..ce966460ac261a7fcfcdef2d20924da8019dc9ce 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ pyporter -s -o python-.spec #### Contribution +You could install pre commit hook before commit your code, it will check your code format and style. + +```python +pip install pre-commit +``` +Refer https://pre-commit.com/ + 1. Fork the repository 2. Create Feat_xxx branch 3. Commit your code diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index cc3e5bc1ad7ef74cd3b747ca376044b8b6d60fa7..6de600c71a8ec3afbcb6e5240082615536a78516 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -17,34 +17,31 @@ This is a packager bot for python modules from pypi.org # Description: provide a tool to package python module automatically # ******************************************************************************/ -import urllib -import urllib.request -from pprint import pprint -from os import path -import json -import sys -import socket -import re -import datetime import argparse -import subprocess +import datetime +import hashlib +import json +import logging import os import platform -import logging +import re +import subprocess +import sys +import urllib +import urllib.request +from os import path from pathlib import Path -import hashlib + from retry import retry_call -# init logging logger = logging.getLogger() handler = logging.StreamHandler(sys.stdout) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +formatter = logging.Formatter( + '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) -# python3-wget is not default available on openEuler yet. - json_file_template = '{pkg_name}.json' name_tag_template = 'Name:\t\t{pkg_name}' summary_tag_template = 'Summary:\t{pkg_sum}' @@ -56,7 +53,6 @@ source_tag_template = 'Source0:\t{pkg_source}' buildreq_tag_template = 'BuildRequires:\t{req}' - # TODO List # 1. Need a reliable way to get description of module .. Partially done # 2. requires_dist has some dependency restirction, need to present @@ -75,9 +71,11 @@ class PyPorter: def __init__(self, args): mirror = args.mirror resp = "" - self.mirror = mirror if mirror == "" or mirror[-1] != '/' else mirror[:-1] + self.mirror = mirror if mirror == "" or mirror[ + -1] != '/' else mirror[:-1] retry_call(self.do_init, [args.arch, args.pkg, args.pkgversion], - tries=args.retry, delay=args.delay) + tries=args.retry, + delay=args.delay) def do_init(self, arch, pkg, ver=""): """ @@ -89,13 +87,14 @@ class PyPorter: else: url = self.__url_template_with_ver\ .format(pkg_name=pkg, pkg_ver=ver) - + try: with urllib.request.urlopen(url, timeout=30) as u: self.__json = json.loads(u.read().decode('utf-8')) except urllib.error.HTTPError as err: if err.code == 404: - logger.error(f"The package:{pkg} ver:{ver} does not existed on pypi") + logger.error( + f"The package:{pkg} ver:{ver} does not existed on pypi") sys.exit(1) else: raise @@ -121,11 +120,8 @@ class PyPorter: filename = s_info.get("filename") if not filename: return "" - filename = ( - filename[: -len(".tar.gz")] - if "tar.gz" in filename - else filename[: -len(".zip")] - ) + filename = (filename[:-len(".tar.gz")] + if "tar.gz" in filename else filename[:-len(".zip")]) v = self.get_version() return filename.replace("-" + v, "") return "" @@ -146,11 +142,9 @@ class PyPorter: try: home = self.__json["info"]["project_urls"]["Homepage"] except: - home = ( - self.__json["info"]["project_url"] - or self.__json["info"]["home_page"] - or self.__json["info"]["package_url"] - ) + home = (self.__json["info"]["project_url"] + or self.__json["info"]["home_page"] + or self.__json["info"]["package_url"]) if home is None: logger.error("Cant find home page url") sys.exit(1) @@ -179,7 +173,11 @@ class PyPorter: rs = self.get_releases() for r in rs: if r["packagetype"] == "sdist": - return {"filename": r["filename"], "md5": r["md5_digest"], "url": r["url"]} + return { + "filename": r["filename"], + "md5": r["md5_digest"], + "url": r["url"] + } return None def get_releases(self): @@ -205,7 +203,8 @@ class PyPorter: if s_info: surl = s_info.get("url") if self.mirror: - surl = surl.replace("https://files.pythonhosted.org", self.mirror) + surl = surl.replace("https://files.pythonhosted.org", + self.mirror) return surl return "" @@ -282,12 +281,11 @@ class PyPorter: if br == "": continue # - # Do not output BuildRequires: + # Do not output BuildRequires: # just collect all build requires and using pip to install - # than can help to build all rpm withoud trap into + # than can help to build all rpm withoud trap into # build dependency nightmare # - # print(buildreq_tag_template.format(req=br)) name = str.lstrip(br).split(" ") req_list.append(name[0]) return req_list @@ -320,7 +318,7 @@ class PyPorter: fname = json_file_template.format(pkg_name=self.__pkg_name) json_file = os.path.join(spath, fname) - # if file exist, do nothing + # if file exist, do nothing if path.exists(json_file) and path.isfile(json_file): with open(json_file, 'r') as f: resp = json.load(f) @@ -387,7 +385,7 @@ def prepare_rpm_build_env(root): prepare environment for rpmbuild """ if not os.path.exists(root): - print("Root path %s does not exist\n" & root) + print(f"Root path {root} does not exist\n") return "" buildroot = os.path.join(root, "rpmbuild") @@ -406,7 +404,6 @@ def try_pip_install_package(pkg): """ install packages listed in build requires """ - # try pip installation pip_name = pkg.split("-") if len(pip_name) == 2: ret = subprocess.call(["pip3", "install", "--user", pip_name[1]]) @@ -414,7 +411,9 @@ def try_pip_install_package(pkg): ret = subprocess.call(["pip3", "install", "--user", pip_name[0]]) if ret != 0: - logger.error("%s can not be installed correctly, Fix it later, go ahead to do building..." % pip_name) + logger.error( + f"{pip_name} can not be installed correctly, Fix it later, go ahead to do building..." + ) # # TODO: try to build anyway, fix it later @@ -432,11 +431,9 @@ def package_installed(pkg): def dependencies_ready(req_list): - """ + """ TODO: do not need to do dependency check here, do it in pyporter_run """ - # if (try_pip_install_package(req) == False): - # return req return "" @@ -459,7 +456,8 @@ def build_install_rpm(porter, rootpath): else: arch = platform.machine() - pkgname = os.path.join(rootpath, "rpmbuild", "RPMS", arch, porter.get_pkg_name() + "*") + pkgname = os.path.join(rootpath, "rpmbuild", "RPMS", arch, + porter.get_pkg_name() + "*") ret = subprocess.call(["rpm", "-ivh", pkgname]) if ret != 0: return "Install failed\n" @@ -475,12 +473,14 @@ def build_rpm(porter, rootpath): if buildroot == "": return False - specfile = os.path.join(buildroot, "SPECS", porter.get_spec_name() + ".spec") + specfile = os.path.join(buildroot, "SPECS", + porter.get_spec_name() + ".spec") req_list = build_spec(porter, specfile) ret = dependencies_ready(req_list) if ret != "": - logger.error("%s can not be installed automatically, Please handle it" % ret) + logger.error( + f"{ret} can not be installed automatically, Please handle it") return ret download_source(porter, os.path.join(buildroot, "SOURCES")) @@ -516,25 +516,27 @@ def build_spec(porter, output): print(porter.get_description()) print("") - print("%package -n {name}".format(name=porter.get_pkg_name())) + print(f"%package -n {porter.get_pkg_name()}") print(summary_tag_template.format(pkg_sum=porter.get_summary())) - print("Provides:\t" + porter.get_spec_name()) + print(f"Provides:\t{porter.get_spec_name()}") porter.prepare_build_requires() build_req_list = porter.get_build_requires() - print("%description -n " + porter.get_pkg_name()) + print(f"%description -n {porter.get_pkg_name()}") print(porter.get_description()) print("") print("%package help") - print("Summary:\tDevelopment documents and examples for {name}".format(name=porter.get_module_name())) - print("Provides:\t{name}-doc".format(name=porter.get_pkg_name())) + print( + f"Summary:\tDevelopment documents and examples for {porter.get_module_name()}" + ) + print(f"Provides:\t{porter.get_pkg_name()}-doc") print("%description help") print(porter.get_description()) print("") print("%prep") - print("%autosetup -n {name}-{ver}".format(name=porter.get_archive_name(), ver=porter.get_version())) + print(f"%autosetup -n {porter.get_archive_name()}-{porter.get_version()}") print("") print("%build") porter.prepare_pkg_build() @@ -544,33 +546,45 @@ def build_spec(porter, output): print("install -d -m755 %{buildroot}/%{_pkgdocdir}") print("if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi") print("if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi") - print("if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi") - print("if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi") + print( + "if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi" + ) + print( + "if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi" + ) print("pushd %{buildroot}") print("if [ -d usr/lib ]; then") # we double quota the path for the case: # whitespace in filename or dirname # see: https://rpm-list.redhat.narkive.com/7WUOZXa6/basic-question-space-in-file-name - print("\tfind usr/lib -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") + print( + "\tfind usr/lib -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") print("fi") print("if [ -d usr/lib64 ]; then") - print("\tfind usr/lib64 -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") + print( + "\tfind usr/lib64 -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst" + ) print("fi") print("if [ -d usr/bin ]; then") - print("\tfind usr/bin -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") + print( + "\tfind usr/bin -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") print("fi") print("if [ -d usr/sbin ]; then") - print("\tfind usr/sbin -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst") + print( + "\tfind usr/sbin -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst" + ) print("fi") print("touch doclist.lst") print("if [ -d usr/share/man ]; then") - print("\tfind usr/share/man -type f -printf \"\\\"/%h/%f.gz\\\"\\n\" >> doclist.lst") + print( + "\tfind usr/share/man -type f -printf \"\\\"/%h/%f.gz\\\"\\n\" >> doclist.lst" + ) print("fi") print("popd") print("mv %{buildroot}/filelist.lst .") print("mv %{buildroot}/doclist.lst .") print("") - print("%files -n {name} -f filelist.lst".format(name=porter.get_pkg_name())) + print(f"%files -n {porter.get_pkg_name()} -f filelist.lst") porter.prepare_pkg_files() @@ -580,7 +594,9 @@ def build_spec(porter, output): print("") print("%changelog") date_str = datetime.date.today().strftime("%a %b %d %Y") - print("* {today} Python_Bot - {version}-1".format(today=date_str, version=porter.get_version())) + print( + f"* {date_str} Python_Bot - {porter.get_version()}-1" + ) print("- Package Spec generated") sys.stdout = tmp @@ -591,23 +607,76 @@ def build_spec(porter, output): def do_args(dft_root_path): parser = argparse.ArgumentParser() - parser.add_argument("-v", "--pkgversion", help="Specify the pypi package version", type=str, default="") - parser.add_argument("--retry", help="Specify the retry times when fetching metadata(default=3)", - type=int, default=3) - parser.add_argument("--delay", help="Specify the delay time between two retries(default 2s)", type=int, default=2) - parser.add_argument("-m", "--mirror", help="Specify the pypi mirror, should be a url which contain pypi packages", - type=str, default="") - parser.add_argument("-s", "--spec", help="Create spec file", action="store_true") - parser.add_argument("-R", "--requires", help="Get required python modules", action="store_true") - parser.add_argument("-b", "--build", help="Build rpm package", action="store_true") - parser.add_argument("-B", "--buildinstall", help="Build&Install rpm package", action="store_true") - parser.add_argument("-r", "--rootpath", help="Build rpm package in root path", type=str, default=dft_root_path) - parser.add_argument("-d", "--download", help="Download source file indicated path", action="store_true") - parser.add_argument("-p", "--path", help="indicated path to store files", type=str, default=os.getcwd()) - parser.add_argument("-j", "--json", help="Get Package JSON info", action="store_true") - parser.add_argument("-o", "--output", help="Output to file", type=str, default="") - parser.add_argument("-t", "--type", help="Build module type : python, perl...", type=str, default="python") - parser.add_argument("-a", "--arch", help="Build module with arch", action="store_true") + parser.add_argument("-v", + "--pkgversion", + help="Specify the pypi package version", + type=str, + default="") + parser.add_argument( + "--retry", + help="Specify the retry times when fetching metadata(default=3)", + type=int, + default=3) + parser.add_argument( + "--delay", + help="Specify the delay time between two retries(default 2s)", + type=int, + default=2) + parser.add_argument( + "-m", + "--mirror", + help="Specify pypi mirror, should be a url which contain" + " pypi packages", + type=str, + default="") + parser.add_argument("-s", + "--spec", + help="Create spec file", + action="store_true") + parser.add_argument("-R", + "--requires", + help="Get required python modules", + action="store_true") + parser.add_argument("-b", + "--build", + help="Build rpm package", + action="store_true") + parser.add_argument("-B", + "--buildinstall", + help="Build&Install rpm package", + action="store_true") + parser.add_argument("-r", + "--rootpath", + help="Build rpm package in root path", + type=str, + default=dft_root_path) + parser.add_argument("-d", + "--download", + help="Download source file indicated path", + action="store_true") + parser.add_argument("-p", + "--path", + help="indicated path to store files", + type=str, + default=os.getcwd()) + parser.add_argument("-j", + "--json", + help="Get Package JSON info", + action="store_true") + parser.add_argument("-o", + "--output", + help="Output to file", + type=str, + default="") + parser.add_argument("-t", + "--type", + help="Build module type : python, perl...", + type=str, + default="python") + parser.add_argument("-a", + "--arch", + help="Build module with arch", + action="store_true") parser.add_argument("pkg", type=str, help="The Python Module Name") return parser @@ -617,7 +686,7 @@ def porter_creator(args): if args.type == "python": return PyPorter(args) - logger.error("Type %s is not supported now" % args.type) + logger.error(f"Type {args.type} is not supported now") sys.exit(1) @@ -637,7 +706,7 @@ def main(): elif args.build: ret = build_rpm(porter, args.rootpath) if ret != "": - logger.error("build failed : BuildRequire : %s" % ret) + logger.error(f"build failed : BuildRequire : {ret}") sys.exit(1) elif args.buildinstall: ret = build_install_rpm(porter, args.rootpath) @@ -649,5 +718,6 @@ def main(): elif args.json: porter.store_json(args.path) + if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index d6d07f954c7609ba109997d0ec3d6d898e513958..6005bcbd096dbb82a7211b5d093ff368c7ce346a 100644 --- a/setup.py +++ b/setup.py @@ -36,13 +36,7 @@ setuptools.setup( 'Topic :: Utilities', ], long_description=open('README.md').read(), -# scripts=['pyporter'], - entry_points={ - 'console_scripts': [ - 'pyporter = pyporter.pyporter:main', - ] - }, - install_requires=[ - "retry2" - ] -) + entry_points={'console_scripts': [ + 'pyporter = pyporter.pyporter:main', + ]}, + install_requires=["retry2"]) diff --git a/tests/TestLicense.json b/tests/TestLicense.json index c1d74cdb1bdf59ce8a4d4be52dc755de695439d0..a958454db0998b9428ffe81786e3b01136067158 100644 --- a/tests/TestLicense.json +++ b/tests/TestLicense.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestNoHomepageNone.json b/tests/TestNoHomepageNone.json index c1d74cdb1bdf59ce8a4d4be52dc755de695439d0..a958454db0998b9428ffe81786e3b01136067158 100644 --- a/tests/TestNoHomepageNone.json +++ b/tests/TestNoHomepageNone.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestNoHomepageUseHomePage.json b/tests/TestNoHomepageUseHomePage.json index 999ef16622275e44fe32d96c0f9aa7581518c86e..50895e16c93d7c4a9374bfeebb092e1453bc4052 100644 --- a/tests/TestNoHomepageUseHomePage.json +++ b/tests/TestNoHomepageUseHomePage.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestNoHomepageUsePackageUrl.json b/tests/TestNoHomepageUsePackageUrl.json index 016660a297c41ae49d0d411716f7f6823dc61794..0f73a5ae26a74fa6f7fdbdbae1281496a2afb155 100644 --- a/tests/TestNoHomepageUsePackageUrl.json +++ b/tests/TestNoHomepageUsePackageUrl.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestNoHomepageUseProjectUrl.json b/tests/TestNoHomepageUseProjectUrl.json index 7256ee6d4d4560f8c5a40966555610bcff0276ff..5cff3e0e9f51919794b78a6e083b2afa38fc8547 100644 --- a/tests/TestNoHomepageUseProjectUrl.json +++ b/tests/TestNoHomepageUseProjectUrl.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestNoOSIApproved.json b/tests/TestNoOSIApproved.json index e1d59539d70dc2ecce403d7bbd1217969152e16c..4a88fa0468ff0af4fd9bd8ae40b516b5f556ca1a 100644 --- a/tests/TestNoOSIApproved.json +++ b/tests/TestNoOSIApproved.json @@ -62,4 +62,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/TestOSIApproved.json b/tests/TestOSIApproved.json index 057e0f1a46bf054fa8563b8061a02f581f51bbc0..be379707a002da6e5c6a04768d9e53dbd69b8522 100644 --- a/tests/TestOSIApproved.json +++ b/tests/TestOSIApproved.json @@ -63,4 +63,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tests/test_get_archive_name.py b/tests/test_get_archive_name.py index ddb626fd98bf3efd943a9de63878559d21960291..cdea11dd8dd126086d37fa8391c4ea0f9b76eba5 100644 --- a/tests/test_get_archive_name.py +++ b/tests/test_get_archive_name.py @@ -1,5 +1,6 @@ import unittest from unittest.mock import MagicMock + from pyporter.pyporter import porter_creator VALID_PKG = ["pure-eval", "oic", "XStatic-Patternfly"] @@ -7,6 +8,7 @@ VALID_ARCHIVE_NAME = ["pure_eval", "oic", "XStatic-Patternfly"] class TestValidArchive(unittest.TestCase): + def test(self): args = MagicMock() args.configure_mock(type="python") diff --git a/tests/test_get_home.py b/tests/test_get_home.py index 410024e2aaa59b7f1cbbb8027e9b69fd2e67c0ab..d767a912e92da23b85980eb677a5f79b39b54f27 100644 --- a/tests/test_get_home.py +++ b/tests/test_get_home.py @@ -1,26 +1,29 @@ -import unittest import os -from unittest.mock import patch, MagicMock +import unittest +from unittest.mock import MagicMock, patch + from pyporter.pyporter import porter_creator +args = MagicMock() +args.configure_mock(type="python") +args.pkg = "oic" +args.pkgversion = "1.5.0" +args.arch = None +args.mirror = "" + + class TestNoHomepageNone(unittest.TestCase): + def setUp(self): - self.f = open(os.path.join('tests', __class__.__name__+'.json')) + self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() - + @patch('urllib.request.urlopen') def test_no_homepage_in_project_urls(self, m): cm = MagicMock() cm.read.return_value = self.data cm.__enter__.return_value = cm m.return_value = cm - - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "oic" - args.pkgversion = "1.5.0" - args.arch = None - args.mirror = "" p = porter_creator(args) self.assertRaises(SystemExit, p.get_home) @@ -30,10 +33,11 @@ class TestNoHomepageNone(unittest.TestCase): class TestNoHomepageUseProjectUrl(unittest.TestCase): + def setUp(self): - self.f = open(os.path.join('tests', __class__.__name__+'.json')) + self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() - + @patch('urllib.request.urlopen') def test_no_homepage_in_project_urls(self, m): cm = MagicMock() @@ -41,13 +45,6 @@ class TestNoHomepageUseProjectUrl(unittest.TestCase): cm.__enter__.return_value = cm m.return_value = cm - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "oic" - args.pkgversion = "1.5.0" - args.arch = None - args.mirror = "" - p = porter_creator(args) self.assertEqual("test_project_url", p.get_home()) @@ -56,10 +53,11 @@ class TestNoHomepageUseProjectUrl(unittest.TestCase): class TestNoHomepageUsePackageUrl(unittest.TestCase): + def setUp(self): - self.f = open(os.path.join('tests', __class__.__name__+'.json')) + self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() - + @patch('urllib.request.urlopen') def test_no_homepage_in_project_urls(self, m): cm = MagicMock() @@ -67,13 +65,6 @@ class TestNoHomepageUsePackageUrl(unittest.TestCase): cm.__enter__.return_value = cm m.return_value = cm - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "oic" - args.pkgversion = "1.5.0" - args.arch = None - args.mirror = "" - p = porter_creator(args) self.assertEqual("test_package_url", p.get_home()) @@ -82,10 +73,11 @@ class TestNoHomepageUsePackageUrl(unittest.TestCase): class TestNoHomepageUseHomePage(unittest.TestCase): + def setUp(self): - self.f = open(os.path.join('tests', __class__.__name__+'.json')) + self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() - + @patch('urllib.request.urlopen') def test_no_homepage_in_project_urls(self, m): cm = MagicMock() @@ -93,18 +85,12 @@ class TestNoHomepageUseHomePage(unittest.TestCase): cm.__enter__.return_value = cm m.return_value = cm - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "oic" - args.pkgversion = "1.5.0" - args.arch = None - args.mirror = "" - p = porter_creator(args) self.assertEqual("test_home_page", p.get_home()) def tearDown(self): self.f.close() + if __name__ == '__main__': unittest.main() diff --git a/tests/test_get_license.py b/tests/test_get_license.py index 528e6515350e9c1ac3b1519c2894dad1167ce3f8..a7e45469edba4ca2684a8953ecf5859284d6c69e 100644 --- a/tests/test_get_license.py +++ b/tests/test_get_license.py @@ -1,6 +1,7 @@ -import unittest import os -from unittest.mock import patch, MagicMock +import unittest +from unittest.mock import MagicMock, patch + from pyporter.pyporter import porter_creator @@ -8,6 +9,7 @@ class TestNoOSIApproved(unittest.TestCase): """ case 1: json["info"]["license"] == "" and the License in json["info"]["classifiers"] is not OSI approved """ + def setUp(self): self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() @@ -27,7 +29,9 @@ class TestNoOSIApproved(unittest.TestCase): args.mirror = "" p = porter_creator(args) - self.assertEqual('CC0 1.0 Universal (CC0 1.0) Public Domain Dedication', p.get_license()) + self.assertEqual( + 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication', + p.get_license()) def tearDown(self): self.f.close() @@ -37,6 +41,7 @@ class TestOSIApproved(unittest.TestCase): """ case 2: json["info"]["license"] == "" and the License in json["info"]["classifiers"] is OSI approved """ + def setUp(self): self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() @@ -66,6 +71,7 @@ class TestLicense(unittest.TestCase): """ case 3: json["info"]["license"] != "" """ + def setUp(self): self.f = open(os.path.join('tests', __class__.__name__ + '.json')) self.data = self.f.read().encode() diff --git a/tests/test_get_source_url.py b/tests/test_get_source_url.py index 6228728319e1ca41b74bf4a86a97420870172596..743c8df9d10683ebe92d2a4621570a5d8a119ea7 100644 --- a/tests/test_get_source_url.py +++ b/tests/test_get_source_url.py @@ -1,5 +1,6 @@ import unittest from unittest.mock import MagicMock + from pyporter.pyporter import porter_creator SRC_URL = "https://files.pythonhosted.org/packages/36/62/7cda20a9bd8c52bf47c6f1cf7e"\ @@ -9,6 +10,7 @@ MIRROR_URL = "https://mirrors.aliyun.com/pypi/packages/36/62/7cda20a9bd8c52bf47c class TestValidSource(unittest.TestCase): + def test_no_mirror(self): args = MagicMock() args.configure_mock(type="python") diff --git a/tests/test_get_ver.py b/tests/test_get_ver.py index 033059b1ae89283ebe81c85986786b6b1b496422..e00c53c0494363d7ddc6c08d35f454a38ecef0a9 100644 --- a/tests/test_get_ver.py +++ b/tests/test_get_ver.py @@ -1,9 +1,11 @@ import unittest from unittest.mock import MagicMock + from pyporter.pyporter import porter_creator class TestGetByVer(unittest.TestCase): + def test_invalid_ver(self): args = MagicMock() args.configure_mock(type="python")