dpack


Namedpack JSON
Version 0.4.2 PyPI version JSON
download
home_pagehttps://github.com/dcwatson/dpack
SummaryAsset packager for Django.
upload_time2024-04-05 13:41:48
maintainerNone
docs_urlNone
authorDan Watson
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # DPack

DPack is a static asset packager, written primarily for Django applications.

## Installation

`pip install dpack`

DPack has a number of optional processors for things like minification and compilation:

* `pip install dpack[cssmin]`
* `pip install dpack[jsmin]`
* `pip install dpack[sass]`

Or get everything with `pip install dpack[all]`.

## Configuration

DPack can be configured either via a `dpack.yaml` file, or via a `DPACK` setting if using Django. The following options
are available:

* `assets` - a dictionary whose keys are paths of files to be created (relative to `output`), and whose values are
  lists of files to process and concatenate into said file. Each input file in the list may be prefixed by one or more
  processors by specifying the processor name followed by a colon. For instance, `cssmin:sass:somefile.scss` tells
  DPack to first compile `somefile.scss` (found by searching in `search` directories) using SASS, then minify it
  using the `cssmin` processor.
* `defaults` - a dictionary whose keys are file extensions (without the `.`), and whose values are lists of
  processors to use by default for input files of that type.
* `output` - the path to store packed assets under. If not specified, this will be a temporary directory created using
  `tempfile.mkdtemp(prefix="dpack-")`.
* `prefix` - the URL prefix compiled assets will ultimately be served from, used when rewriting `url` and `@import`
  declarations in CSS files via the `rewrite` processor. If using `DPackFinder`, this defaults to `STATIC_URL`.
* `register` - a dictionary whose keys are processor names you wish to register (or override), and whose values are
  dotted-path strings that resolve to a callable. See processors below.
* `search` - a list of directories to search for input files in. If using `DPackFinder`, input files will be searches
  by using any `STATICFILES_FINDERS` that are not `DPackFinder` itself.

### Example `dpack.yaml`

```yaml
assets:
  compiled/site.css:
    - app1/first.css
    - app2/second.css
    - cssmin:sass:app3/third.scss
  compiled/site.js:
    - app1/first.js
    - app2/second.js
defaults:
  css:
    - rewrite
    - cssmin
  js:
    - jsmin
output: ./build
prefix: /static/
register:
  custom: myapp.processors.custom
search:
  - ./app1/static
  - ./app2/static
```

### Example `DPACK` Setting

```python
DPACK = {
    "assets": {
        "compiled/site.css": [
            "app1/first.css",
            "app2/second.css",
            "cssmin:sass:app3/third.scss",
        ],
        "compiled/site.js": [
            "app1/first.js",
            "app2/second.js",
        ],
    },
    "defaults": {
        "css": ["rewrite", "cssmin"],
        "js": ["jsmin"]
    },
    "output": "./build",
    "register": {
        "custom": "myapp.processors.custom"
    },
}
```

## Using DPackFinder With Django

Simply add `dpack.finders.DPackFinder` to your `STATICFILES_FINDERS` setting, and DPack will search for inputs using
Django's `staticfiles` app, output compiled assets when `collectstatic` is called, and generate assets on-the-fly when
serving with `runserver` (`DEBUG=True`) or via the `django.contrib.staticfiles.views.serve` view.

```python
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "dpack.finders.DPackFinder",
)
```

