Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing python_requires in buildInfo #75

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
30 changes: 29 additions & 1 deletion extensions/commands/art/cmd_build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'),
Expand Down Expand Up @@ -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:
Expand All @@ -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":
Expand Down
42 changes: 41 additions & 1 deletion tests/test_artifactory_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os
import tempfile
import textwrap

from tools import run
from tools import run, save

import pytest

Expand Down Expand Up @@ -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")
czoido marked this conversation as resolved.
Show resolved Hide resolved
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():
"""
Expand Down