From 0a5f5dec41285cb251534655e9ae354b35182f6a Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Tue, 4 Jul 2023 13:35:03 +0000 Subject: [PATCH 01/18] add pre commit code format --- .pre-commit-config.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5f7fc8f --- /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.32.0 + hooks: + - id: yapf + name: Format code + additional_dependencies: [toml] -- Gitee From 4237b57bc4dd67b96cce3fe353d41929c533f82c Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Tue, 4 Jul 2023 14:41:11 +0000 Subject: [PATCH 02/18] add test --- tests/test_get_pyproject_toml.py | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/test_get_pyproject_toml.py diff --git a/tests/test_get_pyproject_toml.py b/tests/test_get_pyproject_toml.py new file mode 100644 index 0000000..3489bda --- /dev/null +++ b/tests/test_get_pyproject_toml.py @@ -0,0 +1,60 @@ +import os +import unittest +from unittest.mock import MagicMock, patch + +from pyporter.pyporter import porter_creator + + +class TestTomlGetByVer(unittest.TestCase): + + def test_invalid_ver(self): + args = MagicMock() + args.configure_mock(type="python") + args.pkg = "urllib3" + args.pkgversion = "0.0.0" + args.arch = None + args.mirror = "" + + self.assertRaises(SystemExit, porter_creator, args) + + def test_valid_ver(self): + args = MagicMock() + args.configure_mock(type="python") + args.pkg = "urllib3" + args.pkgversion = "2.0.3" + args.arch = None + args.mirror = "" + + p = porter_creator(args) + self.assertEqual(p.get_version(), "2.0.3") + + +class TestNoHomepageUseProjectUrl(unittest.TestCase): + + def setUp(self): + 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.assertEqual("test_project_url", p.get_home()) + + def tearDown(self): + self.f.close() + + +if __name__ == '__main__': + unittest.main() -- Gitee From 5c695a2733c85d7d5267fad2ec6aa65c54a5bffd Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Tue, 4 Jul 2023 14:42:24 +0000 Subject: [PATCH 03/18] format codes --- .gitignore | 2 +- .pre-commit-config.yaml | 2 +- LICENSE | 44 ++--- pyporter/pyporter.py | 212 +++++++++++++++++-------- setup.py | 15 +- tests/TestLicense.json | 2 +- tests/TestNoHomepageNone.json | 2 +- tests/TestNoHomepageUseHomePage.json | 2 +- tests/TestNoHomepageUsePackageUrl.json | 2 +- tests/TestNoHomepageUseProjectUrl.json | 2 +- tests/TestNoOSIApproved.json | 2 +- tests/TestOSIApproved.json | 2 +- tests/test_get_archive_name.py | 2 + tests/test_get_home.py | 29 ++-- tests/test_get_license.py | 12 +- tests/test_get_source_url.py | 2 + tests/test_get_ver.py | 2 + 17 files changed, 215 insertions(+), 121 deletions(-) diff --git a/.gitignore b/.gitignore index f097971..4d48f6b 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 index 5f7fc8f..bd735cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: hooks: - id: isort name: Sort imports - + - repo: https://github.com/google/yapf rev: v0.32.0 hooks: diff --git a/LICENSE b/LICENSE index ee58399..5729580 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/pyporter/pyporter.py b/pyporter/pyporter.py index cc3e5bc..c81cc5b 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -17,29 +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 socket +import subprocess +import sys +import urllib +import urllib.request +from os import path from pathlib import Path -import hashlib +from pprint import pprint + 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) @@ -56,7 +58,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 +76,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 +92,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 +125,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 +147,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 +178,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 +208,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,9 +286,9 @@ 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)) @@ -320,7 +324,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) @@ -414,7 +418,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( + "%s can not be installed correctly, Fix it later, go ahead to do building..." + % pip_name) # # TODO: try to build anyway, fix it later @@ -432,7 +438,7 @@ 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): @@ -459,7 +465,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 +482,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( + "%s can not be installed automatically, Please handle it" % ret) return ret download_source(porter, os.path.join(buildroot, "SOURCES")) @@ -528,13 +537,15 @@ def build_spec(porter, output): print(porter.get_description()) print("") print("%package help") - print("Summary:\tDevelopment documents and examples for {name}".format(name=porter.get_module_name())) + 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("%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("%autosetup -n {name}-{ver}".format(name=porter.get_archive_name(), + ver=porter.get_version())) print("") print("%build") porter.prepare_pkg_build() @@ -544,33 +555,46 @@ 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( + "%files -n {name} -f filelist.lst".format(name=porter.get_pkg_name())) porter.prepare_pkg_files() @@ -580,7 +604,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( + "* {today} Python_Bot - {version}-1".format( + today=date_str, version=porter.get_version())) print("- Package Spec generated") sys.stdout = tmp @@ -591,23 +617,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 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("pkg", type=str, help="The Python Module Name") return parser @@ -649,5 +728,6 @@ def main(): elif args.json: porter.store_json(args.path) + if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index d6d07f9..4667fd6 100644 --- a/setup.py +++ b/setup.py @@ -36,13 +36,8 @@ setuptools.setup( 'Topic :: Utilities', ], long_description=open('README.md').read(), -# scripts=['pyporter'], - entry_points={ - 'console_scripts': [ - 'pyporter = pyporter.pyporter:main', - ] - }, - install_requires=[ - "retry2" - ] -) + # scripts=['pyporter'], + entry_points={'console_scripts': [ + 'pyporter = pyporter.pyporter:main', + ]}, + install_requires=["retry2"]) diff --git a/tests/TestLicense.json b/tests/TestLicense.json index c1d74cd..a958454 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 c1d74cd..a958454 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 999ef16..50895e1 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 016660a..0f73a5a 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 7256ee6..5cff3e0 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 e1d5953..4a88fa0 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 057e0f1..be37970 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 ddb626f..cdea11d 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 410024e..fe2cec6 100644 --- a/tests/test_get_home.py +++ b/tests/test_get_home.py @@ -1,20 +1,23 @@ -import unittest import os -from unittest.mock import patch, MagicMock +import unittest +from unittest.mock import MagicMock, patch + from pyporter.pyporter import porter_creator + 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" @@ -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() @@ -56,10 +60,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() @@ -82,10 +87,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() @@ -106,5 +112,6 @@ class TestNoHomepageUseHomePage(unittest.TestCase): 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 528e651..a7e4546 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 6228728..743c8df 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 033059b..e00c53c 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") -- Gitee From e80d4944c5baaaf2935f4d1a9ddd87c50637bd7f Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Wed, 5 Jul 2023 16:10:08 +0000 Subject: [PATCH 04/18] add get requires test --- .gitignore | 1 + README.md | 5 ++ pyporter/__init__.py | 1 + pyporter/pyporter.py | 44 +------------ pyporter/utils.py | 30 +++++++++ tests/TestPyprojectToml.json | 108 +++++++++++++++++++++++++++++++ tests/test_get_pyproject_toml.py | 42 ++++-------- 7 files changed, 161 insertions(+), 70 deletions(-) create mode 100644 pyporter/utils.py create mode 100644 tests/TestPyprojectToml.json diff --git a/.gitignore b/.gitignore index 4d48f6b..54aa8c4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ pyporter.egg-info .pytest_cache/ .mypy_cache/ *.spec +rpmbuild/ diff --git a/README.md b/README.md index ce96646..f6e64d1 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,11 @@ Install below software before using this tool 4. python3-cffi 5. rpmbuild +Install commmands +``` +dnf in 'python3dist(botocore)' +dnf in 'python3.9dist(s3transfer)' +``` #### Installation diff --git a/pyporter/__init__.py b/pyporter/__init__.py index e69de29..16281fe 100644 --- a/pyporter/__init__.py +++ b/pyporter/__init__.py @@ -0,0 +1 @@ +from .utils import * diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 6de600c..cf8d6ca 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -24,7 +24,6 @@ import json import logging import os import platform -import re import subprocess import sys import urllib @@ -34,6 +33,8 @@ from pathlib import Path from retry import retry_call +from pyporter.utils import refine_requires, transform_module_name + logger = logging.getLogger() handler = logging.StreamHandler(sys.stdout) @@ -327,35 +328,6 @@ class PyPorter: json.dump(self.__json, f) -def transform_module_name(n): - """ - return module name with version restriction. - Any string with '.' or '/' is considered file, and will be ignored - Modules start with python- will be changed to python3- for consistency. - """ - ns = re.split("[()]", n) - ver_constrain = [] - ns[0] = ns[0].strip() - if ns[0].startswith("python-"): - ns[0] = ns[0].replace("python-", "python3-") - else: - ns[0] = "python3-" + ns[0] - if ns[0].find("/") != -1 or ns[0].find(".") != -1: - return "" - return ns[0] - - -def refine_requires(req): - """ - return only requires without ';' (thus no extra) - """ - ra = req.split(";", 1) - # - # Do not add requires which has ;, which is often has very complicated precondition - # TODO: need more parsing of the denpency after ; - return transform_module_name(ra[0]) - - def download_source(porter, tgtpath): """ download source file from url, and save it to target path @@ -430,13 +402,6 @@ def package_installed(pkg): return False -def dependencies_ready(req_list): - """ - TODO: do not need to do dependency check here, do it in pyporter_run - """ - return "" - - def build_package(specfile): """ build rpm package with rpmbuild @@ -477,11 +442,6 @@ def build_rpm(porter, rootpath): porter.get_spec_name() + ".spec") req_list = build_spec(porter, specfile) - ret = dependencies_ready(req_list) - if ret != "": - logger.error( - f"{ret} can not be installed automatically, Please handle it") - return ret download_source(porter, os.path.join(buildroot, "SOURCES")) diff --git a/pyporter/utils.py b/pyporter/utils.py new file mode 100644 index 0000000..5804f13 --- /dev/null +++ b/pyporter/utils.py @@ -0,0 +1,30 @@ +import re + + +def transform_module_name(s: str): + """ + return module name with version restriction. + Any string with '.' or '/' is considered file, and will be ignored + Modules start with python- will be changed to python3- for consistency. + """ + ns = re.split("[()]", s) + ver_constrain = [] + ns[0] = ns[0].strip() + if ns[0].startswith("python-"): + ns[0] = ns[0].replace("python-", "python3-") + else: + ns[0] = "python3-" + ns[0] + if ns[0].find("/") != -1 or ns[0].find(".") != -1: + return "" + return ns[0] + + +def refine_requires(req): + """ + return only requires without ';' (thus no extra) + """ + ra = req.split(";", 1) + # + # Do not add requires which has ;, which is often has very complicated precondition + # TODO: need more parsing of the denpency after ; + return transform_module_name(ra[0]) diff --git a/tests/TestPyprojectToml.json b/tests/TestPyprojectToml.json new file mode 100644 index 0000000..eea52bf --- /dev/null +++ b/tests/TestPyprojectToml.json @@ -0,0 +1,108 @@ +{ + "info": { + "author": "", + "author_email": "Andrey Petrov ", + "bugtrack_url": null, + "classifiers": [ + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Software Development :: Libraries" + ], + "description": "

