Пример #1
0
 def test_directory_custom(self):
     """A custom root directory is configured."""
     self.env.load_path = [self.tempdir]
     self.create_files(['foo', 'module/bar'])
     print get_all_bundle_files(Bundle('foo'), self.env)
     assert get_all_bundle_files(Bundle('foo'), self.env) == [self.path('foo')]
     # We do not recognize references to modules.
     assert get_all_bundle_files(Bundle('module/bar'), self.env) == [self.path('module/bar')]
Пример #2
0
    def test_custom_load_path(self):
        """A custom load_path is configured - this will affect how
        we deal with source files.
        """
        self.env.append_path(self.tempdir, "/custom/")
        self.create_files(["foo", "module/bar"])
        assert get_all_bundle_files(Bundle("foo"), self.env) == [self.path("foo")]
        # We do not recognize references to modules.
        assert get_all_bundle_files(Bundle("module/bar"), self.env) == [self.path("module/bar")]

        assert Bundle("foo").urls(self.env) == ["/custom/foo"]
        assert Bundle("module/bar").urls(self.env) == ["/custom/module/bar"]
 def test_duplicate_nested_bundles_removed(self):
     nested = self.mkbundle('*.js')
     bundle = self.mkbundle(nested, nested)
     all_files = get_all_bundle_files(bundle)
     all_files.sort()
     assert all_files == [self.path('foo.js'), self.path('hubris.js'),
                          self.path('whimsy.js')]
Пример #4
0
    def test_globbed_load_path(self):
        """The load path itself can contain globs."""
        self.env.append_path(self.path('*'))
        self.create_files({'a/foo': 'a', 'b/foo': 'b', 'dir/bar': 'dir'})

        # With a non-globbed reference
        bundle = self.mkbundle('foo', output='out')
        assert set(get_all_bundle_files(bundle)) == set([
            self.path('a/foo'), self.path('b/foo')
        ])

        # With a globbed reference
        bundle = self.mkbundle('???', output='out')
        assert set(get_all_bundle_files(bundle)) == set([
            self.path('a/foo'), self.path('b/foo'), self.path('dir/bar')
        ])
Пример #5
0
def list_asset_sources(source_dir):
    """
    Returns a list of paths (relative to the given source_dir) of all asset
    sources files defined in the assets environment.
    """
    # This is called during package build, so we create a new env specially to
    # refer to the given source dir.
    # We aren't going to produce any generated files so output_dir is unused
    # and cache can be discarded.
    source_dir = os.path.abspath(source_dir)
    cache_dir = tempfile.mkdtemp(prefix='beaker-build-assets-cache')
    try:
        env = _create_env(source_dir=source_dir, output_dir='/unused',
                cache=cache_dir, debug=False, auto_build=False)
        paths = []
        for bundle in env:
            for path in get_all_bundle_files(bundle, env):
                paths.append(os.path.relpath(path, source_dir))
        # site.less should be skipped because it's a symlink
        paths.remove('site.less')
        # font-awesome is currently not managed by webassets because webassets
        # breaks on non-UTF8 input files
        paths.extend([
            'font-awesome/fonts/fontawesome-webfont.eot',
            'font-awesome/fonts/fontawesome-webfont.svg',
            'font-awesome/fonts/fontawesome-webfont.ttf',
            'font-awesome/fonts/fontawesome-webfont.woff',
        ])
        return paths
    finally:
        shutil.rmtree(cache_dir, ignore_errors=True)
Пример #6
0
    def test_custom_load_path(self):
        """A custom load_path is configured - this will affect how
        we deal with source files.
        """
        self.env.append_path(self.tempdir, '/custom/')
        self.create_files(['foo', 'module/bar'])
        assert get_all_bundle_files(Bundle('foo'), self.env) == [self.path('foo')]
        # We do not recognize references to modules.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [self.path('module/bar')]

        assert Bundle('foo').urls(self.env) == ['/custom/foo']
        assert Bundle('module/bar').urls(self.env) == ['/custom/module/bar']

        # [Regression] With a load path configured, generating output
        # urls still works, and it still uses the flask system.
        self.env.debug = False
        self.env.url_expire = False
        assert Bundle('foo', output='out').urls(self.env) == ['/app_static/out']
