Skip to content

Commit

Permalink
Fix/lock create error msg (#8695)
Browse files Browse the repository at this point in the history
* improve error message for lock create

* cli help msg
  • Loading branch information
memsharded committed Mar 24, 2021
1 parent 27f6997 commit acf6de2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conans/client/command.py
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions conans/client/conan_api.py
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions conans/test/integration/graph_lock/graph_lock_test.py
Expand Up @@ -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")})
Expand Down

0 comments on commit acf6de2

Please sign in to comment.