Skip to content

Commit

Permalink
Merge branch 'release/0.14.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Oct 20, 2016
2 parents 4cf5453 + 2ce9bae commit 829c724
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 39 deletions.
2 changes: 1 addition & 1 deletion conans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
from conans.util.files import load
import os

__version__ = '0.14.0'
__version__ = '0.14.1'

10 changes: 6 additions & 4 deletions conans/client/client_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def export_paths(self, conan_reference):
''' Returns all file paths for a conans (relative to conans directory)'''
return relative_dirs(self.export(conan_reference))

def package_paths(self, package_reference):
def package_paths(self, package_reference, short_paths):
''' Returns all file paths for a package (relative to conans directory)'''
return relative_dirs(self.package(package_reference))
return relative_dirs(self.package(package_reference, short_paths))

def conan_packages(self, conan_reference):
""" Returns a list of package_id from a local cache package folder """
Expand Down Expand Up @@ -124,15 +124,17 @@ def load_package_manifest(self, package_reference):

def conan_manifests(self, conan_reference):
digest_path = self.digestfile_conanfile(conan_reference)
if not path_exists(digest_path, self.store):
return None, None
return self._digests(digest_path)

def package_manifests(self, package_reference):
digest_path = self.digestfile_package(package_reference, short_paths=None)
if not os.path.exists(digest_path):
return None, None
return self._digests(digest_path)

def _digests(self, digest_path):
if not path_exists(digest_path, self.store):
return None, None
readed_digest = FileTreeManifest.loads(load(digest_path))
expected_digest = FileTreeManifest.create(os.path.dirname(digest_path))
return readed_digest, expected_digest
Expand Down
6 changes: 3 additions & 3 deletions conans/client/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fnmatch
import shutil

from conans.paths import CONANINFO, BUILD_INFO
from conans.paths import CONANINFO, BUILD_INFO, package_exists, build_exists
from conans.util.files import save, rmdir
from conans.model.ref import PackageReference
from conans.util.log import logger
Expand Down Expand Up @@ -160,7 +160,7 @@ def _build_node(self, conan_ref, conan_file, build_mode):
# If already exists do not dirt the output, the common situation
# is that package is already installed and OK. If don't, the proxy
# will print some other message about it
if not os.path.exists(package_folder):
if not package_exists(package_folder):
output.info("Installing package %s" % package_id)