Пример #7
0
    def test_directory_auto(self):
        """Test how we handle file references if no root 'directory' is
        configured manually.
        """
        assert not 'directory' in self.env.config
        root = self.app.root_path
        assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
        # Modules prefixes in paths are handled specifically.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [root + '/test_module/static/bar']
        # Prefixes that aren't valid module names are just considered
        # subfolders of the main app.
        assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [root + '/static/nomodule/bar']
        # In case the name of a app-level subfolder conflicts with a
        # module name, you can always use this hack:
        assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar']

        # Custom static folder
        self.app.static_folder = '/'
        assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']
Пример #8
0
    def test_directory_auto(self):
        """Test how we handle file references if no root 'directory' is
        configured manually.
        """
        assert not 'directory' in self.env.config
        root = self.app.root_path
        assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
        # Modules prefixes in paths are handled specifically.
        assert get_all_bundle_files(Bundle('module/bar'), self.env) == [root + '/test_module/static/bar']
        # Prefixes that aren't valid module names are just considered
        # subfolders of the main app.
        assert get_all_bundle_files(Bundle('nomodule/bar'), self.env) == [root + '/static/nomodule/bar']
        # In case the name of a app-level subfolder conflicts with a
        # module name, you can always use this hack:
        assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar']

        # Custom static folder
        self.app.static_folder = '/'
        assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']
Пример #9
0
    def test(self):
        """Make sure the "url" and "directory" config values are
        read from the Flask app.
        """
        with self.app.test_request_context():
            assert not 'url' in self.env.config
            assert Bundle('foo').urls(self.env) == ['/initapp_static/foo']

            assert not 'directory' in self.env.config
            root = self.app.root_path
            assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
Пример #10
0
    def handle_start(self, app, services_service, reloader_service=None):
        self.environment.config.setdefault('url', app.static_url)

        if self.bundles and (reloader_service is not None):
            for name, bundle in self.bundles.items():
                for filename in set(get_all_bundle_files(bundle)):
                    reloader_service.watch_file(filename,
                                                on_change,
                                                o=self,
                                                method='build_on_change',
                                                bundle=name)
Пример #11
0
    def test_directory_auto(self):
        """Test how we resolve file references through the Flask static
        system by default (if no custom 'env.directory' etc. values
        have been configured manually).
        """
        assert not "directory" in self.env.config
        root = self.app.root_path
        assert get_all_bundle_files(Bundle("foo"), self.env) == [root + "/static/foo"]
        # Modules prefixes in paths are handled specifically.
        assert get_all_bundle_files(Bundle("module/bar"), self.env) == [root + "/test_module/static/bar"]
        # Prefixes that aren't valid module names are just considered
        # subfolders of the main app.
        assert get_all_bundle_files(Bundle("nomodule/bar"), self.env) == [root + "/static/nomodule/bar"]
        # In case the name of a app-level subfolder conflicts with a
        # module name, you can always use this hack:
        assert get_all_bundle_files(Bundle("./module/bar"), self.env) == [root + "/static/module/bar"]

        # Custom static folder
        self.app.static_folder = "/"
        assert get_all_bundle_files(Bundle("foo"), self.env) == ["/foo"]
Пример #12
0
    def test(self):
        """Make sure the "url" and "directory" config values are
        read from the Flask app.
        """
        with self.app.test_request_context():
            assert not "url" in self.env.config
            assert Bundle("foo").urls(self.env) == ["/initapp_static/foo"]

            assert not "directory" in self.env.config
            root = self.app.root_path
            assert get_all_bundle_files(Bundle("foo"), self.env) == [root + "/static/foo"]
Пример #13
0
    def test(self):
        """Make sure the "url" and "directory" config values are
        read from the Flask app.
        """
        with self.app.test_request_context():
            assert not 'url' in self.env.config
            assert Bundle('foo', env=self.env).urls() == ['/initapp_static/foo']

            assert not 'directory' in self.env.config
            root = self.app.root_path
            assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
