Skip to content

Commit

Permalink
rollback some changes in conan-io#7048 that modifies public tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsogo committed May 26, 2020
1 parent b839f8e commit e3ee634
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
18 changes: 9 additions & 9 deletions conans/client/cmd/export.py
Expand Up @@ -252,20 +252,19 @@ def _capture_scm_auto_fields(conanfile, conanfile_dir, package_layout, output, i
origin = scm.get_qualified_remote_url(remove_credentials=True)
local_src_path = scm.get_local_path_to_url(origin)
return scm_data, local_src_path

if scm_data.url == "auto":
origin = scm.get_qualified_remote_url(remove_credentials=True)
if not origin:
output.warn("Repo origin cannot be deduced, 'auto' fields won't be replaced."
" 'conan upload' command will prevent uploading recipes with 'auto'"
" values in these fields.")
local_src_path = scm.get_local_path_to_url(origin)
return scm_data, local_src_path
if scm.is_local_repository():
output.warn("Repo origin looks like a local path: %s" % origin)
output.success("Repo origin deduced by 'auto': %s" % origin)
if origin:
scm_data.url = origin
else:
output.warn(
"origin is auto, upload' command will prevent uploading recipes with None values in these fields.")

if scm_data.url is None:
output.warn(
"origin is None, upload' command will prevent uploading recipes with None values in these fields.")
scm_data.url = origin

if scm_data.revision == "auto":
# If it is pristine by default we don't replace the "auto" unless forcing
Expand All @@ -275,6 +274,7 @@ def _capture_scm_auto_fields(conanfile, conanfile_dir, package_layout, output, i

local_src_path = scm.get_local_path_to_url(scm_data.url)
_replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata)

return scm_data, local_src_path


Expand Down
14 changes: 8 additions & 6 deletions conans/client/cmd/uploader.py
Expand Up @@ -295,12 +295,14 @@ def _upload_recipe(self, ref, conanfile, retry, retry_wait, policy, remote, remo
if policy != UPLOAD_POLICY_FORCE:
# Check SCM data for auto fields
if hasattr(conanfile, "scm") and (
conanfile.scm.get("url") == None or conanfile.scm.get("url") == "auto" or conanfile.scm.get("revision") == "auto"):
raise ConanException("The recipe has 'scm.url' with None or 'auto', or 'scm.revision' with 'auto' "
"values. Use '--force' to ignore this error or export again "
"the recipe ('conan export' or 'conan create') in a "
"repository with no-uncommitted changes or by "
"using the '--ignore-dirty' option")
conanfile.scm.get("url") == "auto" or conanfile.scm.get("revision") == "auto" or
conanfile.scm.get("type") is None or conanfile.scm.get("url") is None or
conanfile.scm.get("revision") is None):
raise ConanException("The recipe contains invalid data in the 'scm' attribute"
" (some 'auto' values or missing fields 'type', 'url' or"
" 'revision'). Use '--force' to ignore this error or export"
" again the recipe ('conan export' or 'conan create') to"
" fix these issues.")

remote_manifest = self._check_recipe_date(ref, remote, local_manifest)
if policy == UPLOAD_POLICY_SKIP:
Expand Down
14 changes: 4 additions & 10 deletions conans/client/tools/scm.py
Expand Up @@ -191,7 +191,7 @@ def get_remote_url(self, remote_name=None, remove_credentials=False):
name, url = remote.split(None, 1)
if name == remote_name:
url, _ = url.rsplit(None, 1)
if url and remove_credentials and not os.path.exists(url): # only if not local
if remove_credentials and not os.path.exists(url): # only if not local
url = self._remove_credentials_url(url)
if os.path.exists(url): # Windows local directory
url = url.replace("\\", "/")
Expand All @@ -200,10 +200,7 @@ def get_remote_url(self, remote_name=None, remove_credentials=False):

def is_local_repository(self):
url = self.get_remote_url()
if url:
return os.path.exists(url)
else:
return None
return os.path.exists(url)

def get_commit(self):
self.check_repo()
Expand Down Expand Up @@ -345,7 +342,7 @@ def excluded_files(self):

def get_remote_url(self, remove_credentials=False):
url = self._show_item('url')
if url and remove_credentials and not os.path.exists(url): # only if not local
if remove_credentials and not os.path.exists(url): # only if not local
url = self._remove_credentials_url(url)
return url

Expand All @@ -357,11 +354,8 @@ def get_qualified_remote_url(self, remove_credentials=False):

def is_local_repository(self):
url = self.get_remote_url()
if url:
return (url.startswith(self.file_protocol) and
return (url.startswith(self.file_protocol) and
os.path.exists(unquote(url[len(self.file_protocol):])))
else:
return True

def is_pristine(self):
# Check if working copy is pristine/consistent
Expand Down
20 changes: 10 additions & 10 deletions conans/test/functional/scm/scm_test.py
Expand Up @@ -128,8 +128,8 @@ def test_auto_git(self):
self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
create_local_git_repo(folder=self.client.current_folder)
self.client.run("export . user/channel")
self.assertIn("Repo origin deduced by 'auto': None", self.client.out)
self.assertIn("Revision deduced by 'auto'", self.client.out)
self.assertIn("WARN: Repo origin cannot be deduced, 'auto' fields won't be replaced",
self.client.out)

self.client.run_command('git remote add origin https://myrepo.com.git')

Expand Down Expand Up @@ -1032,9 +1032,10 @@ def test_upload_blocking_auto(self):
"Use --ignore-dirty to force it.", client.out)
# The upload has to fail, no "auto" fields are allowed
client.run("upload lib/0.1@user/channel -r default", assert_error=True)
self.assertIn("ERROR: lib/0.1@user/channel: Upload recipe to 'default' failed: "
"The recipe has 'scm.url' with None or 'auto', or 'scm.revision' "
"with 'auto' values. Use '--force' to ignore", client.out)
self.assertIn("ERROR: lib/0.1@user/channel: Upload recipe to 'default' failed:"
" The recipe contains invalid data in the 'scm' attribute (some 'auto'"
" values or missing fields 'type', 'url' or 'revision'). Use '--force'"
" to ignore", client.out)
# The upload with --force should work
client.run("upload lib/0.1@user/channel -r default --force")
self.assertIn("Uploaded conan recipe", client.out)
Expand Down Expand Up @@ -1085,10 +1086,9 @@ class ConanLib(ConanFile):
client.save({"conanfile.py": conanfile})
create_local_git_repo(folder=client.current_folder)
client.run("create . pkg/0.1@user/channel")
self.assertIn("pkg/0.1@user/channel: WARN: origin is None, upload' command", client.out)

client.run("upload pkg/0.1@user/channel -r default", assert_error=True)
self.assertIn("ERROR: pkg/0.1@user/channel: Upload recipe to 'default' failed: "
"The recipe has 'scm.url' with None or 'auto', or 'scm.revision' "
"with 'auto' values. Use '--force' to ignore", client.out)
self.assertIn("ERROR: pkg/0.1@user/channel: Upload recipe to 'default' failed: The recipe"
" contains invalid data in the 'scm' attribute (some 'auto' values or"
" missing fields 'type', 'url' or 'revision'). Use '--force' to ignore",
client.out)
client.run("upload pkg/0.1@user/channel -r default --force")
3 changes: 2 additions & 1 deletion conans/test/functional/scm/test_command_export.py
Expand Up @@ -60,4 +60,5 @@ def test_non_existing_remote(self, auto_url, auto_rev):
self.client.current_folder = self.path
self.client.run("export . lib/version@user/channel")
if auto_url:
self.assertIn("Repo origin deduced by 'auto': None", self.client.out)
self.assertIn("WARN: Repo origin cannot be deduced, 'auto' fields won't be replaced.",
self.client.out)

0 comments on commit e3ee634

Please sign in to comment.