2015-07-20 19:29:16 -04:00
# Contributing
Contributions are welcome and are greatly appreciated! Every
little bit helps, and credit will always be given.
You can contribute in many ways:
## Types of Contributions
### Report Bugs
2016-08-14 18:48:46 -04:00
Report bugs through GitHub
2015-07-20 19:29:16 -04:00
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in
troubleshooting.
- Detailed steps to reproduce the bug.
2017-06-21 13:12:34 -04:00
When you post python stack traces please quote them using
[markdown blocks ](https://help.github.com/articles/creating-and-highlighting-code-blocks/ ).
2015-07-20 19:29:16 -04:00
### Fix Bugs
Look through the GitHub issues for bugs. Anything tagged with "bug" is
open to whoever wants to implement it.
### Implement Features
Look through the GitHub issues for features. Anything tagged with
2017-06-04 21:00:33 -04:00
"feature" or "starter_task" is open to whoever wants to implement it.
2015-07-20 19:29:16 -04:00
### Documentation
2016-11-10 02:08:22 -05:00
Superset could always use better documentation,
whether as part of the official Superset docs,
2015-07-20 19:29:16 -04:00
in docstrings, `docs/*.rst` or even on the web as blog posts or
articles.
### Submit Feedback
2016-08-14 18:48:46 -04:00
The best way to send feedback is to file an issue on GitHub.
2015-07-20 19:29:16 -04:00
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to
implement.
- Remember that this is a volunteer-driven project, and that
contributions are welcome :)
2017-06-04 21:00:33 -04:00
## Pull Request Guidelines
Before you submit a pull request from your forked repo, check that it
meets these guidelines:
1. The pull request should include tests, either as doctests,
unit tests, or both.
2. If the pull request adds functionality, the docs should be updated
as part of the same PR. Doc string are often sufficient, make
sure to follow the sphinx compatible standards.
3. The pull request should work for Python 2.7, and ideally python 3.4+.
``from __future__ import`` will be required in every `.py` file soon.
4. Code will be reviewed by re running the unittests, flake8 and syntax
should be as rigorous as the core Python project.
5. Please rebase and resolve all conflicts before submitting.
6. If you are asked to update your pull request with some changes there's
no need to create a new one. Push your changes to the same branch.
2017-01-25 14:41:39 -05:00
## Documentation
2015-07-20 19:29:16 -04:00
2017-07-31 15:24:19 -04:00
The latest documentation and tutorial are available [here ](https://superset.incubator.apache.org/ ).
2017-01-25 14:41:39 -05:00
Contributing to the official documentation is relatively easy, once you've setup
your environment and done an edit end-to-end. The docs can be found in the
`docs/` subdirectory of the repository, and are written in the
[reStructuredText format ](https://en.wikipedia.org/wiki/ReStructuredText ) (.rst).
If you've written Markdown before, you'll find the reStructuredText format familiar.
Superset uses [Sphinx ](http://www.sphinx-doc.org/en/1.5.1/ ) to convert the rst files
in `docs/` to the final HTML output users see.
Before you start changing the docs, you'll want to
[fork the Superset project on Github ](https://help.github.com/articles/fork-a-repo/ ).
Once that new repository has been created, clone it on your local machine:
2017-09-14 20:41:01 -04:00
git clone git@github.com:your_username/incubator-superset.git
2017-01-25 14:41:39 -05:00
At this point, you may also want to create a
[Python virtual environment ](http://docs.python-guide.org/en/latest/dev/virtualenvs/ )
to manage the Python packages you're about to install:
virtualenv superset-dev
source superset-dev/bin/activate
2017-01-26 12:07:23 -05:00
Finally, to make changes to the rst files and build the docs using Sphinx,
you'll need to install a handful of dependencies from the repo you cloned:
2017-01-25 14:41:39 -05:00
2017-09-14 20:41:01 -04:00
cd incubator-superset
2017-01-26 12:07:23 -05:00
pip install -r dev-reqs-for-docs.txt
2017-01-25 14:41:39 -05:00
To get the feel for how to edit and build the docs, let's edit a file, build
the docs and see our changes in action. First, you'll want to
[create a new branch ](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging )
to work on your changes:
git checkout -b changes-to-docs
Now, go ahead and edit one of the files under `docs/` , say `docs/tutorial.rst`
- change it however you want. Check out the
[ReStructuredText Primer ](http://docutils.sourceforge.net/docs/user/rst/quickstart.html )
for a reference on the formatting of the rst files.
Once you've made your changes, run this command from the root of the Superset
repo to convert the docs into HTML:
python setup.py build_sphinx
You'll see a lot of output as Sphinx handles the conversion. After it's done, the
HTML Sphinx generated should be in `docs/_build/html` . Go ahead and navigate there
and start a simple web server so we can check out the docs in a browser:
cd docs/_build/html
python -m SimpleHTTPServer
This will start a small Python web server listening on port 8000. Point your
browser to [http://localhost:8000/ ](http://localhost:8000/ ), find the file
you edited earlier, and check out your changes!
If you've made a change you'd like to contribute to the actual docs, just commit
your code, push your new branch to Github:
git add docs/tutorial.rst
git commit -m 'Awesome new change to tutorial'
git push origin changes-to-docs
Then, [open a pull request ](https://help.github.com/articles/about-pull-requests/ ).
If you're adding new images to the documentation, you'll notice that the images
referenced in the rst, e.g.
.. image:: _static/img/tutorial/tutorial_01_sources_database.png
aren't actually included in that directory. _Instead_ , you'll want to add and commit
images (and any other static assets) to the _superset/assets/images_ directory.
2017-08-01 11:54:35 -04:00
When the docs are being pushed to [Apache Superset (incubating) ](https://superset.incubator.apache.org/ ), images
2017-01-25 14:41:39 -05:00
will be moved from there to the _\_static/img_ directory, just like they're referenced
in the docs.
For example, the image referenced above actually lives in
superset/assets/images/tutorial
Since the image is moved during the documentation build process, the docs reference the
image in
_static/img/tutorial
instead.
2015-07-20 19:29:16 -04:00
2016-02-27 10:47:56 -05:00
## Setting up a Python development environment
2016-01-13 12:03:27 -05:00
2017-08-01 11:54:35 -04:00
Check the [OS dependencies ](https://superset.incubator.apache.org/installation.html#os-dependencies ) before follows these steps.
2016-04-08 20:57:24 -04:00
2016-08-14 18:48:46 -04:00
# fork the repo on GitHub and then clone it
2016-01-13 12:03:27 -05:00
# alternatively you may want to clone the main repo but that won't work
# so well if you are planning on sending PRs
2017-08-01 11:54:35 -04:00
# git clone git@github.com:apache/incubator-superset.git
2016-01-13 12:03:27 -05:00
# [optional] setup a virtual env and activate it
virtualenv env
source env/bin/activate
# install for development
python setup.py develop
# Create an admin user
2016-11-10 02:08:22 -05:00
fabmanager create-admin --app superset
2015-07-20 19:29:16 -04:00
2016-01-13 12:03:27 -05:00
# Initialize the database
2016-11-10 02:08:22 -05:00
superset db upgrade
2015-07-20 19:29:16 -04:00
2016-01-13 12:03:27 -05:00
# Create default roles and permissions
2016-11-10 02:08:22 -05:00
superset init
2016-01-13 12:03:27 -05:00
# Load some data to play with
2016-11-10 02:08:22 -05:00
superset load_examples
2016-01-13 12:03:27 -05:00
# start a dev web server
2016-11-10 02:08:22 -05:00
superset runserver -d
2016-01-13 12:03:27 -05:00
2016-02-27 10:47:56 -05:00
## Setting up the node / npm javascript environment
2016-11-10 02:08:22 -05:00
`superset/assets` contains all npm-managed, front end assets.
2016-02-27 10:47:56 -05:00
Flask-Appbuilder itself comes bundled with jQuery and bootstrap.
While these may be phased out over time, these packages are currently not
managed with npm.
2016-10-14 03:00:12 -04:00
### Node/npm versions
2016-12-01 19:48:56 -05:00
Make sure you are using recent versions of node and npm. No problems have been found with node>=5.10 and 4.0. > npm>=3.9.
2016-02-27 10:47:56 -05:00
### Using npm to generate bundled files
#### npm
First, npm must be available in your environment. If it is not you can run the following commands
(taken from [this source ](https://gist.github.com/DanHerbert/9520689 ))
```
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
```
2016-06-15 17:24:25 -04:00
The final step is to add `~/.npm-packages/bin` to your `PATH` so commands you install globally are usable.
Add something like this to your `.bashrc` file, then `source ~/.bashrc` to reflect the change.
2016-02-27 10:47:56 -05:00
```
2016-06-15 17:24:25 -04:00
export PATH="$HOME/.npm-packages/bin:$PATH"
2016-02-27 10:47:56 -05:00
```
#### npm packages
To install third party libraries defined in `package.json` , run the
2016-11-10 02:08:22 -05:00
following within the `superset/assets/` directory which will install them in a
2016-02-27 10:47:56 -05:00
new `node_modules/` folder within `assets/` .
2017-07-19 04:17:56 -04:00
```bash
# from the root of the repository, move to where our JS package.json lives
cd superset/assets/
# install yarn, a replacement for `npm install` that is faster and more deterministic
npm install -g yarn
# run yarn to fetch all the dependencies
yarn
2016-02-27 10:47:56 -05:00
```
2016-11-10 02:08:22 -05:00
To parse and generate bundled files for superset, run either of the
2016-02-27 10:47:56 -05:00
following commands. The `dev` flag will keep the npm script running and
re-run it upon any changes within the assets directory.
```
2017-02-16 20:28:35 -05:00
# Copies a conf file from the frontend to the backend
npm run sync-backend
2016-02-27 10:47:56 -05:00
# Compiles the production / optimized js & css
npm run prod
# Start a web server that manages and updates your assets as you modify them
npm run dev
```
For every development session you will have to start a flask dev server
as well as an npm watcher
```
2016-11-10 02:08:22 -05:00
superset runserver -d -p 8081
2016-02-27 10:47:56 -05:00
npm run dev
```
2016-01-13 12:03:27 -05:00
## Testing
2015-07-20 19:29:16 -04:00
2017-06-21 15:52:04 -04:00
Before running python unit tests, please setup local testing environment:
```
pip install -r dev-reqs.txt
```
2016-07-19 19:14:04 -04:00
Python tests can be run with:
2015-07-20 19:29:16 -04:00
2016-05-03 15:45:38 -04:00
./run_tests.sh
2015-07-20 19:29:16 -04:00
2016-07-19 19:14:04 -04:00
We use [Mocha ](https://mochajs.org/ ), [Chai ](http://chaijs.com/ ) and [Enzyme ](http://airbnb.io/enzyme/ ) to test Javascript. Tests can be run with:
2016-11-10 02:08:22 -05:00
cd /superset/superset/assets/javascripts
2016-07-19 19:14:04 -04:00
npm i
npm run test
## Linting
2015-07-20 19:29:16 -04:00
Lint the project with:
2016-03-16 11:23:40 -04:00
# for python changes
2015-07-20 19:29:16 -04:00
flake8 changes tests
2016-11-10 02:08:22 -05:00
flake8 changes superset
2015-07-20 19:29:16 -04:00
2016-03-16 11:23:40 -04:00
# for javascript
npm run lint
2016-09-02 21:43:28 -04:00
## Linting with codeclimate
2016-11-10 02:08:22 -05:00
Codeclimate is a service we use to measure code quality and test coverage. To get codeclimate's report on your branch, ideally before sending your PR, you can setup codeclimate against your Superset fork. After you push to your fork, you should be able to get the report at http://codeclimate.com . Alternatively, if you prefer to work locally, you can install the codeclimate cli tool.
2016-09-02 21:43:28 -04:00
*Install the codeclimate cli tool*
```
curl -L https://github.com/docker/machine/releases/download/v0.7.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine & & chmod +x /usr/local/bin/docker-machine
brew install docker
docker-machine create --driver virtual box default
docker-machine env default
eval "$(docker-machine env default)"
docker pull codeclimate/codeclimate
brew tap codeclimate/formulae
brew install codeclimate
```
*Run the lint command:*
```
docker-machine start
eval "$(docker-machine env default)”
codeclimate analyze
```
More info can be found here: https://docs.codeclimate.com/docs/open-source-free
2015-07-20 19:29:16 -04:00
## API documentation
Generate the documentation with:
cd docs & & ./build.sh
2016-03-05 15:41:22 -05:00
## CSS Themes
2016-11-10 02:08:22 -05:00
As part of the npm build process, CSS for Superset is compiled from `Less` , a dynamic stylesheet language.
2016-03-05 15:41:22 -05:00
2016-11-10 02:08:22 -05:00
It's possible to customize or add your own theme to Superset, either by overriding CSS rules or preferably
2016-05-02 13:50:23 -04:00
by modifying the Less variables or files in `assets/stylesheets/less/` .
2016-03-05 15:41:22 -05:00
2016-11-10 02:08:22 -05:00
The `variables.less` and `bootswatch.less` files that ship with Superset are derived from
2016-03-05 15:41:22 -05:00
[Bootswatch ](https://bootswatch.com ) and thus extend Bootstrap. Modify variables in these files directly, or
swap them out entirely with the equivalent files from other Bootswatch (themes)[https://github.com/thomaspark/bootswatch.git]
2015-07-20 19:29:16 -04:00
2016-05-20 14:05:28 -04:00
## Translations
2016-05-02 13:50:23 -04:00
2016-11-10 02:08:22 -05:00
We use [Babel ](http://babel.pocoo.org/en/latest/ ) to translate Superset. The
2016-05-02 13:50:23 -04:00
key is to instrument the strings that need translation using
2016-08-02 02:02:41 -04:00
`from flask_babel import lazy_gettext as _` . Once this is imported in
2016-05-02 13:50:23 -04:00
a module, all you have to do is to `_("Wrap your strings")` using the
underscore `_` "function".
To enable changing language in your environment, you can simply add the
2016-11-10 02:08:22 -05:00
`LANGUAGES` parameter to your `superset_config.py` . Having more than one
2016-05-02 13:50:23 -04:00
options here will add a language selection dropdown on the right side of the
navigation bar.
LANGUAGES = {
'en': {'flag': 'us', 'name': 'English'},
'fr': {'flag': 'fr', 'name': 'French'},
'zh': {'flag': 'cn', 'name': 'Chinese'},
}
As per the [Flask AppBuilder documentation] about translation, to create a
new language dictionary, run the following command:
2016-11-10 02:08:22 -05:00
pybabel init -i ./babel/messages.pot -d superset/translations -l es
2016-05-02 13:50:23 -04:00
2017-08-06 23:27:54 -04:00
Then it's a matter of running the statement below to gather all strings that
2016-05-02 13:50:23 -04:00
need translation
2016-11-10 02:08:22 -05:00
fabmanager babel-extract --target superset/translations/
2016-05-02 13:50:23 -04:00
You can then translate the strings gathered in files located under
2016-11-10 02:08:22 -05:00
`superset/translation` , where there's one per language. For the translations
2016-05-02 13:50:23 -04:00
to take effect, they need to be compiled using this command:
2016-11-10 02:08:22 -05:00
fabmanager babel-compile --target superset/translations/
2016-09-21 12:52:05 -04:00
## Adding new datasources
2016-11-10 02:08:22 -05:00
1. Create Models and Views for the datasource, add them under superset folder, like a new my_models.py
2016-09-21 12:52:05 -04:00
with models for cluster, datasources, columns and metrics and my_views.py with clustermodelview
and datasourcemodelview.
2. Create db migration files for the new models
3. Specify this variable to add the datasource model and from which module it is from in config.py:
For example:
2016-11-10 02:08:22 -05:00
`ADDITIONAL_MODULE_DS_MAP = {'superset.my_models': ['MyDatasource', 'MyOtherDatasource']}`
2016-09-21 12:52:05 -04:00
2016-11-10 02:08:22 -05:00
This means it'll register MyDatasource and MyOtherDatasource in superset.my_models module in the source registry.
2017-06-22 15:37:22 -04:00
## Creating a new visualization type
Here's an example as a Github PR with comments that describe what the
different sections of the code do:
2017-08-01 11:54:35 -04:00
https://github.com/apache/incubator-superset/pull/3013
2017-08-15 19:37:40 -04:00
## Refresh documentation website
Every once in a while we want to compile the documentation and publish it.
Here's how to do it.
.. code::
# install doc dependencies
pip install -r dev-reqs-for-docs.txt
# build the docs
python setup.py build_sphinx
# copy html files to temp folder
cp -r docs/_build/html/ /tmp/tmp_superset_docs/
# clone the docs repo
cd ~/
git clone https://git-wip-us.apache.org/repos/asf/incubator-superset-site.git
# copy
cp -r /tmp/tmp_superset_docs/ ~/incubator-superset-site.git/
# commit and push to `asf-site` branch
cd ~/incubator-superset-site.git/
git checkout asf-site
git add .
git commit -a -m "New doc version"
git push origin master