Пример #14
0
    def test_custom_load_path(self):
        """A custom load_path is configured - this will affect how
        we deal with source files.
        """
        self.env.append_path(self.tempdir, '/custom/')
        self.create_files(['foo', 'module/bar'])
        assert get_all_bundle_files(Bundle('foo'),
                                    self.env) == [self.path('foo')]
        # We do not recognize references to modules.
        assert get_all_bundle_files(Bundle('module/bar'),
                                    self.env) == [self.path('module/bar')]

        assert Bundle('foo').urls(self.env) == ['/custom/foo']
        assert Bundle('module/bar').urls(self.env) == ['/custom/module/bar']

        # [Regression] With a load path configured, generating output
        # urls still works, and it still uses the flask system.
        self.env.debug = False
        self.env.url_expire = False
        assert Bundle('foo',
                      output='out').urls(self.env) == ['/app_static/out']
Пример #15
0
 def find_recent_most_timestamp(cls, bundle, env):
     # Recurse through the bundle hierarchy. Check the timestamp of all
     # the bundle source files, as well as any additional
     # dependencies that we are supposed to watch.
     most_recent = None
     for filename in get_all_bundle_files(bundle, env):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent
Пример #16
0
 def find_recent_most_timestamp(cls, bundle, env):
     # Recurse through the bundle hierarchy. Check the timestamp of all
     # the bundle source files, as well as any additional
     # dependencies that we are supposed to watch.
     most_recent = None
     for filename in get_all_bundle_files(bundle, env):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent
Пример #17
0
    def test_globbing(self):
        """When used with globbing."""
        self.env.append_path(self.path('a'))
        self.env.append_path(self.path('b'))
        self.create_files({'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'})

        # Returns all files, even duplicate relative filenames in
        # multiple load paths (foo in this case).
        bundle = self.mkbundle('*', output='out')
        assert set(get_all_bundle_files(bundle)) == set(
            [self.path('a/foo'),
             self.path('b/foo'),
             self.path('b/bar')])
Пример #18
0
    def test_globbing(self):
        """When used with globbing."""
        self.env.append_path(self.path('a'))
        self.env.append_path(self.path('b'))
        self.create_files({
            'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'})

        # Returns all files, even duplicate relative filenames in
        # multiple load paths (foo in this case).
        bundle = self.mkbundle('*', output='out')
        assert set(get_all_bundle_files(bundle)) == set([
            self.path('a/foo'), self.path('b/foo'), self.path('b/bar')
        ])
Пример #19
0
        def check_for_changes():
            changed_bundles = []
            for bundle in self.environment:
                for filename in get_all_bundle_files(bundle):
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _mtimes[filename] = mtime
                        break
                    _mtimes[filename] = mtime
            return changed_bundles
Пример #20
0
        def check_for_changes():
            changed_bundles = []
            for bundle in self.environment:
                for filename in get_all_bundle_files(bundle):
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _mtimes[filename] = mtime
                        break
                    _mtimes[filename] = mtime
            return changed_bundles
Пример #21
0
        def check_for_changes():
            # Do not update original mtimes dict right away, so that we detect
            # all bundle changes if a file is in multiple bundles.
            _new_mtimes = _mtimes.copy()

            changed_bundles = []
            for bundle in self.environment:
                for filename in get_all_bundle_files(bundle):
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _new_mtimes[filename] = mtime
                        break
                    _new_mtimes[filename] = mtime

            _mtimes.update(_new_mtimes)
            return changed_bundles
Пример #22
0
        def check_for_changes():
            # Do not update original mtimes dict right away, so that we detect
            # all bundle changes if a file is in multiple bundles.
            _new_mtimes = _mtimes.copy()

            changed_bundles = []
            for bundle in self.environment:
                for filename in get_all_bundle_files(bundle):
                    stat = os.stat(filename)
                    mtime = stat.st_mtime
                    if _win:
                        mtime -= stat.st_ctime

                    if _mtimes.get(filename, mtime) != mtime:
                        changed_bundles.append(bundle)
                        _new_mtimes[filename] = mtime
                        break
                    _new_mtimes[filename] = mtime

            _mtimes.update(_new_mtimes)
            return changed_bundles
