Skip to content

Commit

Permalink
conan profile detect --nonexistent (#15933)
Browse files Browse the repository at this point in the history
* conan profile detect --nonexistent

* wip
  • Loading branch information
memsharded authored Mar 27, 2024
1 parent d9c3fb7 commit f75d15a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit f75d15a

Please sign in to comment.