Skip to content

Commit

Permalink
Merge branch 'keep_activated_env' into 1.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed Jun 22, 2016
2 parents 6f7c0e0 + ec4fa91 commit a919263
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 265 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ tags
MANIFEST
ve
venv
junit.xml
.cache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ install:
- conda config --set always_yes yes
- conda update -q --all
- conda install -q --force --no-deps conda requests
- conda install -q pip pytest requests jinja2 patchelf flake8 python=$TRAVIS_PYTHON_VERSION pyflakes=1.1
- conda install -q pip pytest requests jinja2 patchelf flake8 mock python=$TRAVIS_PYTHON_VERSION pyflakes=1.1
- conda install -q anaconda-client conda-build
- pip install pytest-cov
- python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install:
- python -c "import sys; print(sys.version)"
- python -c "import sys; print(sys.executable)"
- python -c "import sys; print(sys.prefix)"
- conda install -q pytest pytest-cov requests pycrypto git anaconda-client
- conda install -q pytest pytest-cov mock requests pycrypto git anaconda-client
# this is to ensure dependencies
- conda install -q conda-build
- python --version
Expand Down
1 change: 1 addition & 0 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test:
requires:
- pytest
- pytest-cov
- mock
commands:
- conda-build -h
imports:
Expand Down
39 changes: 30 additions & 9 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io
import json
import logging
import os
import shutil
import stat
Expand Down Expand Up @@ -53,6 +54,8 @@
override_channels = False
verbose = True

log = logging.getLogger(__file__)


def prefix_files():
'''
Expand Down Expand Up @@ -463,21 +466,40 @@ def build(m, post=None, include_recipe=True, keep_old_work=False,
rm_rf(config.short_build_prefix)
rm_rf(config.long_build_prefix)

specs = [ms.spec for ms in m.ms_depends('build')]
if activate:
# If we activate the build envrionment, we need to be sure that we
# have the appropriate VCS available in the environment. People
# are not used to explicitly listing it in recipes, though.
# We add it for them here, but warn them about it.
vcs_source = m.uses_vcs()
if vcs_source and vcs_source not in specs:
specs.append(vcs_source)
log.warn("Your recipe depends on {} at build time (for templates), "
"but you have not listed it as a build dependency. Doing so for"
" this build.")
# Display the name only
# Version number could be missing due to dependency on source info.
create_env(config.build_prefix,
[ms.spec for ms in m.ms_depends('build')])
create_env(config.build_prefix, specs)

if need_source_download:
# Execute any commands fetching the source (e.g., git) in the _build environment.
# This makes it possible to provide source fetchers (eg. git, hg, svn) as build
# dependencies.
m, need_source_download = parse_or_try_download(m,
no_download_source=False,
force_download=True,
verbose=verbose,
dirty=dirty)
assert not need_source_download, "Source download failed. Please investigate."
if not activate:
_old_path = os.environ['PATH']
os.environ['PATH'] = prepend_bin_path({'PATH': _old_path},
config.build_prefix)['PATH']
try:
m, need_source_download = parse_or_try_download(m,
no_download_source=False,
force_download=True,
verbose=verbose,
dirty=dirty)
assert not need_source_download, "Source download failed. Please investigate."
finally:
if not activate:
os.environ['PATH'] = _old_path

if m.name() in [i.rsplit('-', 2)[0] for i in linked(config.build_prefix)]:
print("%s is installed as a build dependency. Removing." %
Expand Down Expand Up @@ -691,7 +713,6 @@ def test(m, move_broken=True, activate=True):
specs += ['lua %s*' % environ.get_lua_ver()]

create_env(config.test_prefix, specs)

env = dict(os.environ)
env.update(environ.get_dict(m, prefix=config.test_prefix))

Expand Down
14 changes: 9 additions & 5 deletions conda_build/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ def main():
)
p.add_argument(
'--token',
action="store",
help="Token to pass through to anaconda upload"
)
p.add_argument(
'--user',
action='store',
help="User/organization to upload packages to on anaconda.org"
)
p.add_argument(
"--no-activate",
action="store_false",
help="do not display progress bar",
dest='activate',
)

add_parser_channels(p)
p.set_defaults(func=execute)
Expand Down Expand Up @@ -305,7 +309,7 @@ def execute(args, parser):
continue
elif args.test:
build.test(m, move_broken=False)
elif args.source:
elif args.source and need_source_download:
source.provide(m.path, m.get_section('source'), verbose=build.verbose)
print('Source tree in:', source.get_dir())
else:
Expand All @@ -325,7 +329,7 @@ def execute(args, parser):
include_recipe=args.include_recipe,
keep_old_work=args.keep_old_work,
need_source_download=need_source_download,
dirty=args.dirty)
dirty=args.dirty, activate=args.activate)
except (NoPackagesFound, Unsatisfiable) as e:
error_str = str(e)
# Typically if a conflict is with one of these
Expand Down Expand Up @@ -365,7 +369,7 @@ def execute(args, parser):
continue

if not args.notest:
build.test(m)
build.test(m, activate=args.activate)

if need_cleanup:
shutil.rmtree(recipe_dir)
Expand Down
26 changes: 26 additions & 0 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def parse_again(self, permit_undefined_jinja=False):
"""
if not self.meta_path:
return

self.meta = parse(self._get_contents(permit_undefined_jinja), path=self.meta_path)

if (isfile(self.requirements_path) and
Expand Down Expand Up @@ -693,3 +694,28 @@ def __repr__(self):
String representation of the MetaData.
'''
return self.__str__()

