Skip to content

Commit

Permalink
Feature/python id mode (#15453)
Browse files Browse the repository at this point in the history
* started python_requires_id_mode

* wip

* wip

* python_package_id_mode proposal
  • Loading branch information
memsharded authored Jan 15, 2024
1 parent e7a0033 commit f8a630b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conans/client/graph/compute_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def compute_package_id(node, new_config):

python_requires = getattr(conanfile, "python_requires", None)
if python_requires:
python_requires = python_requires.all_refs()
python_requires = python_requires.info_requires()

data = OrderedDict()
build_data = OrderedDict()
Expand Down
4 changes: 4 additions & 0 deletions conans/client/graph/python_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def serialize(self):
def all_refs(self):
return [r.ref for r in self._pyrequires.values()]

def info_requires(self):
return {pyreq.ref: getattr(pyreq.conanfile, "package_id_python_mode", None)
for pyreq in self._pyrequires.values()}

def items(self):
return self._pyrequires.items()

Expand Down
8 changes: 5 additions & 3 deletions conans/model/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, ref, package_id, default_package_id_mode):
self._package_id = package_id
self.name = self.version = self.user = self.channel = self.package_id = None
self.recipe_revision = None
self.package_id_mode = default_package_id_mode

try:
func_package_id_mode = getattr(self, default_package_id_mode)
Expand Down Expand Up @@ -234,14 +235,15 @@ class PythonRequiresInfo:
def __init__(self, refs, default_package_id_mode):
self._default_package_id_mode = default_package_id_mode
if refs:
self._refs = [RequirementInfo(r, None, default_package_id_mode=default_package_id_mode)
for r in sorted(refs)]
self._refs = [RequirementInfo(r, None,
default_package_id_mode=mode or default_package_id_mode)
for r, mode in sorted(refs.items())]
else:
self._refs = None

def copy(self):
# For build_id() implementation
refs = [r._ref for r in self._refs] if self._refs else None
refs = {r._ref: r.package_id_mode for r in self._refs} if self._refs else None
return PythonRequiresInfo(refs, self._default_package_id_mode)

def __bool__(self):
Expand Down
34 changes: 34 additions & 0 deletions conans/test/integration/package_id/package_id_modes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,37 @@ class Dep(ConanFile):
c.run("create dep --version=0.2")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("56934f87c11792e356423e081c7cd490f3c1fbe0", "Build")})

def test_dep_python_require_defined(self):
c = TestClient()
dep = textwrap.dedent("""
from conan import ConanFile
class Dep(ConanFile):
name = "dep"
package_type = "python-require"
package_id_python_mode = "major_mode"
""")
c.save({"dep/conanfile.py": dep,
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_python_requires("dep/[*]")})
c.run("create dep --version=0.1")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("331c17383dcdf37f79bc2b86fa55ac56afdc6fec", "Build")})

# using dep 0.2, still same, because dependency chose "major"
c.run("create dep --version=0.1.1")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("331c17383dcdf37f79bc2b86fa55ac56afdc6fec", "Build")})

# using dep 0.2, still same, because dependency chose "major"
c.run("create dep --version=0.2")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("331c17383dcdf37f79bc2b86fa55ac56afdc6fec", "Build")})
c.run("list *:*")
assert "dep/0.Y.Z" in c.out

# using dep 0.2, new package_id, because dependency chose "major"
c.run("create dep --version=1.0")
c.run("create pkg")
c.assert_listed_binary({"pkg/0.1": ("9b015e30b768df0217ffa2c270f60227c998e609", "Build")})
c.run("list *:*")
assert "dep/1.Y.Z" in c.out

0 comments on commit f8a630b

Please sign in to comment.