If you compile an asset to `compiled/css/site.css`, you can reference it as you would any other static asset, with
`{% static "compiled/css/site.css" %}` in your templates. These assets are also then post-processed by your
`STATICFILES_STORAGE`, so you can use things like [Whitenoise](http://whitenoise.evans.io)'s `CompressedManifestStaticFilesStorage` with no extra configuration.

## Command Line Interface

DPack comes with a command-line utility, unsurprisingly named `dpack`. Run by itself, it will look for a `dpack.yaml`
config file and pack any assets it finds according to the config. You can specify a config file (`-c`) or Django
settings module (`-s`), and dump out the loaded config using `dpack -y`. Run `dpack -h` for a full list of options.

## Processors

Processors are simply Python callables that take three arguments: `text` (the processed text so far), `input` (the
`dpack.base.Input` object containing things like relative `name` and absolute `path`), and `packer` (an instance of
`dpack.DPack` containing things like `prefix`). For example, the `cssmin` processor is implemented as:

```python
def process(text, input, packer):
    return rcssmin.cssmin(text)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dcwatson/dpack",
    "name": "dpack",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Dan Watson",
    "author_email": "dcwatson@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "# DPack\n\nDPack is a static asset packager, written primarily for Django applications.\n\n## Installation\n\n`pip install dpack`\n\nDPack has a number of optional processors for things like minification and compilation:\n\n* `pip install dpack[cssmin]`\n* `pip install dpack[jsmin]`\n* `pip install dpack[sass]`\n\nOr get everything with `pip install dpack[all]`.\n\n## Configuration\n\nDPack can be configured either via a `dpack.yaml` file, or via a `DPACK` setting if using Django. The following options\nare available:\n\n* `assets` - a dictionary whose keys are paths of files to be created (relative to `output`), and whose values are\n  lists of files to process and concatenate into said file. Each input file in the list may be prefixed by one or more\n  processors by specifying the processor name followed by a colon. For instance, `cssmin:sass:somefile.scss` tells\n  DPack to first compile `somefile.scss` (found by searching in `search` directories) using SASS, then minify it\n  using the `cssmin` processor.\n* `defaults` - a dictionary whose keys are file extensions (without the `.`), and whose values are lists of\n  processors to use by default for input files of that type.\n* `output` - the path to store packed assets under. If not specified, this will be a temporary directory created using\n  `tempfile.mkdtemp(prefix=\"dpack-\")`.\n* `prefix` - the URL prefix compiled assets will ultimately be served from, used when rewriting `url` and `@import`\n  declarations in CSS files via the `rewrite` processor. If using `DPackFinder`, this defaults to `STATIC_URL`.\n* `register` - a dictionary whose keys are processor names you wish to register (or override), and whose values are\n  dotted-path strings that resolve to a callable. See processors below.\n* `search` - a list of directories to search for input files in. If using `DPackFinder`, input files will be searches\n  by using any `STATICFILES_FINDERS` that are not `DPackFinder` itself.\n\n### Example `dpack.yaml`\n\n```yaml\nassets:\n  compiled/site.css:\n    - app1/first.css\n    - app2/second.css\n    - cssmin:sass:app3/third.scss\n  compiled/site.js:\n    - app1/first.js\n    - app2/second.js\ndefaults:\n  css:\n    - rewrite\n    - cssmin\n  js:\n    - jsmin\noutput: ./build\nprefix: /static/\nregister:\n  custom: myapp.processors.custom\nsearch:\n  - ./app1/static\n  - ./app2/static\n```\n\n### Example `DPACK` Setting\n\n```python\nDPACK = {\n    \"assets\": {\n        \"compiled/site.css\": [\n            \"app1/first.css\",\n            \"app2/second.css\",\n            \"cssmin:sass:app3/third.scss\",\n        ],\n        \"compiled/site.js\": [\n            \"app1/first.js\",\n            \"app2/second.js\",\n        ],\n    },\n    \"defaults\": {\n        \"css\": [\"rewrite\", \"cssmin\"],\n        \"js\": [\"jsmin\"]\n    },\n    \"output\": \"./build\",\n    \"register\": {\n        \"custom\": \"myapp.processors.custom\"\n    },\n}\n```\n\n## Using DPackFinder With Django\n\nSimply add `dpack.finders.DPackFinder` to your `STATICFILES_FINDERS` setting, and DPack will search for inputs using\nDjango's `staticfiles` app, output compiled assets when `collectstatic` is called, and generate assets on-the-fly when\nserving with `runserver` (`DEBUG=True`) or via the `django.contrib.staticfiles.views.serve` view.\n\n```python\nSTATICFILES_FINDERS = (\n    \"django.contrib.staticfiles.finders.FileSystemFinder\",\n    \"django.contrib.staticfiles.finders.AppDirectoriesFinder\",\n    \"dpack.finders.DPackFinder\",\n)\n```\n\nIf you compile an asset to `compiled/css/site.css`, you can reference it as you would any other static asset, with\n`{% static \"compiled/css/site.css\" %}` in your templates. These assets are also then post-processed by your\n`STATICFILES_STORAGE`, so you can use things like [Whitenoise](http://whitenoise.evans.io)'s `CompressedManifestStaticFilesStorage` with no extra configuration.\n\n## Command Line Interface\n\nDPack comes with a command-line utility, unsurprisingly named `dpack`. Run by itself, it will look for a `dpack.yaml`\nconfig file and pack any assets it finds according to the config. You can specify a config file (`-c`) or Django\nsettings module (`-s`), and dump out the loaded config using `dpack -y`. Run `dpack -h` for a full list of options.\n\n## Processors\n\nProcessors are simply Python callables that take three arguments: `text` (the processed text so far), `input` (the\n`dpack.base.Input` object containing things like relative `name` and absolute `path`), and `packer` (an instance of\n`dpack.DPack` containing things like `prefix`). For example, the `cssmin` processor is implemented as:\n\n```python\ndef process(text, input, packer):\n    return rcssmin.cssmin(text)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asset packager for Django.",
    "version": "0.4.2",
    "project_urls": {
        "Homepage": "https://github.com/dcwatson/dpack"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f29a45d12e3115667f99c6480b56b1c6f6910994df28a85846c6691b30db9fc8",
                "md5": "5547a3092a27a9c5fb513ae13982f75b",
                "sha256": "8866702b0135b363e33d97b5d42857a29cbb0ec3315d2caf2541b60f2cb2c0cc"
            },
            "downloads": -1,
            "filename": "dpack-0.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5547a3092a27a9c5fb513ae13982f75b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11484,
            "upload_time": "2024-04-05T13:41:48",
            "upload_time_iso_8601": "2024-04-05T13:41:48.528805Z",
            "url": "https://files.pythonhosted.org/packages/f2/9a/45d12e3115667f99c6480b56b1c6f6910994df28a85846c6691b30db9fc8/dpack-0.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-05 13:41:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dcwatson",
    "github_project": "dpack",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "lcname": "dpack"
}
        
Elapsed time: 0.23688s