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

Rollback (and simplify) changes from #7048 #7095

Merged
merged 2 commits into from May 27, 2020
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
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
7 changes: 5 additions & 2 deletions conans/client/source.py
Expand Up @@ -185,8 +185,11 @@ def _run_cache_scm(conanfile, scm_sources_folder, src_folder, output):
merge_directories(scm_sources_folder, dest_dir)
else:
output.info("SCM: Getting sources from url: '%s'" % scm_data.url)
scm = SCM(scm_data, dest_dir, output)
scm.checkout()
try:
scm = SCM(scm_data, dest_dir, output)
scm.checkout()
except Exception as e:
raise ConanException("Couldn't checkout SCM: %s" % str(e))
# This is a bit weird. Why after a SCM should we remove files.
# Maybe check conan 2.0
# TODO: Why removing in the cache? There is no danger.
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
64 changes: 59 additions & 5 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,63 @@ 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)

def test_export_blocking_type_none(self):
client = TestClient(default_server_user=True)
conanfile = textwrap.dedent("""
from conans import ConanFile
class ConanLib(ConanFile):
scm = {
"type": None,
"url": "some url",
"revision": "some_rev",
}
""")
client.save({"conanfile.py": conanfile})
client.run("export . pkg/0.1@user/channel", assert_error=True)
self.assertIn("ERROR: SCM not supported: None", client.out)

def test_create_blocking_url_none(self):
# If URL is None, it cannot create locally, as it will try to clone it
client = TestClient()
conanfile = textwrap.dedent("""
from conans import ConanFile
class ConanLib(ConanFile):
scm = {
"type": "git",
"url": None,
"revision": "some_rev",
}
""")
client.save({"conanfile.py": conanfile})
client.run("create . pkg/0.1@user/channel", assert_error=True)
self.assertIn("Couldn't checkout SCM:", client.out)

def test_upload_blocking_url_none_revision_auto(self):
# if the revision is auto and the url is None, it can be created locally, but not uploaded
client = TestClient(default_server_user=True)
conanfile = textwrap.dedent("""
from conans import ConanFile
class ConanLib(ConanFile):
scm = {
"type": "git",
"url": None,
"revision": "auto",
}
""")
client.save({"conanfile.py": conanfile})
create_local_git_repo(folder=client.current_folder)
client.run("create . pkg/0.1@user/channel")
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"
" 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)