self._handle_system_requirements(conan_ref, package_reference, conan_file, output)
Expand Down Expand Up @@ -250,7 +250,7 @@ def _build_package(self, export_folder, src_folder, build_folder, package_folder
code
"""
output.info('Building your package in %s' % build_folder)
if not os.path.exists(build_folder):
if not build_exists(build_folder):
config_source(export_folder, src_folder, conan_file, output)
output.info('Copying sources to build folder')

Expand Down
6 changes: 3 additions & 3 deletions conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def __init__(self, runner, settings, options, scopes):
to start propagation, and having them in order to call build()
'''
self._runner = runner
assert isinstance(settings, Settings)
assert isinstance(options, OptionsValues)
assert isinstance(scopes, Scopes)
assert settings is None or isinstance(settings, Settings)
assert options is None or isinstance(options, OptionsValues)
assert scopes is None or isinstance(scopes, Scopes)
self._settings = settings
self._options = options
self._scopes = scopes
Expand Down
6 changes: 4 additions & 2 deletions conans/client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from collections import OrderedDict

from conans.paths import (CONANFILE, CONANINFO, CONANFILE_TXT, BUILD_INFO)
from conans.paths import (CONANFILE, CONANINFO, CONANFILE_TXT, BUILD_INFO, build_exists)
from conans.client.loader import ConanFileLoader
from conans.client.export import export_conanfile
from conans.client.deps_builder import DepsBuilder
Expand Down Expand Up @@ -218,6 +218,8 @@ def _read_profile(self, profile_name):
try:
profile = self._client_cache.load_profile(profile_name)
return profile
except ConanException as exc:
raise ConanException("Error reading '%s' profile: %s" % (profile_name, exc))
except Exception:
current_profiles = ", ".join(self._client_cache.current_profiles()) or "[]"
raise ConanException("Specified profile '%s' doesn't exist.\nExisting profiles: "
Expand Down Expand Up @@ -349,7 +351,7 @@ def package(self, reference, package_id):

for package_reference in packages:
build_folder = self._client_cache.build(package_reference, short_paths=None)
if not os.path.exists(build_folder):
if not build_exists(build_folder):
raise NotFoundException("%s: Package binary '%s' folder doesn't exist\n"
"Please read the 'conan package' command help\n"
"Use 'conan install' or 'conan test_package' to build and "
Expand Down
22 changes: 14 additions & 8 deletions conans/client/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
NotFoundException)
from conans.client.remote_registry import RemoteRegistry
from conans.util.log import logger
import os
from conans.paths import package_exists, CONANFILE
from conans.client.loader import ConanFileLoader


class ConanProxy(object):
Expand Down Expand Up @@ -36,7 +37,7 @@ def get_package(self, package_reference, force_build, short_paths):
package_folder = self._client_cache.package(package_reference, short_paths=short_paths)

# Check current package status
if path_exists(package_folder, self._client_cache.store):
if package_exists(package_folder):
if self._check_updates:
read_manifest = self._client_cache.load_package_manifest(package_reference)
try: # get_conan_digest can fail, not in server
Expand All @@ -54,13 +55,14 @@ def get_package(self, package_reference, force_build, short_paths):

installed = False
if not force_build:
local_package = os.path.exists(package_folder)
local_package = package_exists(package_folder)
if local_package:
output = ScopedOutput(str(package_reference.conan), self._out)
output.info('Already installed!')
installed = True
else:
installed = self._retrieve_remote_package(package_reference, output)
installed = self._retrieve_remote_package(package_reference, package_folder,
output)

self.handle_package_manifest(package_reference, installed)
return installed
Expand Down Expand Up @@ -263,13 +265,18 @@ def download_packages(self, reference, package_ids):
remote, _ = self._get_remote(reference)
export_path = self._client_cache.export(reference)
self._remote_manager.get_recipe(reference, export_path, remote)
conanfile_path = self._client_cache.conanfile(reference)
loader = ConanFileLoader(None, None, None, None)
conanfile = loader.load_class(conanfile_path)
short_paths = conanfile.short_paths
self._registry.set_ref(reference, remote)
output = ScopedOutput(str(reference), self._out)
for package_id in package_ids:
package_reference = PackageReference(reference, package_id)
self._retrieve_remote_package(package_reference, output, remote)
package_folder = self._client_cache.package(package_reference, short_paths=short_paths)
self._retrieve_remote_package(package_reference, package_folder, output, remote)

def _retrieve_remote_package(self, package_reference, output, remote=None):
def _retrieve_remote_package(self, package_reference, package_folder, output, remote=None):

if remote is None:
remote = self._registry.get_ref(package_reference.conan)
Expand All @@ -281,8 +288,7 @@ def _retrieve_remote_package(self, package_reference, output, remote=None):
try:
output.info("Looking for package %s in remote '%s' " % (package_id, remote.name))
# Will raise if not found NotFoundException
package_path = self._client_cache.package(package_reference)
self._remote_manager.get_package(package_reference, package_path, remote)
self._remote_manager.get_package(package_reference, package_folder, remote)
output.success('Package installed %s' % package_id)
return True
except ConanConnectionError:
Expand Down
3 changes: 2 additions & 1 deletion conans/client/remote_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def upload_package(self, package_reference, remote):
t1 = time.time()
# existing package, will use short paths if defined
basedir = self._client_cache.package(package_reference, short_paths=None)
rel_files = self._client_cache.package_paths(package_reference)
rel_files = self._client_cache.package_paths(package_reference, short_paths=None)

self._output.rewrite_line("Checking package integrity...")
if CONANINFO not in rel_files or CONAN_MANIFEST not in rel_files:
Expand Down Expand Up @@ -223,6 +223,7 @@ def unzip_and_get_files(files, destination_dir, tgz_name):
tgz_file = files.pop(tgz_name, None)
if tgz_file:
uncompress_file(tgz_file, destination_dir)
os.remove(tgz_file)

return relative_dirs(destination_dir)

Expand Down
4 changes: 2 additions & 2 deletions conans/client/source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conans.paths import DIRTY_FILE
from conans.paths import DIRTY_FILE, source_exists
import os
from conans.util.files import rmdir, save
import six
Expand Down Expand Up @@ -36,7 +36,7 @@ def remove_source(raise_error=False):
output.warn("Detected build_policy 'always', trying to remove source folder")
remove_source(raise_error=True)

if not os.path.exists(src_folder):
if not source_exists(src_folder):
output.info('Configuring sources in %s' % src_folder)
shutil.copytree(export_folder, src_folder)
save(dirty, "") # Creation of DIRTY flag
Expand Down
21 changes: 14 additions & 7 deletions conans/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import OrderedDict
from conans.util.config_parser import ConfigParser
from conans.model.scope import Scopes, _root
from conans.errors import ConanException


class Profile(object):
Expand All @@ -19,18 +20,24 @@ def loads(text):
obj = Profile()
doc = ConfigParser(text, allowed_fields=["settings", "env", "scopes"])

for setting in doc.settings.split("\n"):
if setting:
for setting in doc.settings.splitlines():
setting = setting.strip()
if setting and not setting.startswith("#"):
if "=" not in setting:
raise ConanException("Invalid setting line '%s'" % setting)
name, value = setting.split("=")
obj.settings[name] = value
obj.settings[name.strip()] = value.strip()

if doc.scopes:
obj.scopes = Scopes.from_list(doc.scopes.split("\n"))
obj.scopes = Scopes.from_list(doc.scopes.splitlines())

for env in doc.env.split("\n"):
if env:
for env in doc.env.splitlines():
env = env.strip()
if env and not env.startswith("#"):
if "=" not in env:
raise ConanException("Invalid env line '%s'" % env)
varname, value = env.split("=")
obj.env[varname] = value
obj.env[varname.strip()] = value.strip()

obj._order()
return obj
Expand Down
12 changes: 12 additions & 0 deletions conans/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ def shortener(path, short_paths):
return redirect


def package_exists(folder):
return os.path.exists(os.path.join(folder, CONANINFO))


def build_exists(folder):
return os.path.exists(os.path.join(folder, CONANFILE))


def source_exists(folder):
return os.path.exists(os.path.join(folder, CONANFILE))


class SimplePaths(object):
"""
Generate Conan paths. Handles the conan domain path logic. NO DISK ACCESS, just
Expand Down
72 changes: 72 additions & 0 deletions conans/test/integration/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,78 @@ class ProfileTest(unittest.TestCase):
def setUp(self):
self.client = TestClient()

def bad_syntax_test(self):
self.client.save({CONANFILE: conanfile_scope_env})
self.client.run("export lasote/stable")

profile = '''
[settings
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self.assertIn("Error reading 'clang' profile", self.client.user_io.out)
self.assertIn("Bad syntax", self.client.user_io.out)

profile = '''
[settings]
[invented]
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self.assertIn("Unrecognized field 'invented'", self.client.user_io.out)
self.assertIn("Error reading 'clang' profile", self.client.user_io.out)

profile = '''
[settings]
as
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self.assertIn("Error reading 'clang' profile: Invalid setting line 'as'", self.client.user_io.out)

profile = '''
[env]
as
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self.assertIn("Error reading 'clang' profile: Invalid env line 'as'", self.client.user_io.out)

profile = '''
[scopes]
as
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self.assertIn("Error reading 'clang' profile: Bad scope as", self.client.user_io.out)

profile = '''
[settings]
os = a value
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
# stripped "a value"
self.assertIn("'a value' is not a valid 'settings.os'", self.client.user_io.out)

profile = '''
[env]
ENV_VAR = a value
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build missing -pr clang", ignore_error=True)
self._assert_env_variable_printed("ENV_VAR", "a value")

profile = '''
# Line with comments is not a problem
[env]
# Not even here
ENV_VAR = a value
'''
save(self.client.client_cache.profile_path("clang"), profile)
self.client.run("install Hello0/0.1@lasote/stable --build -pr clang", ignore_error=True)
self._assert_env_variable_printed("ENV_VAR", "a value")

def build_with_profile_test(self):
self._create_profile("scopes_env", {},
{}, # undefined scope do not apply to my packages
Expand Down
1 change: 1 addition & 0 deletions conans/test/path_exists_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PathExistsTest(unittest.TestCase):
def test_paths(self):
"""Unit test of path_exists"""
tmp_dir = temp_folder()
tmp_dir = os.path.join(tmp_dir, "WhatEver")
new_path = os.path.join(tmp_dir, "CapsDir")
mkdir(new_path)
self.assertTrue(path_exists(new_path, tmp_dir))
Expand Down
Loading

0 comments on commit 829c724

Please sign in to comment.