Skip to main content

Utility for defining then downloading and preprocessing external static files.

Project description

Build Status codecov.io PyPI Status license

Copyright (C) 2013-2017 Samuel Colvin

Kind of like bower, but in Python, and simpler, and with some more features.

grablib can:

  • download files from urls, including extracting selectively from zip files.

  • create .grablib.lock which retains hashes of all downloaded files meaning assets can’t change unexpectedly.

  • compile sass/scss/css using libsass.

  • concatenate and minify javascript using jsmin.

Definition files can either be JSON or YAML (see examples).

Installation

grablib requires python 3.5+.

pip install grablib[build]

(You can also use simply pip install grablib to install without build requirements, this is useful when you’re not using grablib for building as it avoids installing jsmin and libsass which can be slow.)

CLI Usage

Define your static files thus: (grablib.yml)

download_root: 'static/libs'
download:
  'http://code.jquery.com/jquery-1.11.3.js': 'js/jquery.js'
  'https://github.com/twbs/bootstrap-sass/archive/v3.3.6.zip':
    'bootstrap-sass-3.3.6/assets/(.+)$': 'bootstrap-sass/'

  'GITHUB/codemirror/CodeMirror/5.8.0/lib/codemirror.js': 'codemirror/'
  # simple scss file to import and compile bootstrap from above,
  # generally this would be in your code
  # this file just reads "@import 'bootstrap-sass/stylesheets/bootstrap';"
  'https://git.io/v1Z5J': 'build_bootstrap.scss'

debug: true
build_root: 'static/prod'
build:
  # delete the entire static/prod directory before building, this is required for sass,
  # and generally safer
  wipe: '.*'
  cat:
    # concatenate jquery and codemirror into "libraries.js"
    # it won't get minified as debug is true, but without that it would
    'libraries.js':
      - 'DL/js/jquery.js'
      - 'DL/codemirror/codemirror.js'
  sass:
    # compile all css, scss and sass files which don't start with _ from the "download_root"
    # into the "css" directory, here that will just be build_bootstrap.scss which will
    # build the whole of bootstrap.
    # debug: true means you'll get map files and a copy of sass files so maps work properly.
    'css': 'DL/'

Then download and build you static files with just:

grablib

Library Usage

You can also call grablib from python:

from grablib import Grab

grab = Grab('path/to/definitions.json|yml')
grab.download()
grab.build()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grablib-0.4.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

grablib-0.4-py35+-none-any.whl (14.4 kB view details)

Uploaded Python 3.5+

File details

Details for the file grablib-0.4.tar.gz.

File metadata

  • Download URL: grablib-0.4.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for grablib-0.4.tar.gz
Algorithm Hash digest
SHA256 882a277a1c5083de9ab5f6266e03ee0b3fdcbca940e0dfe4363f723eba4a275d
MD5 d59c08b3af03f06fdc121b269b4f7e04
BLAKE2b-256 d69fe9050af3ddf2362448e23c577a6be0b36a3bd0cebdd90a8291fe86105b5b

See more details on using hashes here.

Provenance

File details

Details for the file grablib-0.4-py35+-none-any.whl.

File metadata

File hashes

Hashes for grablib-0.4-py35+-none-any.whl
Algorithm Hash digest
SHA256 c99eb9fc4b81b5cc08173092e5137c8366834b2ee7aefb1d7281fd1eb8ae62a1
MD5 2f2f71960a0d411996da326784af9898
BLAKE2b-256 f514842d7d94d3cf42e9ea73220b8265016848e52b4e9e97f189ab8a337d8b42

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page