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

Fix/export pkg version pyrequire #16224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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