Пример #23
0
def list_asset_sources(source_dir):
    """
    Returns a list of paths (relative to the given source_dir) of all asset
    sources files defined in the assets environment.
    """
    # This is called during package build, so we create a new env specially to
    # refer to the given source dir.
    # We aren't going to produce any generated files so output_dir is unused
    # and cache can be discarded.
    source_dir = os.path.abspath(source_dir)
    cache_dir = tempfile.mkdtemp(prefix='beaker-build-assets-cache')
    try:
        env = _create_env(source_dir=source_dir,
                          output_dir='/unused',
                          cache=cache_dir,
                          debug=False,
                          auto_build=False)
        paths = []
        for bundle in env:
            for path in get_all_bundle_files(bundle, env):
                paths.append(os.path.relpath(path, source_dir))
        # site.less should be skipped because it's a symlink
        paths.remove('site.less')
        # images and fonts are currently not managed by webassets because webassets
        # breaks on non-UTF8 input files
        paths.extend([
            'font-awesome/fonts/fontawesome-webfont.eot',
            'font-awesome/fonts/fontawesome-webfont.svg',
            'font-awesome/fonts/fontawesome-webfont.ttf',
            'font-awesome/fonts/fontawesome-webfont.woff',
            'favicon.ico',
            'favicon-16.png',
            'favicon-32.png',
            'favicon-64.png',
            'favicon-152.png',
        ])
        return paths
    finally:
        shutil.rmtree(cache_dir, ignore_errors=True)
Пример #24
0
 def yield_files_to_watch(self):
     for bundle in self.environment:
         for filename in get_all_bundle_files(bundle):
             yield filename, set([bundle])
Пример #25
0
 def test_dependencies(self):
     expected = len(glob('jarbas/frontend/elm/**/*.elm', recursive=True))
     files = set(get_all_bundle_files(elm))
     self.assertEqual(expected, len(files), files)
Пример #26
0
 def test_dependencies(self):
     files = set(get_all_bundle_files(elm))
     self.assertEqual(9, len(files), files)
Пример #27
0
 def test_directory_custom(self):
     """A custom root directory is configured."""
     self.env.directory = '/tmp'
     assert get_all_bundle_files(Bundle('foo'), self.env) == ['/tmp/foo']
     # We do not recognize references to modules.
     assert get_all_bundle_files(Bundle('module/bar'), self.env) == ['/tmp/module/bar']
Пример #28
0
 def test_do_not_glob_directories(self):
     """[Regression] Glob should be smart enough not to pick
     up directories."""
     self.create_directories('subdir')
     assert not [s for s in get_all_bundle_files(self.mkbundle('*')) if 'subdir' in s]
Пример #29
0
 def test_glob_exclude_output(self):
     """Never include the output file in the globbinb result.
     """
     self.create_files(['out.js'])
     assert not [s for s in get_all_bundle_files(self.mkbundle('*', output='out.js')) if 'out.js' in s]
Пример #30
0
 def test_glob_exclude_output(self):
     """Never include the output file in the globbinb result.
     """
     self.create_files(['out.js'])
     assert not list(filter(lambda s: 'out.js' in s,
         get_all_bundle_files(self.mkbundle('*', output='out.js'))))
Пример #31
0
 def test_do_not_glob_directories(self):
     """[Regression] Glob should be smart enough not to pick
     up directories."""
     self.create_directories('subdir')
     assert not list(filter(lambda s: 'subdir' in s,
                        get_all_bundle_files(self.mkbundle('*'))))
Пример #32
0
 def yield_files_to_watch(self):
     for bundle in self.environment:
         for filename in get_all_bundle_files(bundle):
             yield filename, set([bundle])
Пример #33
0
 def test_do_not_glob_directories(self):
     """[Regression] Glob should be smart enough not to pick
     up directories."""
     self.create_directories('subdir')
     assert not filter(lambda s: 'subdir' in s,
                       get_all_bundle_files(self.mkbundle('*')))