Skip to content

Commit

Permalink
Create a python package for the webui
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos authored Dec 5, 2018
2 parents 588841b + 9ac1bf5 commit c5f557f
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[bumpversion]
current_version = 0.5.0
commit = True
tag = False

[bumpversion:file:setup.py]
serialize = {major}.{minor}.{patch}

[bumpversion:file:package.json]
parse = "version": "(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)";
serialize = {major}.{minor}.{patch}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/build
/dist
/dist-server
/raiden_webui/ui
/tmp
/out-tsc
/raiden_webui.egg-info
__pycache__


# dependencies
/node_modules
Expand Down
13 changes: 13 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prune *
recursive-include raiden_webui *.*
exclude .gitignore
exclude angular.json
exclude karma.conf.js
exclude package.json
exclude package-lock.json
exclude protractor.conf.js
exclude proxy.config.json
exclude tsconfig.json
exclude tslint.json
exclude .editorconfig
exclude .bumpversion.cfg
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Helper guide to install and test the Raiden UI
# Raiden WebUI

* Once you come in the `raiden/ui/web/` folder please run
* To install the dependencies please run.

> **npm install**.
Expand All @@ -24,7 +24,7 @@ You can read more about this [here](https://github.com/angular/angular-cli/blob/

**npm run build:prod**

It'll lay in the `dist` subfolder, and can be served directly by flask API.
It'll lay in the `raiden_webui/ui` subfolder.

* Inside the folder src/assets/config we have a config.development.json. This file contains configuration details about host port etc for the raiden as well as geth because we query both the api servers simultaneously. We need to change this file so that it can pick up details according our local configuration.
```
Expand Down Expand Up @@ -73,7 +73,44 @@ file.
```

# Raidenwebui
# WebUI python package

The WebUI can be build as a python package that can then be consumed by raiden.
The package provides a static that points to the location of the WebUI static content root directory.

The WebUI resources path can be imported in the following way:

```python
from raiden_webui import RAIDEN_WEBUI_PATH
```

You can build the python package by calling:

```bash
python setup.py build sdist bdist_wheel
```

This will call `npm build:prod` to build the static production version of the WebUI so
that it can get included in the python package.

If you need to install the package locally to your development virtual environment you can do
so by running:

```bash
python setup.py build install
```

In case you need to use the debug version of the WebUI with in your virtual environment you can also
run:

```bash
python setup.py compile_webui -D install
```

This will build the debug version of the WebUI to include in your package.


# Raiden WebUI

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.6.5.

Expand All @@ -87,7 +124,7 @@ Run `ng generate component component-name` to generate a new component. You can

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
Run `ng build` to build the project. The build artifacts will be stored in the `raiden_webui/ui` directory. Use the `-prod` flag for a production build.

## Running unit tests

Expand Down
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"outputPath": "raiden_webui/ui",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
Expand Down
3 changes: 3 additions & 0 deletions raiden_webui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

RAIDEN_WEBUI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'ui'))
117 changes: 117 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env python
import distutils.log
import os
import subprocess
from distutils.spawn import find_executable

from setuptools import Command, find_packages, setup
from distutils.command.build import build


class BuildCommand(build):

def run(self):
self.run_command('compile_webui')
build.run(self)


class CompileWebUI(Command):
description = 'use npm to compile raiden_webui'
user_options = [
('dev', 'D', 'use development preset, instead of production (default)'),
]

def initialize_options(self):
self.dev = None

def finalize_options(self):
pass

def run(self):
npm = find_executable('npm')
if not npm:
if os.environ.get('RAIDEN_NPM_MISSING_FATAL') is not None:
# Used in the automatic deployment scripts to prevent builds with missing web-ui
raise RuntimeError('NPM not found. Aborting')
self.announce(
'NPM not found. Skipping webUI compilation',
level=distutils.log.WARN, # pylint: disable=no-member
)
return
npm_run = 'build:prod'
if self.dev is not None:
npm_run = 'build:dev'

cwd = os.path.abspath(
os.path.join(
os.path.dirname(__file__)
),
)

npm_version = subprocess.check_output([npm, '--version'])
# require npm 4.x.x or later
if not int(npm_version.split(b'.')[0]) >= 4:
if os.environ.get('RAIDEN_NPM_MISSING_FATAL') is not None:
# Used in the automatic deployment scripts to prevent builds with missing web-ui
raise RuntimeError(f'NPM >= 4.0 required. Have {npm_version} from {npm}.')
self.announce(
'NPM 4.x or later required. Skipping webUI compilation',
level=distutils.log.WARN, # pylint: disable=no-member
)
return

command = [npm, 'install']
self.announce(
'Running %r in %r' % (command, cwd),
level=distutils.log.INFO, # pylint: disable=no-member
)
subprocess.check_call(command, cwd=cwd)

command = [npm, 'run', npm_run]
self.announce(
'Running %r in %r' % (command, cwd),
level=distutils.log.INFO, # pylint: disable=no-member
)
subprocess.check_call(command, cwd=cwd)

self.announce(
'WebUI compiled with success!',
level=distutils.log.INFO, # pylint: disable=no-member
)


with open('README.md', encoding='utf-8') as readme_file:
readme = readme_file.read()

history = ''

version = '0.5.0' # Do not edit: this is maintained by bumpversion (see .bumpversion.cfg)

setup(
name='raiden-webui',
description='Raiden webui',
version=version,
long_description=readme,
long_description_content_type='text/markdown',
author='Brainbot Labs Est.',
author_email='[email protected]',
url='https://github.com/raiden-network/webui',
packages=find_packages(),
include_package_data=True,
license='MIT',
zip_safe=False,
keywords='raiden webui',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English'
],
cmdclass={
'compile_webui': CompileWebUI,
'build': BuildCommand
},
use_scm_version=True,
setup_requires=['setuptools_scm'],
python_requires='>=3.6'
)

0 comments on commit c5f557f

Please sign in to comment.