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

conan profile detect --nonexistent #15933

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
10 changes: 8 additions & 2 deletions conan/cli/commands/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ def profile_detect(conan_api, parser, subparser, *args):
"""
subparser.add_argument("--name", help="Profile name, 'default' if not specified")
subparser.add_argument("-f", "--force", action='store_true', help="Overwrite if exists")
subparser.add_argument("-e", "--exist-ok", action='store_true',
help="If the profile already exist, do not detect a new one")
args = parser.parse_args(*args)

profile_name = args.name or "default"
profile_pathname = conan_api.profiles.get_path(profile_name, os.getcwd(), exists=False)
if not args.force and os.path.exists(profile_pathname):
raise ConanException(f"Profile '{profile_pathname}' already exists")
if os.path.exists(profile_pathname):
if args.exist_ok:
ConanOutput().info(f"Profile '{profile_name}' already exists, skipping detection")
return
if not args.force:
raise ConanException(f"Profile '{profile_pathname}' already exists")

detected_profile = conan_api.profiles.detect()
ConanOutput().success("\nDetected profile:")
Expand Down
11 changes: 8 additions & 3 deletions conans/test/functional/command/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ def test_profile_new(self):
assert "MyProfile2' already exists" in c.out

c.run("profile detect --name=./MyProfile2 --force") # will not raise error

assert "build_type=Release" in c.load("MyProfile2")
c.save({"MyProfile2": "potato"})
c.run("profile detect --name=./MyProfile2 --exist-ok") # wont raise, won't overwrite
assert "Profile './MyProfile2' already exists, skipping detection" in c.out
assert c.load("MyProfile2") == "potato"

@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows and msvc")
def test_profile_new_msvc_vcvars(self):
c = TestClient()
Expand All @@ -140,8 +145,8 @@ def test_profile_new_msvc_vcvars(self):
cl_executable = c.out.splitlines()[-1]
assert os.path.isfile(cl_executable)
cl_location = os.path.dirname(cl_executable)
# Try different variations, including full path and full path with quotes

# Try different variations, including full path and full path with quotes
for var in ["cl", "cl.exe", cl_executable, f'"{cl_executable}"']:
output = RedirectedTestOutput()
with redirect_output(output):
Expand Down