dartpip 0.2.8
dartpip: ^0.2.8 copied to clipboard
Add Python modules (packages) to your Dart or Flutter project. Like `pip`, but for Dart, heavily inspired by the `pub` command.
dartpip #
Like pip, but for Dart, heavily inspired by the pub command.
Add Python modules (packages) to your Dart or Flutter project.
Then use them in your Dart code via python_ffi
and python_ffi_dart.
Table of Contents #
Getting Started #
Installation #
Install dartpip as a global package
via pub.dev so it can be used from anywhere on your
system:
$ dart pub global activate dartpip
Alternatively add dartpip as a dev-dependency for the current project only:
$ dart pub add --dev dartpip
$ flutter pub add --dev dartpip
Usage #
To add a python dependency to your Dart / Flutter project simply enter the following command:
$ dartpip install <package>
If you installed dartpip as a dev-dependency, you can run it via dart run / flutter run:
$ dart run dartpip install <package>
$ flutter run dartpip install <package>
You may specify multiple dependencies at once:
$ dartpip install <package1> <package2> <package3>
Or specifying no package at all will install all dependencies specified in pubspec.yaml:
$ dartpip install
See below on how to manually declare Python dependencies in pubspec.yaml.
Manually declare Python dependencies
Add any pure Python module as a dependency to your pubspec.yaml. To do this, create a new
top-level key 'python_ffi' with subkey 'modules':
python_ffi:
modules:
json_parser: any
You do not need to specify submodules separately. dartpip will automatically detect them.
Note: The specified version has no effect at the moment. You can specify 'any' or any other
value. Using 'any' is recommended, since it will work with future versions of dartpip.
Using local dependencies not uploaded to PyPI
Instead of declaring a module by its name and version constraint (or any), you can also specify a
dependency to a local directory. This is called a path-dependency.
python_ffi:
modules:
my_module:
path: /path/to/my/module
You may specify a relative or absolute path. If your path contains special characters, it is advantageous to enclose the path in quotes.
Add sources for all Python dependencies
Note: This is not needed when using dartpip install.
Click to expand
Put the source files for all Python modules you specified in pubspec.yaml in a single directory.
You may create subdirectories for Python modules with more than one source file. The directory
structure will be mostly preserved when bundling the Python modules.
Be sure to also add the source files for all submodules of the Python modules you specified in
pubspec.yaml. dartpip will automatically detect them, if they are in this directory.
For example such a source directory could look like this:
python-modules/
├── json_parser/
│ ├── __init__.py
│ ├── json_parser.py
│ ├── json_parser_test.py
│ └── LICENSE.TXT
├── liblax/
│ ├── __init__.py
│ ├── lexer.py
│ ├── LICENSE.TXT
│ └── parser/
│ ├── __init__.py
│ └── src.py
└── structs.py
Here liblax.parser is a submodule that will be automatically included.
Bundle Python dependencies
Note: This is not needed when using dartpip install.
Click to expand
Run the bundle command to bundle all Python dependencies for the current Dart / Flutter project:
$ dartpip bundle -r <app-root> -m <python-modules-root>
<app-root> is the root directory of the Dart / Flutter application, i.e. the directory containing
the pubspec.yaml file. <python-modules-root> is the root directory for the Python module
sources. Specify the directory of the previous step.
Note: The bundle command and steps above have been replaced by the install command
Commands #
bundle #
Bundles all Python modules specified in pubspec.yaml for a Dart / Flutter application.
What will happen?
- The
pubspec.yamlfile will be parsed and all Python modules will be collected. Python modules are specified in thepython_ffisection. - The Python modules will be collected from the directory specified in the
python-modules-rootoption. - For Flutter projects, the Python modules will be copied to the
python-modulesdirectory and added to theassetssection of thepubspec.yamlfile. For Dart projects, the Python modules will be embedded into a singlepython_modules.g.dartfile and added to thelibdirectory. - For Flutter projects, all added Python modules will be registered to a
modules.jsonfile within thepython-modulesdirectory, and added to theassetssection of thepubspec.yamlfile. This allows for seamless integration with thepython_ffipackage. For Dart projects, all added Python modules will be registered to thepython_modules.g.dartfile within thelibdirectory. This file includes aMapof all Python modules and their sources encoded in a Dart constant to be used seamlessly by thepython_ffi_dartpackage.
Usage
Bundles all Python modules specified in pubspec.yaml for a Dart application.
Usage: dartpip bundle [arguments]
-h, --help Print this usage information.
-r, --app-root (mandatory)
-m, --python-modules-root (mandatory)
Run "dartpip help" to see global options.
Options
| Option | Abbreviation | Description |
|---|---|---|
--app-root |
-r |
The root directory of the Dart / Flutter application. |
--python-modules-root |
-m |
The root directory for the Python module sources. |
bundle-module #
Bundles a Python module into a Dart application.
What will happen?
Same as bundle, but only for a single Python module.
Usage
Bundles a Python module into a Dart application.
Usage: dartpip bundle-module [arguments]
-h, --help Print this usage information.
-r, --app-root (mandatory)
-m, --python-module (mandatory)
-t, --app-type [flutter (default), console]
Run "dartpip help" to see global options.
Options
| Option | Abbreviation | Description |
|---|---|---|
--app-root |
-r |
The root directory of the Dart / Flutter application. |
--python-modules-root |
-m |
The root directory for the Python module sources. |
--app-type |
-t |
The type of the Dart / Flutter application. Possible values are console and flutter. |
download #
Downloads python modules from PyPI.
What will happen?
- The
pubspec.yamlfile will be parsed and all Python modules will be collected. Python modules are specified in thepython_ffisection. - The Python modules will be collected from PyPI.
Usage
Downloads python modules from PyPI.
Usage: dartpip download [arguments]
-h, --help Print this usage information.
Run "dartpip help" to see global options.
install #
Aliases: add
Adds Python modules to the current Dart / Flutter project. They will be specified in pubspec.yaml and bundled for a Dart application.
Note: This command replaced the bundle command.
What will happen?
- The
pubspec.yamlfile will be parsed and all Python modules will be collected. Python modules are specified in thepython_ffisection. - Python modules specified in the command will be added to the
pubspec.yamlfile. - Transitive dependencies will be resolved and added to the
pubspec.yamlfile. (Note: This is implemented very naively at the moment. Version constraints are ignored.) - All Python modules will be collected from PyPI or their source directory in case of a path-dependency.
- For Flutter projects, the Python modules will be copied to the
python-modulesdirectory and added to theassetssection of thepubspec.yamlfile. For Dart projects, the Python modules will be embedded into a singlepython_modules.g.dartfile and added to thelibdirectory. - For Flutter projects, all added Python modules will be registered to a
modules.jsonfile within thepython-modulesdirectory, and added to theassetssection of thepubspec.yamlfile. This allows for seamless integration with thepython_ffipackage. For Dart projects, all added Python modules will be registered to thepython_modules.g.dartfile within thelibdirectory. This file includes aMapof all Python modules and their sources encoded in a Dart constant to be used seamlessly by thepython_ffi_dartpackage.
Usage
Adds Python modules to the current Dart / Flutter project. They will be specified in pubspec.yaml and bundled for a Dart application.
Usage: dartpip install [arguments]
-h, --help Print this usage information.
Run "dartpip help" to see global options.