A Node.js-like runtime for Python.
Node.py is a Python runtime and package manager compatible with CPython 2.7 and 3.3 – 3.6. It provides a separate import mechanism for modules inspired by Node.js, bringing dependency management and ease of deployment for Python applications up to par with other languages without virtual environments.
Node.py comes with a built-in package manager that builds on Pip for standard
Python dependencies but also adds the capability to install packages that are
specifically developed for Node.py. To install the dependencies of the
package manager you must specify the [pm]
install extra.
Node.py is inspired by Node.js.
$ pip install nodepy-runtime[nppm]
Node.py allows you to write very modular Python applications with module import semantics that are more easily trackable. From a language standpoint, it is a superset of standard Python. It provides some syntactic sugar as well as additional built-ins for scripts loaded with Node.py
Built-in | Description |
---|---|
require |
An instance of the Require class created specificially your module. Allows you to load other modules like require('./module') |
module |
The PythonModule object that represents your Node.py module. |
Concept | Description |
---|---|
if require.main == module: |
The Node.py way of saying if __name__ == '__main__': . |
import <...> from '<module-name>' |
Syntactic sugar for the require() built-in function. |
namespace <name>: |
Similar to a class declaration, but a module is created instead. |
Example script
import flask
import sys
import cli from './cli'
require('werkzeug-reloader-patch').install()
app = flask.Flask('myapp')
import './models'
if require.main == module:
sys.exit(cli.main())
Example nodepy.json
{
"name": "myapp",
"pip_dependencies": {
"Flask": ">=1.0.2",
"pony": ">=0.7.3"
},
"dependencies": {
"werkzeug-reloader-patch": "^0.0.7"
}
}
FileNotFoundError: No such file or directory: '...\installed-files.txt'
This is a bug that will be fixed with Pip 9.0.2.
In the meantime, to fix this issues, ensure that you have the wheel
package
installed.
pip3 install wheel [--user]
-c
optionnamespace <name>:
declaration concept (nodepy.extensions.NamespaceSyntax
)package.yaml
file for the Pliz setupfiles rendererRequest.copy()
methodPythonLoader.suggest_files()
, no longer replaces an existing suffix
when trying to add .py
suffixMANIFEST.in
which now includes requirements.txt
(required by setup.py
)nodepy-pm
to nppm
in README.md
nodepy.base.Module()
constructor now accepts absolute filenames onlysetup.py
to include Markdown long_description
and read install
requirements from requirements.txt
.nodepy/pip
directory is now always added to sys.path
by using
the EntryModule.run_with_exec_handler()
method instead of loading
and executing the module directlyPythonLoader.load()
no longer adds to sys.path
if the path already is
in the listPythonLoader._load_code()
now uses utf8 encoding by default, however we
should try to peek into the file to see if it contains a coding: commentmodules_directory
to Context resolve path, this helps
projects that use package links.nodepy/pip
directoryresolve_root
outside of package rootpathlib
from nodepy.utils.path
, but instead import
pathlib2
directly. We decided on not using std pathlib
if it is
available, as there can be minor differencesstrict=False
to UrlPath.resolve()
and ZipPath.resolve()
nodepy.runtime.scripts
that it can also holds an args
memberresolve_root
now taken into account for default Package.main
if it is
not explicitly defined, add resolve_root
when package entry point is requiredStdResolver.package_for_directory()
must resolve the path to eliminate
pardir elements, otherwise we can end up with two Packages pointing to the
same directory, but one contains subdir/..
elementsModule.name
property to be able to produce a requirable module name
for modules outside a package's resolve_root
Request.try_()
to properly raise TryResolveErrorFrameDebugger
parent calls for Python 2Config.sections()
, remove debug print in Context.__init__()
nodepy.default_context
, but add nodepy.get_default_context()
insteadnodepy.utils.config
module and add Context.config
member which is
initialized from the NODEPY_CONFIG
file or ~/.nodepy/config
pathlib2
module to abstract the filesystemCopyright © 2018 Niklas Rosenstein