Skip to content

Commit

Permalink
Fix/export pkg version pyrequire (#16224)
Browse files Browse the repository at this point in the history
fix for export-pkg using py-requires to set version from cli arg
  • Loading branch information
memsharded committed May 9, 2024
1 parent 2058630 commit 8eea1a7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
7 changes: 4 additions & 3 deletions conan/api/subapi/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ def test(conanfile):
with chdir(conanfile.build_folder):
conanfile.test()

def inspect(self, conanfile_path, remotes, lockfile):
def inspect(self, conanfile_path, remotes, lockfile, name=None, version=None, user=None,
channel=None):
app = ConanApp(self._conan_api)
conanfile = app.loader.load_named(conanfile_path, name=None, version=None,
user=None, channel=None, remotes=remotes, graph_lock=lockfile)
conanfile = app.loader.load_named(conanfile_path, name=name, version=version, user=user,
channel=channel, remotes=remotes, graph_lock=lockfile)
return conanfile

3 changes: 2 additions & 1 deletion conan/cli/commands/export_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def export_pkg(conan_api, parser, *args):
profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args)
remotes = conan_api.remotes.list(args.remote) if not args.no_remote else []

conanfile = conan_api.local.inspect(path, remotes, lockfile)
conanfile = conan_api.local.inspect(path, remotes, lockfile, name=args.name,
version=args.version, user=args.user, channel=args.channel)
# The package_type is not fully processed at export
if conanfile.package_type == "python-require":
raise ConanException("export-pkg can only be used for binaries, not for 'python-require'")
Expand Down
31 changes: 31 additions & 0 deletions conans/test/integration/command/export_pkg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,34 @@ def test_remote_none_tool_requires():
c.run(f"export-pkg pkg {settings} -s:b compiler.cppstd=17") # This used to crash
# No longer crash
assert "pkg/0.1 (test package): Running test()" in c.out


def test_export_pkg_set_version_python_requires():
# https://github.com/conan-io/conan/issues/16223
c = TestClient(light=True)
py_require = textwrap.dedent("""
from conan import ConanFile
class TestBuild:
def set_version(self):
assert self.version
class TestModule(ConanFile):
name = "pyreq"
version = "0.1"
package_type = "python-require"
""")
pkg = textwrap.dedent("""
from conan import ConanFile
class TestPkgConan(ConanFile):
name="testpkg"
python_requires = "pyreq/0.1"
python_requires_extend = "pyreq.TestBuild"
""")
c.save({"pyreq/conanfile.py": py_require,
"pkg/conanfile.py": pkg})

c.run("create pyreq")
c.run("export-pkg pkg --version=1.0+0")
assert "conanfile.py (testpkg/1.0+0): Exported package binary" in c.out

0 comments on commit 8eea1a7

Please sign in to comment.