def test_watch_config_file(self): """The watch command has an eye on the config file. This is an extension to the base watch command.""" try: import yaml except ImportError: raise SkipTest() self.cmd_env = CommandLineEnvironment(self.env, logging) self.cmd_env.commands['watch'] = \ GenericArgparseImplementation.WatchCommand( self.cmd_env, argparse.Namespace(config=self.path('config.yml'))) self.create_files({'in': 'foo'}) template = """ directory: . bundles: foo: contents: - in output: %s """ self.create_files({'config.yml': template % 'outA'}) with self: time.sleep(0.1) # Change the config file; this change is detected; we update # the timestamp explicitly or we might not have enough precision self.create_files({'config.yml': template % 'outB'}) self.setmtime('config.yml', mod=100) time.sleep(0.2) # The second output file has been built assert self.get('outB') == 'foo'
def main(): log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) call(["coffee", "-c", "src/tambur.coffee"]) call(["coffee", "-c", "src/tambur_publisher.coffee"]) env = Environment('.', '/static') jsonjs = Bundle( 'deps/json2.js', filters='yui_js', output='out/json2.min.js') sockjs = Bundle( 'deps/web_socket.js', filters='yui_js', output='out/web_socket.min.js') tamburjs = Bundle( 'deps/swfobject.js', 'src/tambur.js', output='out/tambur.js') tamburminjs = Bundle( 'deps/swfobject.js', 'src/tambur.js', filters='yui_js', output='out/tambur.min.js') publishjs = Bundle( 'deps/sha1.js', 'deps/oauth.js', 'src/tambur_publisher.js', output='out/tambur_pub.js') publishminjs = Bundle( 'deps/sha1.js', 'deps/oauth.js', 'src/tambur_publisher.js', filters='yui_js', output='out/tambur_pub.min.js') env.register('tambur.js', tamburjs) env.register('tambur.min.js', tamburminjs) env.register('tambur_pub.js', publishjs) env.register('tambur_pub.min.js', publishminjs) env.register('json2.js', jsonjs) env.register('web_socket.js', sockjs) cmdenv = CommandLineEnvironment(env, log) cmdenv.build()
def action(rebuild=False, watch=False, check=False, clean=False, quiet=('q', False), verbose=('v', False)): if len(filter(bool, [rebuild, watch, clean, check])) != 1: print "Error: exactly one of --rebuild, --watch, --check or --clean must be given" return 1 if rebuild: command = 'rebuild' elif watch: command = 'watch' elif clean: command = 'clean' elif check: command = 'check' log.setLevel(logging.DEBUG if verbose else ( logging.WARNING if quiet else logging.INFO)) cmdenv = CommandLineEnvironment(environment, log) if loaders: log.info('Finding bundles...') for loader in loaders: environment.add( *[b for b in loader.load_bundles() if not b.is_container]) cmdenv.invoke(command)
def run(self): from webassets import Bundle from webassets import Environment from webassets.script import CommandLineEnvironment css = Bundle('curious/src/css/app.css', output='curious/dist/curious.css') js = Bundle('curious/src/js/*.js', output='curious/dist/curious.js') jsm = Bundle('curious/src/js/*.js', filters='jsmin', output='curious/dist/curious.min.js') jst = Bundle('curious/src/html/*.html', filters='jst', output='curious/dist/curious_jst.js') assets_env = Environment('./curious/static') assets_env.cache = self.cache_dir assets_env.register('css', css) assets_env.register('js', js) assets_env.register('jsmin', jsm) assets_env.register('jst', jst) log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
def handle(self, *args, **options): valid_commands = CommandLineEnvironment.Commands if len(args) > 1: raise CommandError('Invalid number of subcommands passed: %s' % ", ".join(args)) elif len(args) == 0: raise CommandError('You need to specify a subcommand: %s' % ', '.join(valid_commands)) # Create log log = logging.getLogger('django-assets') log.setLevel({0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG}[int(options.get('verbosity', 1))]) log.addHandler(logging.StreamHandler()) # If the user requested it, search for bundles defined in templates if options.get('parse_templates'): log.info('Searching templates...') # Note that we exclude container bundles. By their very nature, # they are guaranteed to have been created by solely referencing # other bundles which are already registered. get_env().add(*[b for b in self.load_from_templates() if not b.is_container]) if len(get_env()) == 0: raise CommandError('No asset bundles were found. ' 'If you are defining assets directly within your ' 'templates, you want to use the --parse-templates ' 'option.') # Execute the requested subcommand cmd = CommandLineEnvironment(get_env(), log) try: cmd.invoke(args[0]) except AssetCommandError, e: raise CommandError(e)
def _build_webassets(self): # Set up a logger log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(self.webassets_env, log) cmdenv.build()
def build_assets(): log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
def build_assets(app): from webassets.script import CommandLineEnvironment assets_env = app.jinja_env.assets_environment log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build()
def _webassets_cmd(cmd): """Helper to run a webassets command.""" from webassets.script import CommandLineEnvironment logger = logging.getLogger('webassets') logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment( current_app.jinja_env.assets_environment, logger) getattr(cmdenv, cmd)()
def run(self): assets_env = get_webassets_env({ 'debug': False, 'static_files_dir': STATIC, }) cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build() self.copy_assets()
def build(silent=False): """ Build the static Files""" env = current_app.jinja_env.assets_environment cmd = CommandLineEnvironment(env, log) directory = env.get_directory() mybuild = BuildCommand(cmd) mybuild(directory=directory)
def clear_css_cache(): import logging from webassets.script import CommandLineEnvironment # Setup a logger log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets, log) cmdenv.clean()
def test_watch_with_fixed_env_and_no_config(self): """[Regression[ The custom 'watch' command does not break if the CLI is initialized via fixed environment, instead of reading one from a configuration file. """ self.cmd_env = CommandLineEnvironment(self.env, logging) self.cmd_env.commands['watch'] = \ GenericArgparseImplementation.WatchCommand( self.cmd_env, argparse.Namespace()) with self: time.sleep(0.1)
def gen_static(): # Setup a logger log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) assets_env = Environment() assets_env.directory = "static/" assets_env.debug = True assets_env.register(bundles) cmdenv = CommandLineEnvironment(assets_env, log) # This would also work cmdenv.build()
def scss_compile(static_path): webassets = Environment() webassets.directory = static_path webassets.url = static_path webassets.register('css_all', css_all) #webassets.manifest = 'cache' if not app.debug else False webassets.manifest = False webassets.cache = False webassets.debug = False log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(webassets, log) # This would also work cmdenv.build()
def init_app(app): """ Initilize assets. :param app: """ if app.debug: webassets = Environment(app) webassets.url = app.static_url_path webassets.register('css_all', css_all) webassets.manifest = False webassets.cache = False webassets.debug = False webassets.cache = not app.debug webassets.debug = app.debug log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(webassets, log) cmdenv.build()
def static(path, no_input): '''Compile and collect static files into path''' log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets, log) cmdenv.build() if exists(path): warning('{0} directory already exists and will be {1}', white(path), white('erased')) if not no_input and not click.confirm('Are you sure'): exit_with_error() shutil.rmtree(path) echo('Copying assets into {0}', white(path)) shutil.copytree(assets.directory, path) success('Done')
def static(path, input): '''Compile and collect static files''' log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets, log) cmdenv.build() if exists(path): print('"{0}" directory already exists and will be erased'.format(path)) if input and not prompt_bool('Are you sure'): exit(-1) shutil.rmtree(path) print('Copying assets into "{0}"'.format(path)) shutil.copytree(assets.directory, path) print('Done')
def bundle(**kwargs): """ Webassets bundle management. usage: blueberrypy bundle [options] Before you can use this command to bundle up your Web assets, you should have created either a project skeleton using the 'create' command or provided a configuration directory using the global option -c --config_dir. options: -h, --help show this help message and exit -C ENV_VAR_NAME, --env-var ENV_VAR_NAME add the given config from environment variable name [default: BLUEBERRYPY_CONFIG] -b, --build build the asset bundles -w, --watch automatically rebuild the asset bundles upon changes in the static directory -c, --clean delete the generated asset bundles """ config = BlueberryPyConfiguration(config_dir=kwargs.get('config_dir'), env_var_name=kwargs.get('env_var')) assets_env = config.webassets_env if not assets_env: raise BlueberryPyNotConfiguredError("Webassets configuration not found.") from webassets.script import CommandLineEnvironment assets_cli = CommandLineEnvironment(assets_env, logger) if kwargs.get("build"): try: assets_cli.build() except AttributeError: assets_cli.rebuild() elif kwargs.get("watch"): assets_cli.watch() elif kwargs.get("clean"): assets_cli.clean()
def build(): '''Compile static files''' log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) # Override some local config current_app.config['DEBUG'] = False current_app.config['ASSETS_DEBUG'] = False current_app.config['REQUIREJS_RUN_IN_DEBUG'] = True cmdenv = CommandLineEnvironment(theme.assets, log) cmdenv.build(production=True) print('Performing require.js optimization') buildfile = join(theme.assets.directory, 'js', 'app.build.js') # bust = 'pragmas.bust={0}'.format(time.time()) params = ['r.js', '-o', buildfile] subprocess.call(params) print('Done')
def _init_webassets(debug=False, generate=False): assets_env = Environment(directory=SITE_ASSET_DIR, url=SITE_ASSET_URL_PREFIX, cache=WEBASSETS_CACHE_DIR, load_path=[SITE_ASSET_SRC_DIR]) assets_env.debug = debug js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js') css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css') assets_env.register('app_js', js) assets_env.register('app_css', css) cmd = CommandLineEnvironment(assets_env, log) if generate: cmd.build() return assets_env Process(target=lambda: cmd.watch()).start() return assets_env
def build_assets(): from webassets.script import CommandLineEnvironment CommandLineEnvironment(env, assets_logger).build()
def build_assets(): CommandLineEnvironment(assets_env, logger).build()
def assets_(): CommandLineEnvironment(assets, getLogger('flask')).build()
'js/app.js', filters='uglifyjs', output='js/electris-footer.min.js') css = Bundle('bootstrap/css/bootstrap.min.css', 'bootstrap/css/bootstrap-responsive.min.css', 'css/template.css', 'css/app.css', 'css/sponsorship.css', filters='yui_css', output='css/electris.min.css') static.register('js_header', header_js) static.register('js_footer', footer_js) static.register('css', css) header_js.urls() footer_js.urls() css.urls() import logging from webassets.script import CommandLineEnvironment # Setup a logger log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(static, log) cmdenv.watch()
import logging from os import makedirs, path from webassets.script import CommandLineEnvironment from cunhajacaiu import assets from cunhajacaiu.settings import STATIC_PATH for dir in ('css', 'js'): makedirs(path.join(path.abspath(STATIC_PATH), dir), exist_ok=True) log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cli = CommandLineEnvironment(assets, log) cli.build()
def setup(self): self.assets_env = Environment('', '') self.cmd_env = CommandLineEnvironment(self.assets_env, logging)
def watch(debug=False, cache=False): env = _setup_env(debug, cache) log = _load_logger() cmdenv = CommandLineEnvironment(env, log) cmdenv.watch()
def setup(self): super(TestCLI, self).setup() self.assets_env = self.env self.cmd_env = CommandLineEnvironment(self.assets_env, logging)
def compile(): """Compile assets.""" log = logging.getLogger(__name__) cmd = CommandLineEnvironment(get_env(), log) cmd.build()