From cce91f3d6b6ae6992adaa1fd20fa35859109bd4b Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 9 Oct 2023 12:10:17 +0200 Subject: [PATCH] fixing python_requires in buildInfo --- extensions/commands/art/cmd_build_info.py | 30 +++++++++++++++- tests/test_artifactory_commands.py | 42 ++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/extensions/commands/art/cmd_build_info.py b/extensions/commands/art/cmd_build_info.py index 5205729..c8f8e5e 100644 --- a/extensions/commands/art/cmd_build_info.py +++ b/extensions/commands/art/cmd_build_info.py @@ -145,7 +145,7 @@ def _get_local_artifacts(): file_list = list(dl_folder.glob("*")) if len(file_list) >= 3: for file_path in dl_folder.glob("*"): - if file_path.is_file(): + if file_path.is_file(): # FIXME: Make it recursive for metadata folder file_name = file_path.name md5, sha1, sha256 = _get_hashes(file_path) artifact_info = {"type": os.path.splitext(file_name)[1].lstrip('.'), @@ -226,6 +226,33 @@ def _get_remote_artifacts(): return artifacts + def _get_python_requires(self, node, modules): + python_requires = node.get("python_requires") + if python_requires is None: + return + for pyref, pyreq in python_requires.items(): + pyrecipe = pyreq["recipe"] + artifacts_folder = pyreq["path"] + remote_path = _get_remote_path(pyref) + artifacts = [] + + dl_folder = Path(artifacts_folder).parents[0] / "d" + file_list = list(dl_folder.glob("*")) + for f in file_list: + if not f.is_file(): + continue # FIXME: This is discarding metadata folders + md5, sha1, sha256 = _get_hashes(f) + artifact_info = {"type": os.path.splitext(f.name)[1].lstrip('.'), + "sha256": sha256, + "sha1": sha1, + "md5": md5} + artifact_info.update({"name": f.name, "path": f'{self._repository}/{remote_path}/{f.name}'}) + artifacts.append(artifact_info) + pyreq_module = {"type": "conan", + "id": pyref, + "artifacts": artifacts} + modules.append(pyreq_module) + def get_modules(self): ret = [] try: @@ -237,6 +264,7 @@ def get_modules(self): ref = node.get("ref") if ref: transitive_dependencies = node.get("dependencies").keys() if node.get("dependencies").keys() else [] + self._get_python_requires(node, modules=ret) # only add the nodes that were marked as built if node.get("binary") == "Build": diff --git a/tests/test_artifactory_commands.py b/tests/test_artifactory_commands.py index 785f495..298ce74 100644 --- a/tests/test_artifactory_commands.py +++ b/tests/test_artifactory_commands.py @@ -1,7 +1,9 @@ +import json import os import tempfile +import textwrap -from tools import run +from tools import run, save import pytest @@ -198,6 +200,44 @@ def test_build_info_create_deps(): run('conan remove "*" -c -r extensions-stg') +@pytest.mark.requires_credentials +def test_build_info_create_python_requires(): + build_name = "mybuildinfo" + build_number = "1" + + run(f'conan art:server add artifactory {os.getenv("ART_URL")} --user="{os.getenv("CONAN_LOGIN_USERNAME_EXTENSIONS_STG")}" --password="{os.getenv("CONAN_PASSWORD_EXTENSIONS_STG")}"') + + # Create dependency packages and upload them + pytool = textwrap.dedent("""\ + from conan import ConanFile + class PyTool(ConanFile): + name = "pytool" + version = "0.1" + """) + save("conanfile.py", pytool) + run('conan create . ') + pkg = textwrap.dedent("""\ + from conan import ConanFile + class PyTool(ConanFile): + name = "pkg" + version = "0.1" + python_requires = "pytool/0.1" + """) + save("conanfile.py", pkg) + run('conan create . --format=json > create_release.json') + + run("conan upload * -c --dry-run -r=extensions-stg") + run(f'conan art:build-info create create_release.json {build_name}_release {build_number} extensions-stg --server artifactory --with-dependencies > {build_name}_release.json') + build_info = open("mybuildinfo_release.json").read() + + build_info = json.loads(build_info) + assert build_info["modules"][0]["id"] == "pytool/0.1#623dc6c0466e112d42f2b629d8abf49a" + artifacts = build_info["modules"][0]["artifacts"] + assert len(artifacts) == 2 + assert artifacts[0]["name"] == "conanfile.py" + assert artifacts[1]["name"] == "conanmanifest.txt" + + @pytest.mark.requires_credentials def test_fail_if_not_uploaded(): """