def uses_vcs(self):
"""returns true if recipe contains metadata associated with version control systems.
If this metadata is present, a download/copy will be forced in parse_or_try_download.
"""
vcs_types = ["git", "svn", "hg"]
if "source" in self.meta:
for vcs in vcs_types:
if vcs + "_url" in self.meta["source"]:
# translate command name to package name.
# If more than hg, need a dict for this.
if vcs == "hg":
vcs = "mercurial"
return vcs

# We would get here if we use Jinja2 templating, but specify source with path.
with open(self.meta_path) as f:
metayaml = f.read()
for vcs in vcs_types:
matches = re.findall(r"{}_[^\.\s\'\"]+".format(vcs.upper()), metayaml)
if len(matches) > 0:
if vcs == "hg":
vcs = "mercurial"
return vcs
return None
16 changes: 3 additions & 13 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,10 @@ def bldpkg_path(m):
return os.path.join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())


def has_vcs_metadata(metadata):
"""returns true if recie contains metadata associated with version control systems.
If this metadata is present, a download/copy will be forced in parse_or_try_download.
"""
with open(metadata.meta_path) as f:
matches = re.findall(r"GIT_[^\.\s\'\"]+", f.read())
# TODO: extend with other VCS systems (SVN, hg, anything else?)
return len(matches) > 0


def parse_or_try_download(metadata, no_download_source, verbose,
force_download=False, dirty=False):

if (force_download or (not no_download_source and has_vcs_metadata(metadata))):
if (force_download or (not no_download_source and metadata.uses_vcs())):
# this try/catch is for when the tool to download source is actually in
# meta.yaml, and not previously installed in builder env.
try:
Expand Down Expand Up @@ -140,13 +130,13 @@ def render_recipe(recipe_path, no_download_source, verbose, dirty=False):
sys.stderr.write(e.error_msg())
sys.exit(1)

m = parse_or_try_download(m, no_download_source=no_download_source,
m, need_download = parse_or_try_download(m, no_download_source=no_download_source,
verbose=verbose, dirty=dirty)

if need_cleanup:
shutil.rmtree(recipe_dir)

return m
return m, need_download


# Next bit of stuff is to support YAML output in the order we expect.
Expand Down
Loading

0 comments on commit a919263

Please sign in to comment.