django-npm-finder


Namedjango-npm-finder JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/deeprave/django-npm-finder
SummaryA django staticfiles finder that supporting npm/yarn/pnpm
upload_time2024-07-16 02:18:16
maintainerNone
docs_urlNone
authorDavid Nugent
requires_python<4.0,>=3.10
licenseMIT
keywords django npm finder staticfiles
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-npm-finder

Want to use npm modules in your django project without vendoring them?
`django-npm-finder` serves as a wrapper around the npm/yarn/pnpm cli and provides a staticfiles
finder that provides integration of your installed node_modules during development and hooks to
selectively provide `collectstatic` functionality to export static files for production without
exposing the entire node_modules hierarchy.

`django-npm-finder` is a fork of kevin1024's [django-npm](https://github.com/keven1024/django-npm) module with the
following changes:

- modern `pyproject.toml` packaging (poetry)
- caching of searches to provide better performance
- much of the core refactored to be more robust and predictable
- added support for alternative node managers, such as yarn and pnpm.
- autoconfigure default match patterns from `package.json` dependencies
- added an extensive list of default ignore patterns
- unit tests were added (pytest)

These changes make the module easier to use, more reliable and as autoconfiguring as possible.

## Installation

- Install into your django project

```
  $ pip install django-npm-finder
```

```
  $ poetry add django-npm-finder
```

```
  $ uv pip install django-npm-finder
```

- Install npm, yarn or pnpm.
  If you use a private registry, make sure your `.npmrc` or equivalent is set up to connect to it.


- Have a `package.json` at the root of your project (can be configured), listing your dependencies.


- Add `django_npm.finders.NpmFinder` to `STATICFILES_FINDERS`


