diff --git a/conans/client/command.py b/conans/client/command.py index 98622cedbb5..e5ddce6e764 100644 --- a/conans/client/command.py +++ b/conans/client/command.py @@ -1886,7 +1886,8 @@ def lock(self, *args): create_cmd = subparsers.add_parser('create', help='Create a lockfile from a conanfile or a reference') - create_cmd.add_argument("path", nargs="?", help="Path to a conanfile") + create_cmd.add_argument("path", nargs="?", help="Path to a conanfile, including filename, " + "like 'path/conanfile.py'") create_cmd.add_argument("--name", action=OnceArgument, help='Provide a package name if not specified in conanfile') create_cmd.add_argument("--version", action=OnceArgument, diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py index 13952b6ccc9..6ded7e2a6a8 100644 --- a/conans/client/conan_api.py +++ b/conans/client/conan_api.py @@ -1380,6 +1380,9 @@ def lock_create(self, path, lockfile_out, if path: ref_or_path = _make_abs_path(path, cwd) + if os.path.isdir(ref_or_path): + raise ConanException("Path argument must include filename " + "like 'conanfile.py' or 'path/conanfile.py'") if not os.path.isfile(ref_or_path): raise ConanException("Conanfile does not exist in %s" % ref_or_path) else: # reference diff --git a/conans/test/integration/graph_lock/graph_lock_test.py b/conans/test/integration/graph_lock/graph_lock_test.py index 99b9bb577e8..b3e1ac3efbd 100644 --- a/conans/test/integration/graph_lock/graph_lock_test.py +++ b/conans/test/integration/graph_lock/graph_lock_test.py @@ -72,6 +72,14 @@ def test_error_no_find(self): client.run("install consumer.py name/version@ --lockfile=output.lock") self.assertIn("consumer.py (name/version): Generated graphinfo", client.out) + @staticmethod + def test_error_no_filename(): + # https://github.com/conan-io/conan/issues/8675 + client = TestClient() + client.save({"consumer.txt": ""}) + client.run("lock create .", assert_error=True) + assert "RROR: Path argument must include filename like 'conanfile.py'" in client.out + def test_commands_cannot_create_lockfile(self): client = TestClient() client.save({"conanfile.py": GenConanfile("PkgA", "0.1")})