From d6d4d53df78edfc2224c5a29153177399e94493c Mon Sep 17 00:00:00 2001 From: juyi <1263810658@qq.com> Date: Fri, 15 Sep 2023 14:33:20 +0000 Subject: [PATCH] merge --- README.md | 4 +++- pyporter/__init__.py | 4 ++++ pyporter/pyporter.py | 29 ++++++++++------------------- pyporter/utils.py | 26 +------------------------- tests/TestPyprojectToml.json | 3 ++- tests/test_get_pyproject_toml.py | 3 ++- 6 files changed, 22 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index ce96646..26bd45c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Install below software before using this tool 3. libstdc++-devel 4. python3-cffi 5. rpmbuild - +6. python3-hatchling +7. python3-hatch-vcs +8. openEuler-rpm-config (>= Release 30-39) #### Installation diff --git a/pyporter/__init__.py b/pyporter/__init__.py index c621aba..4859b22 100644 --- a/pyporter/__init__.py +++ b/pyporter/__init__.py @@ -1 +1,5 @@ +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/pyporter.py b/pyporter/pyporter.py index ec7629a..04b1998 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): @@ -256,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 @@ -303,16 +301,16 @@ class PyPorter: 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): if self.__build_noarch: - print("%dir %{python3_sitelib}/*") + print("%{python3_sitelib}/*") else: - print("%dir %{python3_sitearch}/*") + print("%{python3_sitearch}/*") def store_json(self, spath): """ @@ -321,7 +319,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) @@ -389,9 +386,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 @@ -516,13 +510,10 @@ def build_spec(porter, output): "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("fi") + print("touch filelist.lst") + # # 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("if [ -d usr/lib64 ]; then") print( "\tfind usr/lib64 -type f -printf \"\\\"/%h/%f\\\"\\n\" >> filelist.lst" diff --git a/pyporter/utils.py b/pyporter/utils.py index 7db69e1..1c8e3d4 100644 --- a/pyporter/utils.py +++ b/pyporter/utils.py @@ -1,34 +1,10 @@ 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): - # 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 = input_str[len(module_name):].strip().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