- Configure your `settings.py` as detailed in the following section [Configuration](#configuration)


- Run `$ ./manage.py npm_install` from the command line, or with your own Python code
(see npm install section below).
Or install your npm modules using `[p]npm|yarn install` from the command line.


- `$ ./manage.py collectstatic` will copy all selected node_modules files into your `STATIC_ROOT`.
   This is only required at deployment, and if using Django runserver for development, will not be required.

## Configuration

In the following section, reference to `npm` also includes `yarn` or `pnpm`.

* `NPM_ROOT_PATH`: path to the npm "root" directory, where your package manager will look
  for `package.json`, `node_modules`, `.npmrc` etc.
  Set this if it differs from the root of your Django project
  (usually `settings.BASE_DIR` in most Django projects).


* `NPM_EXECUTABLE_PATH`: (optional, default manager) sets `npm` as modules manager and optionally
  overrides its location.
  Supported NPM managers are: npm, yarn and pnpm.


* `NPM_STATIC_FILES_PREFIX`: (optional) Your npm files will be located under this path inside the
  static URL.
  As an example, if set to 'vendor' the collected files will be located in
  `/static/vendor/dist/bootstrap.min.js`, and if not set, it will be located in
  `/static/dist/bootstrap.min.js`.


* `NPM_FILE_PATTERNS`: (optional) By default, django-npm will expose all modules defined as dependencies
  in `package.json` to Django as staticfiles, excluding files using the default or specified ignore patterns.
  You may want to restrict what is exposed.
  You can pick specific files by adding some additional configuration shown in the following code block.
  Keys are the names of the npm modules, and values are lists containing strings. The strings match against glob patterns.
  Use double asterisk wildcard '**' to include all subdirectories.
  > **NOTE**: If unset, the module will autoconfigure modules based on the
  > dependencies specified in `package.json`.
```python
NPM_FILE_PATTERNS = {
    'bootstrap': ['dist/*'],
    'htmx.org': ['htmx.org/dist/*']
}
```

* `NPM_IGNORE_PATTERNS`: (optional) This is a python list of patterns to exclude.
  There is an extensive list of default patterns that are excluded, but you can override this.


* `NPM_FINDER_USE_CACHE`: (default True) A boolean that enables cache in the finder.
  If enabled, the file list will be computed only once when the server is started.


## npm install

To add the `./manage.py npm_install` "django_npm" must be added to Django's `INSTALLED_APPS` setting, otherwise it doesn't need to be added there.

Even if the module is not added in `INSTALLED_APPS` you can run `npm install` programmatically
from python by creating a script as follows:

```python
from django_npm.finders import npm_install

npm_install()
```

The advantage of using `npm_install` is that it will run the package manager configured in
your Django settings.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deeprave/django-npm-finder",
    "name": "django-npm-finder",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "django, npm, finder, staticfiles",
    "author": "David Nugent",
    "author_email": "davidn@uniquode.io",
    "download_url": "https://files.pythonhosted.org/packages/b7/e2/68b2ac565468a28263e51837418e2dba69627a24dfa2ba73fa7d280dc5e0/django_npm_finder-1.0.1.tar.gz",
    "platform": null,
    "description": "# django-npm-finder\n\nWant to use npm modules in your django project without vendoring them?\n`django-npm-finder` serves as a wrapper around the npm/yarn/pnpm cli and provides a staticfiles\nfinder that provides integration of your installed node_modules during development and hooks to\nselectively provide `collectstatic` functionality to export static files for production without\nexposing the entire node_modules hierarchy.\n\n`django-npm-finder` is a fork of kevin1024's [django-npm](https://github.com/keven1024/django-npm) module with the\nfollowing changes:\n\n- modern `pyproject.toml` packaging (poetry)\n- caching of searches to provide better performance\n- much of the core refactored to be more robust and predictable\n- added support for alternative node managers, such as yarn and pnpm.\n- autoconfigure default match patterns from `package.json` dependencies\n- added an extensive list of default ignore patterns\n- unit tests were added (pytest)\n\nThese changes make the module easier to use, more reliable and as autoconfiguring as possible.\n\n## Installation\n\n- Install into your django project\n\n```\n  $ pip install django-npm-finder\n```\n\n```\n  $ poetry add django-npm-finder\n```\n\n```\n  $ uv pip install django-npm-finder\n```\n\n- Install npm, yarn or pnpm.\n  If you use a private registry, make sure your `.npmrc` or equivalent is set up to connect to it.\n\n\n- Have a `package.json` at the root of your project (can be configured), listing your dependencies.\n\n\n- Add `django_npm.finders.NpmFinder` to `STATICFILES_FINDERS`\n\n\n- Configure your `settings.py` as detailed in the following section [Configuration](#configuration)\n\n\n- Run `$ ./manage.py npm_install` from the command line, or with your own Python code\n(see npm install section below).\nOr install your npm modules using `[p]npm|yarn install` from the command line.\n\n\n- `$ ./manage.py collectstatic` will copy all selected node_modules files into your `STATIC_ROOT`.\n   This is only required at deployment, and if using Django runserver for development, will not be required.\n\n## Configuration\n\nIn the following section, reference to `npm` also includes `yarn` or `pnpm`.\n\n* `NPM_ROOT_PATH`: path to the npm \"root\" directory, where your package manager will look\n  for `package.json`, `node_modules`, `.npmrc` etc.\n  Set this if it differs from the root of your Django project\n  (usually `settings.BASE_DIR` in most Django projects).\n\n\n* `NPM_EXECUTABLE_PATH`: (optional, default manager) sets `npm` as modules manager and optionally\n  overrides its location.\n  Supported NPM managers are: npm, yarn and pnpm.\n\n\n* `NPM_STATIC_FILES_PREFIX`: (optional) Your npm files will be located under this path inside the\n  static URL.\n  As an example, if set to 'vendor' the collected files will be located in\n  `/static/vendor/dist/bootstrap.min.js`, and if not set, it will be located in\n  `/static/dist/bootstrap.min.js`.\n\n\n* `NPM_FILE_PATTERNS`: (optional) By default, django-npm will expose all modules defined as dependencies\n  in `package.json` to Django as staticfiles, excluding files using the default or specified ignore patterns.\n  You may want to restrict what is exposed.\n  You can pick specific files by adding some additional configuration shown in the following code block.\n  Keys are the names of the npm modules, and values are lists containing strings. The strings match against glob patterns.\n  Use double asterisk wildcard '**' to include all subdirectories.\n  > **NOTE**: If unset, the module will autoconfigure modules based on the\n  > dependencies specified in `package.json`.\n```python\nNPM_FILE_PATTERNS = {\n    'bootstrap': ['dist/*'],\n    'htmx.org': ['htmx.org/dist/*']\n}\n```\n\n* `NPM_IGNORE_PATTERNS`: (optional) This is a python list of patterns to exclude.\n  There is an extensive list of default patterns that are excluded, but you can override this.\n\n\n* `NPM_FINDER_USE_CACHE`: (default True) A boolean that enables cache in the finder.\n  If enabled, the file list will be computed only once when the server is started.\n\n\n## npm install\n\nTo add the `./manage.py npm_install` \"django_npm\" must be added to Django's `INSTALLED_APPS` setting, otherwise it doesn't need to be added there.\n\nEven if the module is not added in `INSTALLED_APPS` you can run `npm install` programmatically\nfrom python by creating a script as follows:\n\n```python\nfrom django_npm.finders import npm_install\n\nnpm_install()\n```\n\nThe advantage of using `npm_install` is that it will run the package manager configured in\nyour Django settings.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A django staticfiles finder that supporting npm/yarn/pnpm",
    "version": "1.0.1",
    "project_urls": {
        "Documentation": "https://github.com/deeprave/django-npm-finder",
        "Homepage": "https://github.com/deeprave/django-npm-finder",
        "Repository": "https://github.com/deeprave/django-npm-finder"
    },
    "split_keywords": [
        "django",
        " npm",
        " finder",
        " staticfiles"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df7acbed86db3b150b2860cf8976c924a6c29d295cd65b3960ca2c856b359539",
                "md5": "c27ac553a4b33f8a3c1a41fdc5e2fd96",
                "sha256": "3f9fbd9b594c252cdd786ac85dad368f6c269bc1c1417cbab19e3ecefa4fae28"
            },
            "downloads": -1,
            "filename": "django_npm_finder-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c27ac553a4b33f8a3c1a41fdc5e2fd96",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 7563,
            "upload_time": "2024-07-16T02:18:14",
            "upload_time_iso_8601": "2024-07-16T02:18:14.641117Z",
            "url": "https://files.pythonhosted.org/packages/df/7a/cbed86db3b150b2860cf8976c924a6c29d295cd65b3960ca2c856b359539/django_npm_finder-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7e268b2ac565468a28263e51837418e2dba69627a24dfa2ba73fa7d280dc5e0",
                "md5": "874c9d675c50d29dd7b96badad037992",
                "sha256": "4308b13d7078c517d7df2e7ce36cf12dcfe1269f8bc17dcf5395af770e040f02"
            },
            "downloads": -1,
            "filename": "django_npm_finder-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "874c9d675c50d29dd7b96badad037992",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 6469,
            "upload_time": "2024-07-16T02:18:16",
            "upload_time_iso_8601": "2024-07-16T02:18:16.419478Z",
            "url": "https://files.pythonhosted.org/packages/b7/e2/68b2ac565468a28263e51837418e2dba69627a24dfa2ba73fa7d280dc5e0/django_npm_finder-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-16 02:18:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deeprave",
    "github_project": "django-npm-finder",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-npm-finder"
}
        
Elapsed time: 4.06664s