\n\n![urllib3](https://github.com/urllib3/urllib3/raw/main/docs/_static/banner_github.svg)\n\n

\n\n

\n \"PyPI\n \"Python\n \"Join\n \"Coverage\n \"Build\n \"Documentation
\n \"OpenSSF\n \"SLSA\n \"CII\n

\n\nurllib3 is a powerful, *user-friendly* HTTP client for Python. Much of the\nPython ecosystem already uses urllib3 and you should too.\nurllib3 brings many critical features that are missing from the Python\nstandard libraries:\n\n- Thread safety.\n- Connection pooling.\n- Client-side SSL/TLS verification.\n- File uploads with multipart encoding.\n- Helpers for retrying requests and dealing with HTTP redirects.\n- Support for gzip, deflate, brotli, and zstd encoding.\n- Proxy support for HTTP and SOCKS.\n- 100% test coverage.\n\nurllib3 is powerful and easy to use:\n\n```python3\n>>> import urllib3\n>>> resp = urllib3.request(\"GET\", \"http://httpbin.org/robots.txt\")\n>>> resp.status\n200\n>>> resp.data\nb\"User-agent: *\\nDisallow: /deny\\n\"\n```\n\n## Installing\n\nurllib3 can be installed with [pip](https://pip.pypa.io):\n\n```bash\n$ python -m pip install urllib3\n```\n\nAlternatively, you can grab the latest source code from [GitHub](https://github.com/urllib3/urllib3):\n\n```bash\n$ git clone https://github.com/urllib3/urllib3.git\n$ cd urllib3\n$ pip install .\n```\n\n\n## Documentation\n\nurllib3 has usage and reference documentation at [urllib3.readthedocs.io](https://urllib3.readthedocs.io).\n\n\n## Community\n\nurllib3 has a [community Discord channel](https://discord.gg/urllib3) for asking questions and\ncollaborating with other contributors. Drop by and say hello 👋\n\n\n## Contributing\n\nurllib3 happily accepts contributions. Please see our\n[contributing documentation](https://urllib3.readthedocs.io/en/latest/contributing.html)\nfor some tips on getting started.\n\n\n## Security Disclosures\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure with maintainers.\n\n\n## Maintainers\n\n- [@sethmlarson](https://github.com/sethmlarson) (Seth M. Larson)\n- [@pquentin](https://github.com/pquentin) (Quentin Pradet)\n- [@theacodes](https://github.com/theacodes) (Thea Flowers)\n- [@haikuginger](https://github.com/haikuginger) (Jess Shapiro)\n- [@lukasa](https://github.com/lukasa) (Cory Benfield)\n- [@sigmavirus24](https://github.com/sigmavirus24) (Ian Stapleton Cordasco)\n- [@shazow](https://github.com/shazow) (Andrey Petrov)\n\n👋\n\n\n## Sponsorship\n\nIf your company benefits from this library, please consider [sponsoring its\ndevelopment](https://urllib3.readthedocs.io/en/latest/sponsors.html).\n\n\n## For Enterprise\n\nProfessional support for urllib3 is available as part of the [Tidelift\nSubscription][1]. Tidelift gives software development teams a single source for\npurchasing and maintaining their software, with professional grade assurances\nfrom the experts who know it best, while seamlessly integrating with existing\ntools.\n\n[1]: https://tidelift.com/subscription/pkg/pypi-urllib3?utm_source=pypi-urllib3&utm_medium=referral&utm_campaign=readme\n", + "description_content_type": "text/markdown", + "docs_url": null, + "download_url": "", + "downloads": { + "last_day": -1, + "last_month": -1, + "last_week": -1 + }, + "home_page": "", + "keywords": "filepost,http,httplib,https,pooling,ssl,threadsafe,urllib", + "license": "", + "maintainer": "", + "maintainer_email": "Seth Michael Larson , Quentin Pradet ", + "name": "urllib3", + "package_url": "https://pypi.org/project/urllib3/", + "platform": null, + "project_url": "https://pypi.org/project/urllib3/", + "project_urls": { + "Changelog": "https://github.com/urllib3/urllib3/blob/main/CHANGES.rst", + "Code": "https://github.com/urllib3/urllib3", + "Documentation": "https://urllib3.readthedocs.io", + "Issue tracker": "https://github.com/urllib3/urllib3/issues" + }, + "release_url": "https://pypi.org/project/urllib3/2.0.3/", + "requires_dist": [ + "brotli>=1.0.9; platform_python_implementation == 'CPython' and extra == 'brotli'", + "certifi; extra == 'secure'", + "urllib3-secure-extra; extra == 'secure'", + "pysocks!=1.5.7,<2.0,>=1.5.6; extra == 'socks'" + ], + "requires_python": ">=3.7", + "summary": "HTTP library with thread-safe connection pooling, file post, and more.", + "version": "2.0.3", + "yanked": false, + "yanked_reason": null + }, + "last_serial": 18406816, + "urls": [ + { + "comment_text": "", + "digests": { + "blake2b_256": "8a03ad9306a50d05c166e3456fe810f33cee2b8b2a7a6818ec5d4908c4ec6b36", + "md5": "8a9ecd2fb1059fdc16a1c36a1139b546", + "sha256": "48e7fafa40319d358848e1bc6809b208340fafe2096f1725d05d67443d0483d1" + }, + "downloads": -1, + "filename": "urllib3-2.0.3-py3-none-any.whl", + "has_sig": false, + "md5_digest": "8a9ecd2fb1059fdc16a1c36a1139b546", + "packagetype": "bdist_wheel", + "python_version": "py3", + "requires_python": ">=3.7", + "size": 123613, + "upload_time": "2023-06-07T10:59:09", + "upload_time_iso_8601": "2023-06-07T10:59:09.651459Z", + "url": "https://files.pythonhosted.org/packages/8a/03/ad9306a50d05c166e3456fe810f33cee2b8b2a7a6818ec5d4908c4ec6b36/urllib3-2.0.3-py3-none-any.whl", + "yanked": false, + "yanked_reason": null + }, + { + "comment_text": "", + "digests": { + "blake2b_256": "d6af3b4cfedd46b3addab52e84a71ab26518272c23c77116de3c61ead54af903", + "md5": "39c1af575eac4938c33e9bdf4549c1dd", + "sha256": "bee28b5e56addb8226c96f7f13ac28cb4c301dd5ea8a6ca179c0b9835e032825" + }, + "downloads": -1, + "filename": "urllib3-2.0.3.tar.gz", + "has_sig": false, + "md5_digest": "39c1af575eac4938c33e9bdf4549c1dd", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=3.7", + "size": 280489, + "upload_time": "2023-06-07T10:59:13", + "upload_time_iso_8601": "2023-06-07T10:59:13.325611Z", + "url": "https://files.pythonhosted.org/packages/d6/af/3b4cfedd46b3addab52e84a71ab26518272c23c77116de3c61ead54af903/urllib3-2.0.3.tar.gz", + "yanked": false, + "yanked_reason": null + } + ], + "vulnerabilities": [] +} diff --git a/tests/test_get_pyproject_toml.py b/tests/test_get_pyproject_toml.py index 3489bda..8739455 100644 --- a/tests/test_get_pyproject_toml.py +++ b/tests/test_get_pyproject_toml.py @@ -4,39 +4,18 @@ from unittest.mock import MagicMock, patch from pyporter.pyporter import porter_creator +SRC_URL = "https://files.pythonhosted.org/packages/d6/af/"\ + "3b4cfedd46b3addab52e84a71ab26518272c23c77116de3c61ead54af903/urllib3-2.0.3.tar.gz" # noqa -class TestTomlGetByVer(unittest.TestCase): - def test_invalid_ver(self): - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "urllib3" - args.pkgversion = "0.0.0" - args.arch = None - args.mirror = "" - - self.assertRaises(SystemExit, porter_creator, args) - - def test_valid_ver(self): - args = MagicMock() - args.configure_mock(type="python") - args.pkg = "urllib3" - args.pkgversion = "2.0.3" - args.arch = None - args.mirror = "" - - p = porter_creator(args) - self.assertEqual(p.get_version(), "2.0.3") - - -class TestNoHomepageUseProjectUrl(unittest.TestCase): +class TestPyprojectToml(unittest.TestCase): def setUp(self): 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): + def test_pyprojecttoml(self, m): cm = MagicMock() cm.read.return_value = self.data cm.__enter__.return_value = cm @@ -44,13 +23,20 @@ class TestNoHomepageUseProjectUrl(unittest.TestCase): args = MagicMock() args.configure_mock(type="python") - args.pkg = "oic" - args.pkgversion = "1.5.0" + args.pkg = "urllib3" + args.pkgversion = "2.0.3" args.arch = None args.mirror = "" p = porter_creator(args) - self.assertEqual("test_project_url", p.get_home()) + self.assertEqual("https://pypi.org/project/urllib3/", p.get_home()) + self.assertEqual(p.get_version(), "2.0.3") + self.assertEqual(p.get_source_url(), SRC_URL) + self.assertEqual(p.get_license(), "MIT License") + self.assertEqual(p.get_requires(), [ + "brotli>=1.0.9", "certifi", "urllib3-secure-extra", + "pysocks!=1.5.7,<2.0,>=1.5.6" + ]) def tearDown(self): self.f.close() -- Gitee From 2691fe723ec2ca7abce77861f6ec054de6756b0b Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Wed, 5 Jul 2023 18:49:20 +0000 Subject: [PATCH 05/18] update --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index f6e64d1..ce96646 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,6 @@ Install below software before using this tool 4. python3-cffi 5. rpmbuild -Install commmands -``` -dnf in 'python3dist(botocore)' -dnf in 'python3.9dist(s3transfer)' -``` #### Installation -- Gitee From f01917ec4e4f69444980bb0ce8cf89d6fa2d829d Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Thu, 6 Jul 2023 08:37:33 +0000 Subject: [PATCH 06/18] update --- tests/TestPyprojectToml.json | 2 +- tests/test_get_pyproject_toml.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestPyprojectToml.json b/tests/TestPyprojectToml.json index eea52bf..8122cba 100644 --- a/tests/TestPyprojectToml.json +++ b/tests/TestPyprojectToml.json @@ -51,7 +51,7 @@ "brotli>=1.0.9; platform_python_implementation == 'CPython' and extra == 'brotli'", "certifi; extra == 'secure'", "urllib3-secure-extra; extra == 'secure'", - "pysocks!=1.5.7,<2.0,>=1.5.6; extra == 'socks'" + "pysocks<2.0,>=1.5.6; extra == 'socks'" ], "requires_python": ">=3.7", "summary": "HTTP library with thread-safe connection pooling, file post, and more.", diff --git a/tests/test_get_pyproject_toml.py b/tests/test_get_pyproject_toml.py index 8739455..28669d8 100644 --- a/tests/test_get_pyproject_toml.py +++ b/tests/test_get_pyproject_toml.py @@ -35,7 +35,7 @@ class TestPyprojectToml(unittest.TestCase): self.assertEqual(p.get_license(), "MIT License") self.assertEqual(p.get_requires(), [ "brotli>=1.0.9", "certifi", "urllib3-secure-extra", - "pysocks!=1.5.7,<2.0,>=1.5.6" + "(pysocks >= 1.5.6 with pysocks < 2.0)" ]) def tearDown(self): -- Gitee From eeef5f9e3869bfff4026c1461b6e02852e5de70b Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Thu, 6 Jul 2023 09:03:23 +0000 Subject: [PATCH 07/18] update --- pyporter/pyporter.py | 7 +++++-- pyporter/utils.py | 17 ++++++++++++----- tests/test_transform_module_name.py | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 tests/test_transform_module_name.py diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index cf8d6ca..1ab2273 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -216,11 +216,13 @@ class PyPorter: rs = self.__json["info"]["requires_dist"] if rs is None: return + all_requires = [] for r in rs: idx = r.find(";") if idx != -1: r = r[:idx] - print("Requires:\t" + transform_module_name(r)) + all_requires.append(transform_module_name(r)) + return all_requires def __get_buildarch(self): """ @@ -470,7 +472,8 @@ def build_spec(porter, output): print(source_tag_template.format(pkg_source=porter.get_source_url())) porter.get_buildarch() print("") - porter.get_requires() + for r in porter.get_requires(): + print("Requires:\t" + r) print("") print("%description") print(porter.get_description()) diff --git a/pyporter/utils.py b/pyporter/utils.py index 5804f13..0fa9e1b 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -1,7 +1,7 @@ import re -def transform_module_name(s: str): +def transform_module_name(s: str) -> str: """ return module name with version restriction. Any string with '.' or '/' is considered file, and will be ignored @@ -14,12 +14,19 @@ def transform_module_name(s: str): ns[0] = ns[0].replace("python-", "python3-") else: ns[0] = "python3-" + ns[0] - if ns[0].find("/") != -1 or ns[0].find(".") != -1: - return "" - return ns[0] -def refine_requires(req): +# Process version constraints + if len(ns) > 1: + ver_constrain.append(ns[1]) + + if len(ver_constrain) > 0: + return f"({ns[0]} {ver_constrain[0]})" + else: + return ns[0] + + +def refine_requires(req: str) -> str: """ return only requires without ';' (thus no extra) """ diff --git a/tests/test_transform_module_name.py b/tests/test_transform_module_name.py new file mode 100644 index 0000000..ed8e2fe --- /dev/null +++ b/tests/test_transform_module_name.py @@ -0,0 +1,16 @@ +from pyporter.utils import transform_module_name + + +def test_transform_module_name(): + + input_str = "brotli>=1.0.9" + expected_output = "python3-brotli (>=1.0.9)" + assert transform_module_name(input_str) == expected_output + + input_str = "pysocks<2.0,>=1.5.6" + expected_output = " (python3-pysocks<2.0 with python3-pysocks >=1.5.6)" + assert transform_module_name(input_str) == expected_output + + +if __name__ == '__main__': + test_transform_module_name() -- Gitee From e71e552ea8b08573c30f66a0775827257a0cdc61 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Thu, 6 Jul 2023 13:11:49 +0000 Subject: [PATCH 08/18] pass test_transform_module_name test --- pyporter/utils.py | 54 +++++++++++++++++++---------- tests/test_transform_module_name.py | 4 +-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/pyporter/utils.py b/pyporter/utils.py index 0fa9e1b..628e230 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -1,29 +1,45 @@ import re +# def transform_module_name(s: str) -> str: +# """ +# return module name with version restriction. +# Any string with '.' or '/' is considered file, and will be ignored +# Modules start with python- will be changed to python3- for consistency. +# """ +# ns = re.split("[()]", s) +# ver_constrain = [] +# ns[0] = ns[0].strip() +# if ns[0].startswith("python-"): +# ns[0] = ns[0].replace("python-", "python3-") +# else: +# ns[0] = "python3-" + ns[0] -def transform_module_name(s: str) -> str: - """ - return module name with version restriction. - Any string with '.' or '/' is considered file, and will be ignored - Modules start with python- will be changed to python3- for consistency. - """ - ns = re.split("[()]", s) - ver_constrain = [] - ns[0] = ns[0].strip() - if ns[0].startswith("python-"): - ns[0] = ns[0].replace("python-", "python3-") - else: - ns[0] = "python3-" + ns[0] +# # Process version constraints +# if len(ns) > 1: +# ver_constrain.append(ns[1]) +# if len(ver_constrain) > 0: +# return f"({ns[0]} {ver_constrain[0]})" +# else: +# return ns[0] -# Process version constraints - if len(ns) > 1: - ver_constrain.append(ns[1]) - if len(ver_constrain) > 0: - return f"({ns[0]} {ver_constrain[0]})" +def transform_module_name(input_str): + # Extracting the module name from the input string + module_name = re.match(r"([a-zA-Z0-9_-]+)", input_str).group(1) + version_names = input_str[len(module_name):] + # Extracting the version constraint from the input string + version_constraint = version_names.split(",") + package_name = "python3-" + module_name + if len(version_constraint) > 1: + constraints_string = " with ".join([ + f"{package_name}{constraint}" for constraint in version_constraint + ]) + result_string = f"({constraints_string})" else: - return ns[0] + result_string = f"({package_name}{version_constraint[0]})" + + return result_string def refine_requires(req: str) -> str: diff --git a/tests/test_transform_module_name.py b/tests/test_transform_module_name.py index ed8e2fe..0860e9b 100644 --- a/tests/test_transform_module_name.py +++ b/tests/test_transform_module_name.py @@ -4,11 +4,11 @@ from pyporter.utils import transform_module_name def test_transform_module_name(): input_str = "brotli>=1.0.9" - expected_output = "python3-brotli (>=1.0.9)" + expected_output = "(python3-brotli>=1.0.9)" assert transform_module_name(input_str) == expected_output input_str = "pysocks<2.0,>=1.5.6" - expected_output = " (python3-pysocks<2.0 with python3-pysocks >=1.5.6)" + expected_output = "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)" assert transform_module_name(input_str) == expected_output -- Gitee From ee98b73c006adb4675cd4aea8b887b5834a8ab7e Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Thu, 6 Jul 2023 13:26:49 +0000 Subject: [PATCH 09/18] pass tests/test_get_pyproject_toml.py --- tests/test_get_pyproject_toml.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_get_pyproject_toml.py b/tests/test_get_pyproject_toml.py index 28669d8..60dc5bb 100644 --- a/tests/test_get_pyproject_toml.py +++ b/tests/test_get_pyproject_toml.py @@ -34,8 +34,9 @@ class TestPyprojectToml(unittest.TestCase): self.assertEqual(p.get_source_url(), SRC_URL) self.assertEqual(p.get_license(), "MIT License") self.assertEqual(p.get_requires(), [ - "brotli>=1.0.9", "certifi", "urllib3-secure-extra", - "(pysocks >= 1.5.6 with pysocks < 2.0)" + "(python3-brotli>=1.0.9)", "(python3-certifi)", + "(python3-urllib3-secure-extra)", + "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)" ]) def tearDown(self): -- Gitee From bd5989ce9b559275a700ec385010d887d898931f Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Fri, 7 Jul 2023 06:53:16 +0000 Subject: [PATCH 10/18] update --- pyporter/__init__.py | 2 +- pyporter/pyporter.py | 2 +- pyporter/utils.py | 2 -- tests/test_transform_module_name.py | 19 +++++++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pyporter/__init__.py b/pyporter/__init__.py index 16281fe..c621aba 100644 --- a/pyporter/__init__.py +++ b/pyporter/__init__.py @@ -1 +1 @@ -from .utils import * +from .utils import refine_requires, transform_module_name diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 1ab2273..ec7629a 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -215,7 +215,7 @@ class PyPorter: """ rs = self.__json["info"]["requires_dist"] if rs is None: - return + return [] all_requires = [] for r in rs: idx = r.find(";") diff --git a/pyporter/utils.py b/pyporter/utils.py index 628e230..0fa2346 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -47,7 +47,5 @@ def refine_requires(req: str) -> str: return only requires without ';' (thus no extra) """ ra = req.split(";", 1) - # # Do not add requires which has ;, which is often has very complicated precondition - # TODO: need more parsing of the denpency after ; return transform_module_name(ra[0]) diff --git a/tests/test_transform_module_name.py b/tests/test_transform_module_name.py index 0860e9b..765946e 100644 --- a/tests/test_transform_module_name.py +++ b/tests/test_transform_module_name.py @@ -1,16 +1,19 @@ +import unittest + from pyporter.utils import transform_module_name -def test_transform_module_name(): +class TestTransofrmModuleName(unittest.TestCase): - input_str = "brotli>=1.0.9" - expected_output = "(python3-brotli>=1.0.9)" - assert transform_module_name(input_str) == expected_output + def test_transform_module_name(self): + input_str = "brotli>=1.0.9" + expected_output = "(python3-brotli>=1.0.9)" + self.assertEqual(transform_module_name(input_str), expected_output) - input_str = "pysocks<2.0,>=1.5.6" - expected_output = "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)" - assert transform_module_name(input_str) == expected_output + input_str = "pysocks<2.0,>=1.5.6" + expected_output = "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)" + self.assertEqual(transform_module_name(input_str), expected_output) if __name__ == '__main__': - test_transform_module_name() + unittest.main() -- Gitee From 3c2ea60cca962e9cf9b2fc7a6ccfb86368aef5c5 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Tue, 11 Jul 2023 12:03:56 +0000 Subject: [PATCH 11/18] Use pyproject-rpm-macros to support pyproject.toml --- pyporter/pyporter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index ec7629a..26188eb 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -297,16 +297,21 @@ class PyPorter: print(buildreq_tag_template.format(req='python3-devel')) print(buildreq_tag_template.format(req='python3-setuptools')) print(buildreq_tag_template.format(req='python3-pip')) + print(buildreq_tag_template.format(req='pyproject-rpm-macros')) if not self.__build_noarch: print(buildreq_tag_template.format(req='python3-cffi')) print(buildreq_tag_template.format(req='gcc')) print(buildreq_tag_template.format(req='gdb')) def prepare_pkg_build(self): - print("%py3_build") + # print("%py3_build") + print("%generate_buildrequires") + print("%pyproject_buildrequires") + print("%pyproject_wheel") def prepare_pkg_install(self): - print("%py3_install") + # print("%py3_install") + print("%pyproject_install") def prepare_pkg_files(self): if self.__build_noarch: -- Gitee From 3885b32cbfeb3d76bb5ae5b1f99d364626b6b3a2 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Fri, 21 Jul 2023 14:29:00 +0000 Subject: [PATCH 12/18] update --- pyporter/pyporter.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 26188eb..154ff25 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -297,7 +297,9 @@ class PyPorter: print(buildreq_tag_template.format(req='python3-devel')) print(buildreq_tag_template.format(req='python3-setuptools')) print(buildreq_tag_template.format(req='python3-pip')) - print(buildreq_tag_template.format(req='pyproject-rpm-macros')) + # print(buildreq_tag_template.format(req='python3-hatchling')) + print(buildreq_tag_template.format(req='python3-pbr')) + print(buildreq_tag_template.format(req='python3-wheel')) if not self.__build_noarch: print(buildreq_tag_template.format(req='python3-cffi')) print(buildreq_tag_template.format(req='gcc')) @@ -305,9 +307,11 @@ class PyPorter: def prepare_pkg_build(self): # print("%py3_build") - print("%generate_buildrequires") - print("%pyproject_buildrequires") - print("%pyproject_wheel") + # print("%generate_buildrequires") + # print("%pyproject_buildrequires") + # print("%pyproject_wheel") + # print("%py_build_egg") + print("%pyproject_build") def prepare_pkg_install(self): # print("%py3_install") -- Gitee From d0eb367707f27c8d666079b4fd16515ef0cb9798 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Wed, 6 Sep 2023 08:51:54 +0000 Subject: [PATCH 13/18] update --- pyporter/pyporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 154ff25..016f8b0 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -297,7 +297,7 @@ class PyPorter: print(buildreq_tag_template.format(req='python3-devel')) print(buildreq_tag_template.format(req='python3-setuptools')) print(buildreq_tag_template.format(req='python3-pip')) - # print(buildreq_tag_template.format(req='python3-hatchling')) + print(buildreq_tag_template.format(req='python3-hatchling')) print(buildreq_tag_template.format(req='python3-pbr')) print(buildreq_tag_template.format(req='python3-wheel')) if not self.__build_noarch: -- Gitee From b32039ddb21cff24d36f33d03ccdd3db62be157c Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Thu, 7 Sep 2023 11:43:17 +0000 Subject: [PATCH 14/18] support jmespath (<2.0.0,>=0.7.1) --- pyporter/pyporter.py | 10 +++------- pyporter/utils.py | 4 ++-- tests/TestPyprojectToml.json | 3 ++- tests/test_get_pyproject_toml.py | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 016f8b0..526fb5c 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -297,9 +297,9 @@ class PyPorter: print(buildreq_tag_template.format(req='python3-devel')) print(buildreq_tag_template.format(req='python3-setuptools')) print(buildreq_tag_template.format(req='python3-pip')) - print(buildreq_tag_template.format(req='python3-hatchling')) - print(buildreq_tag_template.format(req='python3-pbr')) - print(buildreq_tag_template.format(req='python3-wheel')) + # print(buildreq_tag_template.format(req='python3-hatchling')) + # print(buildreq_tag_template.format(req='python3-pbr')) + # print(buildreq_tag_template.format(req='python3-wheel')) if not self.__build_noarch: print(buildreq_tag_template.format(req='python3-cffi')) print(buildreq_tag_template.format(req='gcc')) @@ -307,10 +307,6 @@ class PyPorter: def prepare_pkg_build(self): # print("%py3_build") - # print("%generate_buildrequires") - # print("%pyproject_buildrequires") - # print("%pyproject_wheel") - # print("%py_build_egg") print("%pyproject_build") def prepare_pkg_install(self): diff --git a/pyporter/utils.py b/pyporter/utils.py index 7db69e1..606589d 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -23,12 +23,12 @@ import re # else: # return ns[0] + # TODO: this should be more compatible for https://peps.python.org/pep-0508/ def transform_module_name(input_str): - # Extracting the module name from the input string module_name = re.match(r"([a-zA-Z0-9_-]+)", input_str).group(1).strip() version_names = input_str[len(module_name):].strip() - # Extracting the version constraint from the input string + version_names = version_names.strip("()") version_constraint = version_names.split(",") package_name = "python3-" + module_name if len(version_constraint) > 1: diff --git a/tests/TestPyprojectToml.json b/tests/TestPyprojectToml.json index 8122cba..f891831 100644 --- a/tests/TestPyprojectToml.json +++ b/tests/TestPyprojectToml.json @@ -51,7 +51,8 @@ "brotli>=1.0.9; platform_python_implementation == 'CPython' and extra == 'brotli'", "certifi; extra == 'secure'", "urllib3-secure-extra; extra == 'secure'", - "pysocks<2.0,>=1.5.6; extra == 'socks'" + "pysocks<2.0,>=1.5.6; extra == 'socks'", + "jmespath (<2.0.0,>=0.7.1)" ], "requires_python": ">=3.7", "summary": "HTTP library with thread-safe connection pooling, file post, and more.", diff --git a/tests/test_get_pyproject_toml.py b/tests/test_get_pyproject_toml.py index 60dc5bb..bb05073 100644 --- a/tests/test_get_pyproject_toml.py +++ b/tests/test_get_pyproject_toml.py @@ -36,7 +36,8 @@ class TestPyprojectToml(unittest.TestCase): self.assertEqual(p.get_requires(), [ "(python3-brotli>=1.0.9)", "(python3-certifi)", "(python3-urllib3-secure-extra)", - "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)" + "(python3-pysocks<2.0 with python3-pysocks>=1.5.6)", + "(python3-jmespath<2.0.0 with python3-jmespath>=0.7.1)" ]) def tearDown(self): -- Gitee From 9d453680d8ffcdbfbaf7602cc75910a214c273ad Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Sat, 9 Sep 2023 13:07:04 +0000 Subject: [PATCH 15/18] install botocore successfully --- pyporter/__init__.py | 1 + pyporter/pyporter.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyporter/__init__.py b/pyporter/__init__.py index c621aba..48fa674 100644 --- a/pyporter/__init__.py +++ b/pyporter/__init__.py @@ -1 +1,2 @@ +from .pyporter import * from .utils import refine_requires, transform_module_name diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 526fb5c..b7d8727 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -231,9 +231,8 @@ class PyPorter: """ rs = self.get_releases() for r in rs: - if r["packagetype"] == "bdist_wheel": - if r["url"].find("amd64") != -1: - return False + if r["packagetype"] == "bdist_wheel" and "amd64" in r["url"]: + return False return True def is_build_noarch(self): @@ -553,8 +552,10 @@ def build_spec(porter, output): print("mv %{buildroot}/doclist.lst .") print("") print(f"%files -n {porter.get_pkg_name()} -f filelist.lst") + # print("%defattr(-,root,root,-)") porter.prepare_pkg_files() + print("%{python3_sitelib}/*") print("") print("%files help -f doclist.lst") -- Gitee From 29c927fffd249538903d8d78a198b288b8efd71a Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Sat, 9 Sep 2023 13:20:07 +0000 Subject: [PATCH 16/18] successfully install repo with pyproject.toml --- pyporter/pyporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index b7d8727..360aa2f 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -315,8 +315,10 @@ class PyPorter: def prepare_pkg_files(self): if self.__build_noarch: print("%dir %{python3_sitelib}/*") + print("%{python3_sitelib}/*") else: print("%dir %{python3_sitearch}/*") + print("%{python3_sitearch}/*") def store_json(self, spath): """ @@ -552,10 +554,8 @@ def build_spec(porter, output): print("mv %{buildroot}/doclist.lst .") print("") print(f"%files -n {porter.get_pkg_name()} -f filelist.lst") - # print("%defattr(-,root,root,-)") porter.prepare_pkg_files() - print("%{python3_sitelib}/*") print("") print("%files help -f doclist.lst") -- Gitee From f1a67bf9d5273f8ff9ee8abfd0d75836962dddb6 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Mon, 11 Sep 2023 09:22:37 +0000 Subject: [PATCH 17/18] remove annottation --- pyporter/pyporter.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pyporter/pyporter.py b/pyporter/pyporter.py index 360aa2f..c635fa9 100755 --- a/pyporter/pyporter.py +++ b/pyporter/pyporter.py @@ -255,7 +255,6 @@ class PyPorter: for d in desc: if len(d.strip()) == 0: continue - first_char = d.strip()[0] ignore_line = False if d.strip().startswith("===") or d.strip().startswith("---"): paragraph = paragraph + 1 @@ -296,20 +295,15 @@ class PyPorter: print(buildreq_tag_template.format(req='python3-devel')) print(buildreq_tag_template.format(req='python3-setuptools')) print(buildreq_tag_template.format(req='python3-pip')) - # print(buildreq_tag_template.format(req='python3-hatchling')) - # print(buildreq_tag_template.format(req='python3-pbr')) - # print(buildreq_tag_template.format(req='python3-wheel')) if not self.__build_noarch: print(buildreq_tag_template.format(req='python3-cffi')) print(buildreq_tag_template.format(req='gcc')) print(buildreq_tag_template.format(req='gdb')) def prepare_pkg_build(self): - # print("%py3_build") print("%pyproject_build") def prepare_pkg_install(self): - # print("%py3_install") print("%pyproject_install") def prepare_pkg_files(self): @@ -327,7 +321,6 @@ 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 path.exists(json_file) and path.isfile(json_file): with open(json_file, 'r') as f: resp = json.load(f) @@ -395,9 +388,6 @@ def try_pip_install_package(pkg): f"{pip_name} can not be installed correctly, Fix it later, go ahead to do building..." ) - # - # TODO: try to build anyway, fix it later - # return True -- Gitee From 1367e34e0a41809e37c5a569f1ff616ea95e43f1 Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Mon, 11 Sep 2023 11:35:49 +0000 Subject: [PATCH 18/18] update --- pyporter/__init__.py | 5 ++++- pyporter/utils.py | 24 ------------------------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/pyporter/__init__.py b/pyporter/__init__.py index 48fa674..4859b22 100644 --- a/pyporter/__init__.py +++ b/pyporter/__init__.py @@ -1,2 +1,5 @@ -from .pyporter import * +from .pyporter import (PyPorter, build_install_rpm, build_package, build_rpm, + build_spec, do_args, download_source, main, + package_installed, porter_creator, + prepare_rpm_build_env, try_pip_install_package) from .utils import refine_requires, transform_module_name diff --git a/pyporter/utils.py b/pyporter/utils.py index 606589d..ece8948 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -1,30 +1,6 @@ import re -# def transform_module_name(s: str) -> str: -# """ -# return module name with version restriction. -# Any string with '.' or '/' is considered file, and will be ignored -# Modules start with python- will be changed to python3- for consistency. -# """ -# ns = re.split("[()]", s) -# ver_constrain = [] -# ns[0] = ns[0].strip() -# if ns[0].startswith("python-"): -# ns[0] = ns[0].replace("python-", "python3-") -# else: -# ns[0] = "python3-" + ns[0] -# # Process version constraints -# if len(ns) > 1: -# ver_constrain.append(ns[1]) - -# if len(ver_constrain) > 0: -# return f"({ns[0]} {ver_constrain[0]})" -# else: -# return ns[0] - - -# TODO: this should be more compatible for https://peps.python.org/pep-0508/ def transform_module_name(input_str): module_name = re.match(r"([a-zA-Z0-9_-]+)", input_str).group(1).strip() version_names = input_str[len(module_name):].strip() -- Gitee