Skip to content

Commit

Permalink
Add no_resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenvp committed Feb 4, 2020
1 parent 65c4803 commit 9b7ea3c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/wurf/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create(
# virtualenv will create symlinks to the Python interpreter and other
# stuff - if those are create in the build folder waf will try to
# delete them when running waf clean.
if cwd.startswith(ctx.bldnode.abspath()):
if cwd.startswith(os.path.join(ctx.path.abspath(), 'build')):
ctx.fatal(
"Cannot create virtualenv inside the build folder. "
"Virtualenv create symlinks to files that will be "
Expand Down
16 changes: 15 additions & 1 deletion src/wurf/waf_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@
from waflib.Configure import conf
from waflib.Errors import WafError
from waflib import Logs
from waflib import Context

from . import waf_resolve_context
from . import virtualenv
from . import rewrite


def extend_context(f):
"""
Decorator: attach new functions to waflib.Context. It is like
Waf's conf decorator. But instead of just extending the
ConfigurationContext and BuildContext this will extend the
base Context.
:param f: Method to bind
"""
setattr(Context.Context, f.__name__, f)
return f


@conf
def dependency_path(ctx, name):
"""
Expand Down Expand Up @@ -106,7 +120,7 @@ def recurse_dependencies(ctx):
raise WafError(msg=msg, ex=e)


@conf
@extend_context
def create_virtualenv(ctx, cwd=None, env=None, name=None, overwrite=True,
system_site_packages=False, download=True, download_path=None):

Expand Down
27 changes: 20 additions & 7 deletions src/wurf/waf_options_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# encoding: utf-8

import os
import sys

from waflib import Context
from waflib import Options
Expand Down Expand Up @@ -37,6 +38,10 @@ def __init__(self, **kw):
# Options parser used in the resolve step.
self.wurf_options = None

# Add option to skip resolve
gr = self.add_option_group('Resolve options')
gr.add_option('--no_resolve', default=False, action='store_true')

def execute(self):

self.srcnode = self.path
Expand All @@ -53,8 +58,13 @@ def execute(self):
self.logger = Logs.make_logger(path=log_path, name='options')
self.logger.debug('wurf: Options execute')

# Peek into the options and see of --no_resolve was passed
# if it was skip the resolve. We have at this point not parsed
# the options so we just do it manually
resolve = '--no_resolve' not in sys.argv

# Create and execute the resolve context
ctx = Context.create_context('resolve', resolve=True)
ctx = Context.create_context('resolve', resolve=resolve)

try:
ctx.execute()
Expand All @@ -63,12 +73,15 @@ def execute(self):

# Fetch the resolve options parser such that we can
# print help if needed:
self.wurf_options = ctx.registry.require('options')

# Fetch the arguments not parsed in the resolve step
# We are just interested in the left-over args, which is the
# second value retuned by parse_known_args(...)
self.waf_options = self.wurf_options.unknown_args
if resolve:
self.wurf_options = ctx.registry.require('options')

# Fetch the arguments not parsed in the resolve step
# We are just interested in the left-over args, which is the
# second value retuned by parse_known_args(...)
self.waf_options = self.wurf_options.unknown_args
else:
self.waf_options = sys.argv

# Load any extra tools that define regular options for waf
self.load('wurf.waf_standalone_context')
Expand Down
2 changes: 1 addition & 1 deletion src/wurf/waf_resolve_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# To create the tree. https://gist.github.com/hrldcpr/2012250

dependency_cache = None
dependency_cache = {}
"""Dictionary that stores the dependencies resolved.
The dictionary will be initialized by the WafResolveContext and can be
Expand Down
6 changes: 3 additions & 3 deletions test/python/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_virtualenv_noname(testdirectory):
env = dict(os.environ)
name = None
ctx = mock.Mock()
ctx.bldnode.abspath = lambda: testdirectory.mkdir("build").path()
ctx.path.abspath = lambda: testdirectory.path()
log = mock.Mock()

venv = VirtualEnv.create(cwd=cwd, env=env, name=name, log=log, ctx=ctx)
Expand All @@ -29,7 +29,7 @@ def test_virtualenv_name(testdirectory):
env = dict(os.environ)
name = "gogo"
ctx = mock.Mock()
ctx.bldnode.abspath = lambda: testdirectory.mkdir("build").path()
ctx.path.abspath = lambda: testdirectory.path()
log = mock.Mock()

# Lets make the directory to make sure it is removed
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_virtualenv_system_site_packages(testdirectory):
env = dict(os.environ)
name = "gogo"
ctx = mock.Mock()
ctx.bldnode.abspath = lambda: testdirectory.mkdir("build").path()
ctx.path.abspath = lambda: testdirectory.path()
log = mock.Mock()

# Lets make the directory to make sure it is removed
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _pytest(bld):
# Make python not write any .pyc files. These may linger around
# in the file system and make some tests pass although their .py
# counter-part has been e.g. deleted
command = "python -B -m pytest test --last-failed --basetemp " + basetemp
command = "python -B -m pytest test --basetemp " + basetemp

# Conditionally disable the tests that have the "networktest" marker
if bld.options.skip_network_tests:
Expand Down

0 comments on commit 9b7ea3c

Please sign in to comment.