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/lock create error msg #8695

Merged
merged 2 commits into from Mar 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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