Node.py
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.
Installation
$ pip install nodepy-runtime[nppm]
Usage Example
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"
}
}Troubleshooting
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]
Changes
v2.1.6
- Fix duplicate execution of code specified with the
-coption - Add
namespace <name>:declaration concept (nodepy.extensions.NamespaceSyntax) - Create a
package.yamlfile for the Pliz setupfiles renderer - Deliver NPPM as part of Node.py
v2.1.5 (2018-08-18)
- Add
Request.copy()method
v2.1.4 (2018-08-13)
- Handle relative package links (actually already in 2.1.3)
v2.1.3 (2018-08-13)
- Fix
PythonLoader.suggest_files(), no longer replaces an existing suffix when trying to add.pysuffix
v2.1.2 (2018-06-15)
- Fix
MANIFEST.inwhich now includesrequirements.txt(required bysetup.py)
v2.1.1 (2018-06-14)
- Release date fix for v2.1.0
v2.1.0 (2018-06-14)
- Rename
nodepy-pmtonppminREADME.md - Add MIT license to the header of all source files
v2.0.3 (2018-06-03)
- The
nodepy.base.Module()constructor now accepts absolute filenames only - Update
setup.pyto include Markdownlong_descriptionand read install requirements fromrequirements.txt
v2.0.2 (2018-03-30)
- The local
.nodepy/pipdirectory is now always added tosys.pathby using theEntryModule.run_with_exec_handler()method instead of loading and executing the module directly PythonLoader.load()no longer adds tosys.pathif the path already is in the list
v2.0.1 (2017-12-19)
PythonLoader._load_code()now uses utf8 encoding by default, however we should try to peek into the file to see if it contains a coding: comment- Always add local
modules_directoryto Context resolve path, this helps projects that use package links - Node.py repl can now also import from
.nodepy/pipdirectory - Fix
resolve_rootoutside of package root - Don't import
pathlibfromnodepy.utils.path, but instead importpathlib2directly. We decided on not using stdpathlibif it is available, as there can be minor differences - Add missing
strict=FalsetoUrlPath.resolve()andZipPath.resolve() - Add info to
nodepy.runtime.scriptsthat it can also holds anargsmember resolve_rootnow taken into account for defaultPackage.mainif it is not explicitly defined, addresolve_rootwhen 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 containssubdir/..elements- Update
Module.nameproperty to be able to produce a requirable module name for modules outside a package'sresolve_root - Fixed comparing RequestString with actual request str in
Request.try_()to properly raise TryResolveError - Fix
FrameDebuggerparent calls for Python 2 - Add
Config.sections(), remove debug print inContext.__init__() - Remove
nodepy.default_context, but addnodepy.get_default_context()instead - Add
nodepy.utils.configmodule and addContext.configmember which is initialized from theNODEPY_CONFIGfile or~/.nodepy/config
v2.0.0 (2018-11-24)
- Complete rewrite
- Abstract module resolving interface
- Using the
pathlib2module to abstract the filesystem
Copyright © 2018 Niklas Rosenstein
