From 19b0b4662c1311af4f9fa6d9bf9ddc7bc613b7c7 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 03:05:08 +0100 Subject: [PATCH 01/32] moving skeleton from kolibri_skeleton repo --- .coveragerc | 8 + .gitignore | 71 ++--- .travis.yml | 29 ++ AUTHORS.rst | 16 ++ CHANGELOG.rst | 14 + CONTRIBUTING.rst | 109 +++++++ LICENSE | 32 ++- MANIFEST.in | 5 + Makefile | 56 ++++ README.rst | 82 +++++- TODO.rst | 29 ++ docs/Makefile | 177 ++++++++++++ docs/authors.rst | 1 + docs/changelog.rst | 1 + docs/conf.py | 270 ++++++++++++++++++ docs/contributing.rst | 1 + docs/index.rst | 18 ++ docs/installation.rst | 9 + docs/logo.png | Bin 0 -> 9314 bytes docs/make.bat | 242 ++++++++++++++++ docs/todo.rst | 1 + docs/usage.rst | 7 + kolibri/__init__.py | 5 + kolibri/__main__.py | 6 + kolibri/core/__init__.py | 10 + kolibri/core/kolibri_plugin.py | 28 ++ kolibri/core/models.py | 8 + kolibri/core/templates/kolibri/base.html | 25 ++ kolibri/core/templates/kolibri/index.html | 1 + kolibri/core/templates/kolibri/todo.html | 9 + kolibri/core/templatetags/__init__.py | 0 kolibri/core/templatetags/kolibri_tags.py | 36 +++ kolibri/core/urls.py | 19 ++ kolibri/core/views/__init__.py | 24 ++ kolibri/deployment/__init__.py | 0 kolibri/deployment/default/__init__.py | 0 kolibri/deployment/default/db.sqlite3 | Bin 0 -> 3072 bytes .../deployment/default/settings/__init__.py | 4 + kolibri/deployment/default/settings/base.py | 111 +++++++ kolibri/deployment/default/urls.py | 30 ++ kolibri/deployment/default/wsgi.py | 16 ++ kolibri/logger.py | 26 ++ kolibri/plugins/__init__.py | 4 + kolibri/plugins/base.py | 49 ++++ kolibri/plugins/example_plugin/__init__.py | 10 + .../plugins/example_plugin/kolibri_plugin.py | 28 ++ kolibri/plugins/example_plugin/models.py | 17 ++ .../kolibri/plugins/example_plugin/index.html | 5 + kolibri/plugins/example_plugin/urls.py | 17 ++ kolibri/plugins/example_plugin/views.py | 16 ++ kolibri/plugins/hooks.py | 52 ++++ kolibri/plugins/registry.py | 46 +++ kolibri/test/__init__.py | 0 kolibri/test/test_basic.py | 22 ++ kolibri/utils/__init__.py | 0 kolibri/utils/cli.py | 175 ++++++++++++ kolibri/utils/conf.py | 49 ++++ pytest.ini | 2 + requirements.txt | 1 + requirements/base.txt | 5 + requirements/dev.txt | 1 + requirements/docs.txt | 5 + requirements/test.txt | 7 + setup.cfg | 15 + setup.py | 57 ++++ test/__init__.py | 0 test/test_cli.py | 35 +++ tox.ini | 29 ++ 68 files changed, 2123 insertions(+), 60 deletions(-) create mode 100644 .coveragerc create mode 100644 .travis.yml create mode 100644 AUTHORS.rst create mode 100644 CHANGELOG.rst create mode 100644 CONTRIBUTING.rst create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 TODO.rst create mode 100644 docs/Makefile create mode 100644 docs/authors.rst create mode 100644 docs/changelog.rst create mode 100644 docs/conf.py create mode 100644 docs/contributing.rst create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/logo.png create mode 100644 docs/make.bat create mode 100644 docs/todo.rst create mode 100644 docs/usage.rst create mode 100755 kolibri/__init__.py create mode 100644 kolibri/__main__.py create mode 100644 kolibri/core/__init__.py create mode 100644 kolibri/core/kolibri_plugin.py create mode 100644 kolibri/core/models.py create mode 100644 kolibri/core/templates/kolibri/base.html create mode 100644 kolibri/core/templates/kolibri/index.html create mode 100644 kolibri/core/templates/kolibri/todo.html create mode 100644 kolibri/core/templatetags/__init__.py create mode 100644 kolibri/core/templatetags/kolibri_tags.py create mode 100644 kolibri/core/urls.py create mode 100644 kolibri/core/views/__init__.py create mode 100644 kolibri/deployment/__init__.py create mode 100644 kolibri/deployment/default/__init__.py create mode 100644 kolibri/deployment/default/db.sqlite3 create mode 100644 kolibri/deployment/default/settings/__init__.py create mode 100644 kolibri/deployment/default/settings/base.py create mode 100644 kolibri/deployment/default/urls.py create mode 100644 kolibri/deployment/default/wsgi.py create mode 100644 kolibri/logger.py create mode 100644 kolibri/plugins/__init__.py create mode 100644 kolibri/plugins/base.py create mode 100644 kolibri/plugins/example_plugin/__init__.py create mode 100644 kolibri/plugins/example_plugin/kolibri_plugin.py create mode 100644 kolibri/plugins/example_plugin/models.py create mode 100644 kolibri/plugins/example_plugin/templates/kolibri/plugins/example_plugin/index.html create mode 100644 kolibri/plugins/example_plugin/urls.py create mode 100644 kolibri/plugins/example_plugin/views.py create mode 100644 kolibri/plugins/hooks.py create mode 100644 kolibri/plugins/registry.py create mode 100644 kolibri/test/__init__.py create mode 100755 kolibri/test/test_basic.py create mode 100644 kolibri/utils/__init__.py create mode 100644 kolibri/utils/cli.py create mode 100644 kolibri/utils/conf.py create mode 100644 pytest.ini create mode 100644 requirements.txt create mode 100644 requirements/base.txt create mode 100644 requirements/dev.txt create mode 100644 requirements/docs.txt create mode 100644 requirements/test.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 test/__init__.py create mode 100755 test/test_cli.py create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000000..a580f998478 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,8 @@ +[run] +branch = true + +[report] +show_missing = true +precision = 2 +exclude_lines = raise NotImplementedError + diff --git a/.gitignore b/.gitignore index d6bfe3d28e8..7b0430e8ccc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,62 +1,49 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ *.py[cod] -*$py.class # C extensions *.so -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg +# Packages +.cache +.eggs *.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 # Installer logs pip-log.txt -pip-delete-this-directory.txt # Unit test / coverage reports -htmlcov/ -.tox/ .coverage -.coverage.* -.cache +.tox nosetests.xml -coverage.xml -*,cover -.hypothesis/ # Translations *.mo -*.pot -# Django stuff: -*.log +# Mr Developer +.mr.developer.cfg +.project +.pydevproject +.venv -# Sphinx documentation -docs/_build/ +# Complexity +output/*.html +output/*/index.html -# PyBuilder -target/ +# Sphinx +docs/_build -# PyCharm -.idea \ No newline at end of file +# api-docs +docs/kolibri*rst +docs/modules.rst diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..52362c201f5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +# Config file for automatic testing at travis-ci.org + +language: python + +sudo: false + +python: + - "3.4" + - "3.5" + - "2.7" + - "pypy" + +before_install: + - pip install codecov + - pip install tox + +before_script: + - tox -e lint + +# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: + - TOX_ENV=py${TRAVIS_PYTHON_VERSION} + +# command to run tests, e.g. python setup.py test +script: + - tox -e $TOX_ENV + +after_success: + - codecov diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 00000000000..69065a492fa --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,16 @@ +======= +Credits +======= + +Development Lead +---------------- + +* Learning Equality + + +Community +--------- + +Please feel free to add your name on this list if you do a PR! + +* Your name here / github username diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 00000000000..78f98e8d57c --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,14 @@ +.. :changelog: + +============= +Release notes +============= + +*Don’t let your friends dump git logs into CHANGELOGs™* + +http://keepachangelog.com/ + +Kolibri 0.0.1 ++++++++++++++ + +* This is a test skeleton! diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 00000000000..a69f59fd841 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,109 @@ +============ +Contributing +============ + +Contributions are welcome, and they are greatly appreciated! Every +little bit helps, and credit will always be given. + +You can contribute in many ways: + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/learningequality/kolibri/issues. + +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. + +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 "feature" +is open to whoever wants to implement it. + +Write Documentation +~~~~~~~~~~~~~~~~~~~ + +Kolibri could always use more documentation, whether as part of the +official Kolibri docs, in docstrings, or even on the web in blog posts, +articles, and such. + +Submit Feedback +~~~~~~~~~~~~~~~ + +The best way to send feedback is to file an issue at https://github.com/learningequality/kolibri/issues. + +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 :) + +Get Started! +------------ + +Ready to contribute? Here's how to set up `kolibri` for +local development. + +1. Fork_ the `kolibri` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/kolibri.git + +3. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + +Now you can make your changes locally. + +4. When you're done making changes, check that your changes pass style and unit + tests, including testing other Python versions with tox:: + + $ tox + +To get tox, just pip install it. + +5. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +6. Submit a pull request through the GitHub website. + +.. _Fork: https://github.com/learningequality/kolibri/fork + +Pull Request Guidelines +----------------------- + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put + your new functionality into a function with a docstring, and add the + feature to the list in README.rst. +3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. + Check https://travis-ci.org/learningequality/kolibri + under pull requests for active pull requests or run the ``tox`` command and + make sure that the tests pass for all supported Python versions. + + +Tips +---- + +To run a subset of tests:: + + $ py.test test/test_kolibri.py diff --git a/LICENSE b/LICENSE index e44e093e26c..33f488f3a20 100644 --- a/LICENSE +++ b/LICENSE @@ -1,18 +1,20 @@ -Copyright for the Kolibri software, except where otherwise specified in the code or further down in this file, belongs -to the Foundation for Learning Equality, Inc. (FLE), and by contributing your code to this project (except where -otherwise negotiated), you agree to assign copyright in this code to FLE, to be licensed under the same terms as the -rest of the code. The Kolibri codebase is released for use under the open-source MIT license -(see http://opensource.org/licenses/MIT): +The MIT License (MIT) -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit -persons to whom the Software is furnished to do so, subject to the following conditions: +Copyright (c) 2015 Learning Equality -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the -Software. +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000000..f2a06d6c0cb --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include AUTHORS.rst +include CONTRIBUTING.rst +include CHANGELOG.rst +include LICENSE +include README.rst diff --git a/Makefile b/Makefile new file mode 100644 index 00000000000..8f8fbd53b67 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +.PHONY: help clean clean-pyc clean-build list test test-all coverage docs release sdist + +help: + @echo "clean-build - remove build artifacts" + @echo "clean-pyc - remove Python file artifacts" + @echo "lint - check style with flake8" + @echo "test - run tests quickly with the default Python" + @echo "testall - run tests on every Python version with tox" + @echo "coverage - check code coverage quickly with the default Python" + @echo "docs - generate Sphinx HTML documentation, including API docs" + @echo "release - package and upload a release" + @echo "sdist - package" + +clean: clean-build clean-pyc clean-docs + +clean-build: + rm -fr build/ + rm -fr dist/ + rm -fr *.egg-info + +clean-pyc: + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + +clean-docs: + rm -f docs/kolibri*rst + rm -f docs/modules.rst + $(MAKE) -C docs clean + +lint: + python3 -m pyflakes kolibri + pep8 kolibri test + +test: + python setup.py test + +test-all: + tox + +coverage: + coverage run --source kolibri setup.py test + coverage report -m + +docs: clean-docs + sphinx-apidoc -d 10 -H "Python Reference" -o docs/ kolibri kolibri/test kolibri/deployment/ + $(MAKE) -C docs html + +release: clean + python setup.py sdist upload + python setup.py bdist_wheel upload + +sdist: clean + python setup.py sdist + python setup.py bdist_wheel upload + ls -l dist diff --git a/README.rst b/README.rst index e31f2f0eb38..8ac52c3d92c 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,13 @@ +Kolibri +============================= + +.. image:: https://travis-ci.org/benjaoming/kolibri_skeleton.svg + :target: https://travis-ci.org/benjaoming/kolibri_skeleton +.. image:: http://codecov.io/github/benjaoming/kolibri_skeleton/coverage.svg?branch=master + :target: http://codecov.io/github/benjaoming/kolibri_skeleton?branch=master +.. image:: https://readthedocs.org/projects/kolibri/badge/?version=latest + :target: http://kolibri.readthedocs.org/en/latest/ + What is Kolibri? ---------------- @@ -8,8 +18,8 @@ installation or the internet. At its core, Kolibri is about serving educational content. A typical user (called a Learner) will log in to Kolibri to consume educational content (videos, documents, other multimedia) and test their understanding of the content by -completing exercises and quizzes, with immediate feedback. A users activity will be tracked to offer individualized -insight (like next lesson recommendations), and to allow user data to be synced across different installations -- +completing exercises and quizzes, with immediate feedback. A user’s activity will be tracked to offer individualized +insight (like “next lesson” recommendations), and to allow user data to be synced across different installations -- thus a Kolibri learner can use his or her credentials on any linked Kolibri installation, for instance on different devices at a school. @@ -21,9 +31,75 @@ Join the mailing list: dev (at) learningequality (dot) org The project is just starting, but we want the entire development process, from conception to realization, to be carried out in the open. More will be added to this section in the very near future! + +Running Kolibri +--------------- + +This is how we typically set up a development environment. +Adjust according to your operating system or personal preferences. + +#. Check out the repository:: + + $ git clone git@github.com:learningequality/kolibri.git + $ cd kolibri/ + +#. Install a virtual environment for development (Python 2 or Python 3, you choose!):: + + $ sudo pip install virtualenvwrapper + $ mkvirtualenv --python=python3 kolibri + $ workon kolibri + +#. Install kolibri as an editable, meaning your installation will point to your git checkout:: + + $ pip install -e . + +#. Run the development server:: + + $ kolibri manage runserver + + +Testing +------- + +Kolibri comes with a test suite based on ``py.test``. To run tests in your +current environment:: + + $ python setup.py test # alternatively, "make test" does the same + +You can also use ``tox`` to setup a clean and disposable environment:: + + $ tox -e py3.4 # Runs tests with Python 3.4 + +To run tests for all environments, lint and documentation tests, +use simply ``tox``. This simulates what our CI also does. + +To run linting tests (pep8 and static code analysis), use ``tox -e lint`` or +``make lint``. + + +Current Features +---------------- + +This is a WIP. Architecture is new, and many things are mentioned with the predecessor KA Lite in mind. + +Software architecture +~~~~~~~~~~~~~~~~~~~~~ + +* Using py.test +* Using tox to build py 2.7, 3.4, 3.5 and pypy +* Automatic linting test (pep8) +* Static code analysis check (pyflakes) +* Circle CI +* Integration tests are separate from application code in ``test/`` +* Unit tests live in ``kolibri/test`` and ``kolibri/plugins/core/plugin_name/tests`` +* An example plugin is provided in ``kolibri/plugins/core/example`` + + Documentation ------------- +Usage and API features are taking shape in ``docs/`` and are readable and online on `Read The Docs `_ + Development documentation is in our `Google Drive `_, which you can view and comment on. @@ -31,4 +107,4 @@ You may wish to start with the following documents: * `Introduction to Learning Equality Software `_ * `Our governance model `_ -* `The Kolibri dev bible `_, which aims to be the authoritative guide to Kolibri. \ No newline at end of file +* `The Kolibri dev bible `_, which aims to be the authoritative guide to Kolibri. diff --git a/TODO.rst b/TODO.rst new file mode 100644 index 00000000000..a234ffa1279 --- /dev/null +++ b/TODO.rst @@ -0,0 +1,29 @@ +Planned features +================ + +Skeleton TODO +------------- + + - Plugin class definitions + - Hooks? + - Logging in general + - Logging in tests + - Test framework and --capture + - Add codecov-io + - pytest.ini + - sketch out kolibri command + - implement settings pattern + - python setup.py sdist bdist_wininst upload + - versioning + - changelog + - Circle repo + +Decision TODO +------------- + +#. Django 1.8 or 1.9 (LTS or latest?) +#. CircleCI, right? +#. Should JS / BDD tests be separated out? How to run optionally? +#. Test trigger configuration + #. git show -s --no-notes --oneline 41dcb5e1720929f015b1e04c59fa30f78661daa4 +#. Can we test with multiple CPUs? http://tox.readthedocs.org/en/latest/example/pytest.html#using-multiple-cpus-for-test-runs diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000000..0e35bee9147 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 00000000000..e122f914a87 --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1 @@ +.. include:: ../AUTHORS.rst diff --git a/docs/changelog.rst b/docs/changelog.rst new file mode 100644 index 00000000000..565b0521d0c --- /dev/null +++ b/docs/changelog.rst @@ -0,0 +1 @@ +.. include:: ../CHANGELOG.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000000..57cf34e83ea --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- +# +# complexity documentation build configuration file, created by +# sphinx-quickstart on Tue Jul 9 22:26:36 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import tempfile + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# sys.path.insert(0, os.path.abspath('.')) + +cwd = os.getcwd() +parent = os.path.dirname(cwd) +sys.path.insert(0, parent) + +import kolibri + +# When we start loading stuff from kolibri, we're gonna need this +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") +os.environ["KOLIBRI_HOME"] = tempfile.mkdtemp() + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Kolibri' +copyright = u'2015, Learning Equality' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = kolibri.__version__ +# The full version, including alpha/beta/rc tags. +release = kolibri.__version__ + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' +on_rtd = os.environ.get('READTHEDOCS', None) == 'True' + + +if on_rtd: + os.system("sphinx-apidoc --doc-project='Python Reference' -f -o . ../kolibri ../kolibri/test ../kolibri/deployment/") + +if not on_rtd: # only import and set the theme if we're building docs locally + import sphinx_rtd_theme + html_theme = 'sphinx_rtd_theme' + html_theme_path = ['.', sphinx_rtd_theme.get_html_theme_path()] + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +html_logo = 'logo.png' + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'kolibridoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +# 'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +# 'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +# 'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'kolibri.tex', u'Kolibri Documentation', + u'Learning Equality', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'kolibri', u'Kolibri Documentation', + [u'Learning Equality'], 1) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'kolibri', u'Kolibri Documentation', + u'Learning Equality', 'kolibri', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000000..e582053ea01 --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000000..edbb82d4089 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,18 @@ +.. include:: ../README.rst + +.. include:: ../TODO.rst + +Contents: +========= + +.. toctree:: + :maxdepth: 1 + + installation + usage + contributing + authors + changelog + todo + modules + diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 00000000000..ec97e7249a7 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,9 @@ +============ +Installation +============ + +Once Kolibri is released, you may install it as a standard package from +PyPi using this command:: + + $ pip install kolibri + diff --git a/docs/logo.png b/docs/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..c32d380a769b746d2a1b3cd36bb4a1a65b83af9b GIT binary patch literal 9314 zcmV-oB%RxdP)Oz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$Qi@a{RY)E3 zJ#qp$hg?Rwkvqr$GJ^buyhkyVfwECO)C{#lxu`c9ghrwZ&}4KmnvWKso6vH!8a<3Q zq36)6Xb;+tK10Vaz~~qUGsJ8#F2=(`u{bOVlVi)VBCHIn#u~6ztOL7=^<&SmcLWlF zMZgI*1b0FpVIDz9SWH+>*hr`#93(Um+6gxa1B6k+CnA%mOSC4s5&6UzVlpv@SV$}* z))J2sFA#f(L&P^E5{W}HC%KRUNwK6<(h|}}(r!{C=`5+6G)NjFlgZj-YqAG9lq?`C z$c5yc>d>VnA`E_*3F2Qp##d8RZb=H01_mm@+|Cqnc9PsG(F5HIG_C zt)aG3uTh7n6Et<2In9F>NlT@zqLtGcXcuVrX|L#Xx)I%#9!{6gSJKPrN9dR61N3(c z4Tcqi$B1Vr8Jidf7-t!G7_XR2rWwr)$3XQ?}=hpK0&Z&W{| zep&sA23f;Q!%st`QJ}G3cbou<7-yIK2z4nfCCCtN2-XOGSWo##{8Q{ATurxr~;I`ytDs%xbip}RzP zziy}Qn4Z2~fSycmr`~zJ=lUFdFa1>gZThG6M+{g7vkW8#+YHVaJjFF}Z#*3@$J_By zLtVo_L#1JrVVB{Ak-5=4qt!-@Mh}c>#$4kh<88)m#-k<%CLtzEP3leVno>={htGUuD;o7bD)w_sX$S}eAxwzy?UvgBH(S?;#HZiQMoS*2K2 zT3xe7t(~nU*1N5{rxB;QPLocnp4Ml>u<^FZwyC!nu;thW+pe~4wtZn|Vi#w(#jeBd zlf9FDx_yoPJqHbk*$%56S{;6Kv~mM9!g3B(KJ}#RZ#@)!hR|78Dq|Iq-afF%KE1Brn_fm;Im z_u$xr8UFki1L{Ox>G0o)(&RAZ;=|I=wN2l97;cLaHH6leTB-XXa*h%dBOEvi`+x zi?=Txl?TadvyiL>SuF~-LZ;|cS}4~l2eM~nS7yJ>iOM;atDY;(?aZ^v+mJV$@1Ote z62cPUlD4IWOIIx&SmwQ~YB{nzae3Pc;}r!fhE@iwJh+OsDs9zItL;~pu715HdQEGA zUct(O!LkCy1<%NCg+}G`0PgpNm-?d@-hMgNe6^V+j6x$b<6@S<$+<4_1hi}Ti zncS4LsjI}fWY1>OX6feMEuLErma3QLmkw?X+1j)X-&VBk_4Y;EFPF_I+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGqB>(^xB>_oNB=7(L00(qQO+^Rb0TUA{9k)^4I{*L~lu1NE zRCwC$oq2R!)qU?j`h|Ofc#SAY2hopU7r8F;nQ&-!UtmLhh zwc6D;B&+YG&CtHChBg6`CImtP27F8V_XGfcEEfQco?`IaAf}30A-e47(fDu0})_5@Qe^*$5jrwgh&~G zQ>Bz!fct^-eZ79oV^aw>o2a&m^0a(l*_DZT<2{yLyvO8IRe#AV|aG2cLBCc7EtKmPF~&n8L0?3l&fd2%#}Mb*3@8T;HxwIdaGoz+Yb7>)CG^aJ>*>@4Nz%L3ne<1HVdhrv*U&Y|LUY z2k!7+;o*?WNxOv*vx;CSv*3*JsO=RGhAGX<)%AKQ<=1Cpd5KwY#!ALQ=vQ?1zw7)- z7Sy(2v)C@z5D6iKBX5x6+e~J# zxP-V00HyP`DWA}(zz+_-%l;GZVYORXzxp;7HZ3WHcjPT0#4R)J$uupN0b}cYff0_y z`Sb67pTB+fS0C$&!;uib{_Vf<=I&RisjTBm_dcEz81EcA$s^xXD4IZA=DbCLQua;H&wJ)IB)F_kXz! zp(wOoy9U!R@b>nwc~vLt7SG?I_Fyc^Kfd-7rfE>7nK*1#I+tEUDw*Ka`|oo9rmd8h zyL0Zp-#5zBJKjdAsG_*MoW5hni1-8CaotMpx#8ORSi=26h!;Lespoa3C8-;H>j(cr z+AvTxm8#Yjs_JU_!m>q_+N=}Lr40jJH*ie)Z7!73b-ugpd2~a^qN-Rm3muDEP^}gW zV2QJwma2xig-%RKFrJ{?m2F%;cdU!vkx_aM97IYczh-F`7{OSA@4c~?C!YExiBvkLasGMxOEeT0 zvAV8-y!Iwf?moZ~k2mZ02RqxTiiYv^dGLD%X=+`> zyS-i_$yC08)JrKFCiB2l;d*~Qz3)2Ni;2K$v(wbE7>lOyoj>~;>Lfn=;8Yhsc;h`3 zO~X}E%76dSGx$Q`IgJyFglQ`)$L(;TXd0H%v0#EUC8<<$j8hF`PJRCU^V>Lht`Ad6 z-sH#TBXRbDvIH6LPY#bh0#P4N-d=h|ye-ylEwe^1e{ zuoauriPKfWHy-~oF6V_eb??b8eza{nR;!iuo3|hoK_cj28tG{#S#B=}g%MbCl&%Vk~ z&v}yZ7^9v+?4v_Gba!4#{!75iSsXG6p`11DFJ62Do2KIL^AHJySk+w1!sf<_c3(8j zA-|xat`5^Q@%Hu6*|CtndF)ZvENYw6SfimJiZvSy7`qJ$5KqKN==!YtD{(sbvoGGq zV_P;M6oqiWPf0~N@uCX$^#&)Nvsf(rhx=|L?DrG)j*yPUcxn4Pgu>B$0C{-E(8>56 zh@AY5VLx$85v|vBl1`;iRfWwrXImjVPy29L98}dc;Br^cT59L^y4-xvu#rY9a%K4* z0IE;`1Jg8!WklCpsJ+-usaj57$3hT-x{?OY49DoGc2Qy<+o}?mgEdRqIew;(n)(KW zsLW) zVdvY2^3@}^WQnZIJ@D&u>B%rn2D||bUB`3$G(ufM;4I;XfRaD)dr^5MI9`p;6?+RC|L;({e41nsq@ zjP#r*8VsSEk`rBdof%v=)ylHu8rcno;si$n!~;PBLteySKNd~B;PHB+q|#|xm#?C# zp^^W(bqm_0c7Q&gpBLWTi`{A;o0M+w^zL^VjZQz2dF1>6MU^$!OUluTN(i~E1e_{y zt3pYU3u&5^TF3hL#Y5Bn{{L+IEs0bbX&5-|cJ>@O#g2p1Ps9G+=G(A4T&&r+2_Xc> zN8?%TwHD|*p_P{K=q;Zo6b{if(8B{auf=Z34v|0e+76^)l2j#OMaP`t z-P){HTo#pawG!7;B#abx^@8~N#+G~7dF%vcn?hrK1Kxn29fv+-&7u}co!MLP$fgav zef%_vqA;v#^f_TcO*sHdI+}?mQV1cat!~0zT$2wV6V{KCQHm;K6%uj)B!sKDjLvIs z!0B|*(o{Rq7EdJU-hU9^`92K8prfvGTDbX8Pai!aqj-Y>&JGSxTjgf!hMT5=(dYAV zHaN_XmLi~}nR*<-VYO0Xvtm<3mT2)OB3aLAio)&7I$5)1A@Nj-HxBJb2*JxA9GqGrKjYATy3 zFLq?G9IK{}Bj<(sk8HMNCNf{{vNq;=wn++$l(${HcW(D-a~I(DJ!Cek!; zmX}dpS5Hkt^OQ|gFw$v8&v~HC0n4kiBev-@uk3!C(PRum2wLjbU34r>Q;pE4EmW$V>F8a%RxOIqx7PnvHdf+gN{Hc2-eD!}w13Bc;SyoUQaNRvS%= zJMj+=FyiqLk0tZbBc;FuAog4{bj?ebQ(RGjM3PKohbvS?VCXtg-w2^W12(Ok(ykEn zctO{(+ikck_DgaIfD(zKxEz=kZ3aLtY`#TNu?mGt1d2pGD##lUAZcXz-G1JuB_mpO`FhT7tb1Nsya4HMM3q4W_mrcl02mr%SSFM8cnnL zmRneU%@TCOpsr@RN#5Nvgp`taD2P>6r-*Emcqq)!>9Y)ua3-QV7%3@lUE<>6ou}GAz-VxfHE@be8qEO%1fK)8(Ja`a2mFD5f z8>uLtu1hSI3!5Qy9W5F|cR6QFv)NT`RtEx}e`ObG)q>MzqrRnu`nv4wVmy(iu5}@0 z?ka?;(pHxpf#^Ek!_et7*o%rmN~)?$@&P11nL~WJS_MT#4&tFO$#{%#FgxmL(-Z`P zR6Id6ILbR8_D)ggaLbKLIXf`GXei96XOJhKdhy~MGMT%AkqJE_riiX$%SWHN`qhiO zIDf8>fIoo8=cB!~28TV{73=i`NGFp-LqQC~q|u!%vQ8Z7A)QJS3kDGg$}94^ROXw^ zAvp(Pu3x``GpBu+rorgYAgQE|)uv^fCxMKN;_V$k0D)MXcv8nLJ0q4 z4#_zX)3KxqDJ9Wh06m#t*Y<3W_ug9<5%Kzn4*RI6ZD7}-k!gKwx%FB$f9@7;U%#G; zvQh^9L7sl)9n!inNvW&TRGo+=Q4+~XN?O68sF$4Yb369Y?HL9|uy*B2HgDX(V_P=h zoWdO^&xg@Us)_mh#76uqZ!OPi@9!M}-6S&V!!UHpEAl$zX^tC7?BcTuiL33LLZg=q%bKYRj z`(0p~w69xBDy6e_ZFaig)bV~)MUaTb=sSLr@=`S)K!(TXJ03dG8LQqoXHqqV@=6!U zXo8qOiYhJmhO=#i`+ny}&{h219)g|$e)iKh=J1Q$B}pdJ=(;hMdNvF!!7w&$%(*iSlVm(aG#JI_@zHn2GfnSpz3WCw%N(>Utib8A zOatTZ{_X|5z2^z_dkLK%X3K-O;&5a~5YC?s6AQ*jh7+WdX_l^P$_J2vso{5hT+8P| zn;*UjJ#A3a+(>18J#W2!Hal+QE@u684Im&A8l}Qr!;7z<;as18T3@S|H&R~gn!$dgWq zQ)D=jYj5T5VwSD$#Ect+Ji`p1^{{8>vFw=8;u@M7N+_>tz*$@hLb82V7d!TQG0fSy zL2Vt)w6--MJwp(QP55D{WSX!)f@zv4szNl8pw~OhvL$WQR8`EX?<3tIe)ZZJ4AVrj zSgEXS!e+Jb$U`fcEGc!};K0tKgghgJhy0Y6Rk3ny-iQBAPUR37D>9rjt-oV2kzf=( zr4tVOdHscbgag@T@TNOE=~z@v+R$;jTvWQGKheoDJeEDx$o+9H~H&%f{9(UNUjRgd(qR`w!((bwR6)A9Td4- zm;%a+t=zU|_Q@T)!^S-i-GKyTGKC!QA`(fG=`=kXk}>Q~3pa1-WFBY-%;4kZdyF)d)cN&~ z4rqS_{0BpC#se$uVZn8_YQm6xUMdzv3~gNe<2=AWPFPd!fK_uqZJ_p z#YIlObpLI0zK?RYF9N1XThnxpd&i51IkK+@SCNb2k|In~vi{C?7PM973&yYzqB@I1 zCgJd5K0RA)8uxBpfuabakr)^zNq?B%Jaceb;L+(&a|Q$8-~aI==tdf^&r2*8BN_D^Ie<=R_Xc=iX|Q3O=CHjqrDdHTC=aO0gFT(i1mJ{E!9VW+ZT5!LlcL?$gI6os;m z#W^3~o=PEql;1qH8z`c*rjqcnF3e<_>g5YqdR+taM9*b~gr+q9Vm?M_>2R~@k##7l zilV9n27H79A)fou4o)9AKQF5|alDUY(jcC;kTx|Gi#L96NKHOmOqv zt68+Hab8yO<{O75I9oR@ENfeWP!xoK0e^yg3x(PoR{rQ)51{J?Ac+T~G`73h`d@CJ zPcZfhAx1C7AplRz*Jw=(t9bNJHc(V*XTyD~x%Hk^^V09ga0qkUcM(uo>_$oJl&5th zkkU;;@%-N_cWoJ8`-_K=QgZKC)^XP(*D}xa*t8(yR68432%M&X>CGKSICi8LiKNU` zfz4v0+3ljzq0;Me5?2)*R+U?q6?9pzQO4?ynUf8WsUiy@#F_D6SE16u{bQk-5=SW( z)ruk@X-Xu5`d9)1#F7S)gkH$Y_^lAa{K#w3<4$$Kg7INDs-|GoY}hQ0i5E$lW5*d3 zDQS+x5CZx};)M*zS7!Qg8X%d=JNp@{t5|S!>SR9_%|eOuLVm)MaXQD-Mnf&k>3kPKAuL^Ay$wZo=!2sp1O2(5_Qi3&;O`N>I(qx)q-Qa9tg7ViF zt86i&$jUtY1K?aCt>X394pLEENmlq3iABwDNY<~=7*8-X5-T(?o)tnIzE~t-MnEP# z{PjXvg{~V!{00_nx)(k!vZhJ^6DS=C6G|9`1jwIUs_~L1yMz!wXY9)|pEwzYL>kl6 zq^hb+h_Cbvc@?W}ko1NN1&r?rA^I-4=a*{C$mD`4DV|Ch?0ESEfzdchCRc8?D7Z`P zNC{4hN|{}q$g3-=g1f^_aZN$gVDkzgYCfte(noO!LI@A=okCcV)v9vWmZdCRb>VEd zrYIAlDs7q*ub5`lXuherP{08A{n?bLnoZ5c@d`m_$no03<)Bb7!E3)hhRd!|WVcK# zr_QC}UR*_KLn#GB|0INXd^QixrI2!Sp;=v0O1h5^Gx?-X-GWkV#kNA4rY|G*Q}bF# zIkN$e06*m_&6Z4{UI;NX+dr6VG5((wiaz<2(0xLPq03o}e_WsJ0oGpK?@QAE7D9Y| zuC*p}F5@SqJPLGP-S-*kCqjtd&86_C$PtWjP8kGhuI_&p?G{4ZoNE=l50uaye`FMzD8Eb)$dV_i>aH15P5xKA@6#vLWqA0UUUuD$it;F>B*T^y- zz*>+|a91k*)3^s-u%GXqVp;TOzPa=ba=e*UpyUPa%>)Wl`B+nzU1WWPIC~ek;ZqLA z_k2iPNLAlI8jC0P7z;fX5rx1u|fyR#mj8BB5l=ny}cge!1f0I%!zv4}kNuT0t zl~TSXr3@Dk2tFz0PoS`AofTpS7g3|%_j+lCXqd5^OV0tv#;*hvf{qY{#yOKWL`vDpSg>v#WBL3>#tKHx=B~4u z+4up*?t!0V?6&KU@wy^~Na9m2`f3=f#AeTgY~p~gkT?8_)` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/docs/todo.rst b/docs/todo.rst new file mode 100644 index 00000000000..122b0336e64 --- /dev/null +++ b/docs/todo.rst @@ -0,0 +1 @@ +.. include:: ../TODO.rst diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 00000000000..f7429027767 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,7 @@ +======== +Usage +======== + +.. automodule:: kolibri.utils.cli + :undoc-members: + :show-inheritance: diff --git a/kolibri/__init__.py b/kolibri/__init__.py new file mode 100755 index 00000000000..77d1b4bd8ab --- /dev/null +++ b/kolibri/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +__author__ = 'Learning Equality' +__email__ = 'info@learningequality.org' +__version__ = '0.0.1' diff --git a/kolibri/__main__.py b/kolibri/__main__.py new file mode 100644 index 00000000000..e3652434316 --- /dev/null +++ b/kolibri/__main__.py @@ -0,0 +1,6 @@ +import sys + +if __name__ == "__main__": + + from kolibri.utils.cli import main + main(args=sys.argv[1:]) diff --git a/kolibri/core/__init__.py b/kolibri/core/__init__.py new file mode 100644 index 00000000000..3e1dbb7dc85 --- /dev/null +++ b/kolibri/core/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import diff --git a/kolibri/core/kolibri_plugin.py b/kolibri/core/kolibri_plugin.py new file mode 100644 index 00000000000..e146ece9c36 --- /dev/null +++ b/kolibri/core/kolibri_plugin.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +The core app of Kolibri also uses the plugin API <3 +""" +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from django.utils.translation import ugettext as _ +from django.core.urlresolvers import reverse + + +from kolibri.plugins.base import KolibriPluginBase +from kolibri.plugins.hooks import NAVIGATION_POPULATE + + +class KolibriCore(KolibriPluginBase): + + def main_navigation(self): + return [{ + 'menu_name': _("Start page"), + 'menu_url': reverse('kolibri:index'), + }] + + def hooks(self): + return { + NAVIGATION_POPULATE: self.main_navigation + } diff --git a/kolibri/core/models.py b/kolibri/core/models.py new file mode 100644 index 00000000000..a3b4b5c610d --- /dev/null +++ b/kolibri/core/models.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + + +from kolibri.plugins import registry +registry.initialize() diff --git a/kolibri/core/templates/kolibri/base.html b/kolibri/core/templates/kolibri/base.html new file mode 100644 index 00000000000..fe953db73c1 --- /dev/null +++ b/kolibri/core/templates/kolibri/base.html @@ -0,0 +1,25 @@ +{% load i18n kolibri_tags %} + + {% block title %}{% endblock %} - {% trans "Kolibri" %} + + + +{% block main_menu %} +
    + {% kolibri_main_navigation as nav %} + + {% for item in nav %} +
  • {{ item.menu_name }}
  • + {% endfor %} + +
+{% endblock %} + +
+ +{% block content %} + +{% endblock %} + + + diff --git a/kolibri/core/templates/kolibri/index.html b/kolibri/core/templates/kolibri/index.html new file mode 100644 index 00000000000..84693a1dfa5 --- /dev/null +++ b/kolibri/core/templates/kolibri/index.html @@ -0,0 +1 @@ +{% extends "kolibri/todo.html" %} diff --git a/kolibri/core/templates/kolibri/todo.html b/kolibri/core/templates/kolibri/todo.html new file mode 100644 index 00000000000..b6b7503483c --- /dev/null +++ b/kolibri/core/templates/kolibri/todo.html @@ -0,0 +1,9 @@ +{% extends "kolibri/base.html" %} + +{% block title %}TODO{% endblock %} + +{% block content %} +

Work in progress

+ +This page is a stub. Meaning something should be here but is not yet complete. +{% endblock %} diff --git a/kolibri/core/templatetags/__init__.py b/kolibri/core/templatetags/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/core/templatetags/kolibri_tags.py b/kolibri/core/templatetags/kolibri_tags.py new file mode 100644 index 00000000000..df0e1ac3000 --- /dev/null +++ b/kolibri/core/templatetags/kolibri_tags.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +""" +Kolibri template tags +===================== + +To use + +.. code-block:: html + + {% load kolibri_tags %} + + + +""" +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from django import template + +register = template.Library() + + +from kolibri.plugins import hooks + + +@register.assignment_tag() +def kolibri_main_navigation(): + + for callback in hooks.get_callables(hooks.NAVIGATION_POPULATE): + for item in callback(): + yield item diff --git a/kolibri/core/urls.py b/kolibri/core/urls.py new file mode 100644 index 00000000000..a343d4ee25b --- /dev/null +++ b/kolibri/core/urls.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url('^', views.IndexView.as_view(), name='index'), + # url('.* ', views.TODOView.as_view()) +] diff --git a/kolibri/core/views/__init__.py b/kolibri/core/views/__init__.py new file mode 100644 index 00000000000..5e27a880335 --- /dev/null +++ b/kolibri/core/views/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.views.generic.base import TemplateView + + +class IndexView(TemplateView): + + template_name = "kolibri/index.html" + + +class TODOView(TemplateView): + """While sketching, use this view to visually inform users that a page + is not yet in place.""" + + template_name = "kolibri/todo.html" diff --git a/kolibri/deployment/__init__.py b/kolibri/deployment/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/deployment/default/__init__.py b/kolibri/deployment/default/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/deployment/default/db.sqlite3 b/kolibri/deployment/default/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..a1a057f31873cfe630782f76ceb39e731503e292 GIT binary patch literal 3072 zcmeHGJx{|h5VeyECg!duiy={qDuKEaP=<;$Ex{c!Ri-h)C?Bn3*x@JgBlsO$kXos& z5K~bHpLDjK@80?J?0dM6l#%dM>rxoFA{|00xdtGFP;?i4Z7uGs0q!mS%P6_{a?UWz zaXyKAj*B&`z(Ez5Iw##;kETXE7P46t_`TbJAG dHPr`w8(Z8eU==tf1?>DE(`(pXtOEb5z&F+HYXblP literal 0 HcmV?d00001 diff --git a/kolibri/deployment/default/settings/__init__.py b/kolibri/deployment/default/settings/__init__.py new file mode 100644 index 00000000000..a8d91ca6988 --- /dev/null +++ b/kolibri/deployment/default/settings/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py new file mode 100644 index 00000000000..df14cba07e2 --- /dev/null +++ b/kolibri/deployment/default/settings/base.py @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- +""" +Django settings for kolibri project. + +Generated by 'django-admin startproject' using Django 1.8.4. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.8/ref/settings/ +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + + +# This is essential! We load the kolibri conf INSIDE the Django conf +from kolibri.utils import conf + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'f@ey3)y^03r9^@mou97apom*+c1m#b1!cwbm50^s4yk72xce27' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'kolibri.core', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + conf.config['INSTALLED_APPS'] + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.security.SecurityMiddleware', +) + +ROOT_URLCONF = 'kolibri.deployment.default.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'kolibri.deployment.default.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.8/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(conf.KOLIBRI_HOME, 'db.sqlite3'), + } +} + + +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.8/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/kolibri/deployment/default/urls.py b/kolibri/deployment/default/urls.py new file mode 100644 index 00000000000..41a3898b254 --- /dev/null +++ b/kolibri/deployment/default/urls.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +"""kolibri URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.8/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Add an import: from blog import urls as blog_urls + 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', include(admin.site.urls)), + url(r'', include('kolibri.core.urls', namespace='kolibri')), +] diff --git a/kolibri/deployment/default/wsgi.py b/kolibri/deployment/default/wsgi.py new file mode 100644 index 00000000000..74218283640 --- /dev/null +++ b/kolibri/deployment/default/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for kolibri project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") + +application = get_wsgi_application() diff --git a/kolibri/logger.py b/kolibri/logger.py new file mode 100644 index 00000000000..5e391c57301 --- /dev/null +++ b/kolibri/logger.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +import logging + +from colorlog import ColoredFormatter + +# TODO: Logging decision. +# The main Kolibri logger always logs to console and does not propagate. + +LOG_LEVEL = logging.DEBUG +LOGFORMAT = " %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s" +logging.root.setLevel(LOG_LEVEL) +formatter = ColoredFormatter(LOGFORMAT) +stream = logging.StreamHandler() +stream.setLevel(LOG_LEVEL) +stream.setFormatter(formatter) +logger = logging.getLogger(__name__) +logger.setLevel(LOG_LEVEL) +logger.addHandler(stream) +logger.propagate = False + +# For now, logging for test output is the same +test_logger = logger diff --git a/kolibri/plugins/__init__.py b/kolibri/plugins/__init__.py new file mode 100644 index 00000000000..a8d91ca6988 --- /dev/null +++ b/kolibri/plugins/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import diff --git a/kolibri/plugins/base.py b/kolibri/plugins/base.py new file mode 100644 index 00000000000..1491e5bffa0 --- /dev/null +++ b/kolibri/plugins/base.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +"""The base of a Kolibri plugin is the inheritence from +:class:`.KolibriPluginBase`. + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + + +class MandatoryPluginMethodNotImplemented(Exception): + + def __init__(self): + NotImplemented.__init__(self, "Plugin needs to define this method") + + +class KolibriPluginBase(object): + """ + This is the base class that all Kolibri plugins need to implement. + """ + + #: Suggested property, not yet in use + migrate_on_enable = False + + #: Suggested property, not yet in use + collect_static_on_enable = False + + #: Suggested property, not yet in use + collect_static_on_enable = False + + def hooks(self): + """ + Return a list of hooks and callables for each hook. To make your plugin + extendible, consider only having hooks that call methods of your plugin + class + """ + return {} + + @classmethod + def enable(cls, kolibri_config): + """Modify the kolibri config dict to your plugin's needs""" + raise MandatoryPluginMethodNotImplemented() + + @classmethod + def disable(cls, kolibri_config): + """Modify the kolibri config dict to your plugin's needs""" + raise MandatoryPluginMethodNotImplemented() diff --git a/kolibri/plugins/example_plugin/__init__.py b/kolibri/plugins/example_plugin/__init__.py new file mode 100644 index 00000000000..3e1dbb7dc85 --- /dev/null +++ b/kolibri/plugins/example_plugin/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py new file mode 100644 index 00000000000..a7ad4493698 --- /dev/null +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +Kolibri example plugin +====================== + +Copy and modify this code for your own plugin. + +""" +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from kolibri.plugins.base import KolibriPluginBase + + +class ExamplePlugin(KolibriPluginBase): + + @classmethod + def enable(cls, config): + print("Activating example plugin") + # Make this automatic and use __name__ ? + config["INSTALLED_APPS"].append("kolibri.plugins.example_plugin") + + @classmethod + def disable(cls, config): + print("Deactivating example plugin") + # Make this automatic and use __name__ ? + config["INSTALLED_APPS"].remove("kolibri.plugins.example_plugin") diff --git a/kolibri/plugins/example_plugin/models.py b/kolibri/plugins/example_plugin/models.py new file mode 100644 index 00000000000..dc487f8d284 --- /dev/null +++ b/kolibri/plugins/example_plugin/models.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.db import models + + +class MyPluginModel(models.Model): + + a_field = models.IntegerField() diff --git a/kolibri/plugins/example_plugin/templates/kolibri/plugins/example_plugin/index.html b/kolibri/plugins/example_plugin/templates/kolibri/plugins/example_plugin/index.html new file mode 100644 index 00000000000..54e6d15820f --- /dev/null +++ b/kolibri/plugins/example_plugin/templates/kolibri/plugins/example_plugin/index.html @@ -0,0 +1,5 @@ +{% extends "kolibri/base.html" %} + +{% block content %} +This is an example +{% endblock %} diff --git a/kolibri/plugins/example_plugin/urls.py b/kolibri/plugins/example_plugin/urls.py new file mode 100644 index 00000000000..39f894c101b --- /dev/null +++ b/kolibri/plugins/example_plugin/urls.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +"""URLs for the Example Plugin + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url('^', views.MyView.as_view(), name='index'), +] diff --git a/kolibri/plugins/example_plugin/views.py b/kolibri/plugins/example_plugin/views.py new file mode 100644 index 00000000000..b78611557bc --- /dev/null +++ b/kolibri/plugins/example_plugin/views.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +"""Views for ExamplePlugin + + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.views.generic.base import TemplateView + + +class MyView(TemplateView): + template_name = "kolibri/plugins/example_plugin/index.html" diff --git a/kolibri/plugins/hooks.py b/kolibri/plugins/hooks.py new file mode 100644 index 00000000000..99b57c5de08 --- /dev/null +++ b/kolibri/plugins/hooks.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +""" +Hooks are used for your plugin's ``hooks()`` method, returning a dictionary +with hooks you wish to use. For instance:: + + from kolibri.plugins.base import KolibriPluginBase + from kolibri.plugins.hooks import NAVIGATION_POPULATE + + class MyPlugin(KolibriPluginBase): + + def my_navigation(self, navigation_items): + navigation_items.append( + { + 'menu_name': _("My list"), + 'menu_url': reverse_lazy("my_plugin:list_of_things") + } + ) + + def hooks(self): + return { + NAVIGATION_POPULATE: self.my_navigation + } +""" +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +__hook_index = -1 +def __enumerate_hook(): + global __hook_index + __hook_index += 1 + return __hook_index + +# : Assign to a callable ``my_func(navigation)``. +NAVIGATION_POPULATE = __enumerate_hook() + +REGISTERED_HOOKS = { + x: [] for x in range(__hook_index + 1) +} + +def register_hook(hook, callback): + """ + Takes a hook identifier and adds it to the registry + """ + if callback not in REGISTERED_HOOKS[hook]: + REGISTERED_HOOKS[hook].append(callback) + else: + raise RuntimeError("Callback already registered") + + +def get_callables(hook): + return REGISTERED_HOOKS[hook] diff --git a/kolibri/plugins/registry.py b/kolibri/plugins/registry.py new file mode 100644 index 00000000000..3a498973c7c --- /dev/null +++ b/kolibri/plugins/registry.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +"""TODO: Write something about this module (everything in the docstring +enters the docs) + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +import importlib + +from django.conf import settings + +from kolibri.logger import logger + +from . import hooks +from .base import KolibriPluginBase + +registry = {} + +__initialized = False + +def initialize(): + global __initialized + + if not __initialized: + logger.debug("Loading kolibri plugin registry...") + + for app in settings.INSTALLED_APPS: + try: + plugin_module = importlib.import_module(app + ".kolibri_plugin") + logger.debug("Loaded kolibri plugin: {}".format(app)) + plugin_classes = [] + for obj in plugin_module.__dict__.values(): + if type(obj) == type and obj is not KolibriPluginBase and issubclass(obj, KolibriPluginBase): + plugin_classes.append(obj) + for plugin_klass in plugin_classes: + plugin_obj = plugin_klass() + for hook, callback in plugin_obj.hooks().items(): + hooks.register_hook(hook, callback) + except ImportError: + pass + + __initialized = True diff --git a/kolibri/test/__init__.py b/kolibri/test/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/test/test_basic.py b/kolibri/test/test_basic.py new file mode 100755 index 00000000000..80024d42cac --- /dev/null +++ b/kolibri/test/test_basic.py @@ -0,0 +1,22 @@ +""" +Tests for `kolibri` module. +""" +import logging +# import pytest +# import kolibri + +logger = logging.getLogger('kolibri_tests') + + +class TestKolibri_prototype(object): + + @classmethod + def setup_class(cls): + pass + + def test_something(self): + logger.debug("This is the main Kolibri integration tests") + + @classmethod + def teardown_class(cls): + pass diff --git a/kolibri/utils/__init__.py b/kolibri/utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py new file mode 100644 index 00000000000..f544c08ebe3 --- /dev/null +++ b/kolibri/utils/cli.py @@ -0,0 +1,175 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals +import importlib +from kolibri.plugins.base import KolibriPluginBase + +USAGE = """ +Kolibri + +Supported by Foundation for Learning Equality +www.learningequality.org + +Usage: + kolibri start [--foreground --watch] [options] [-- DJANGO_OPTIONS ...] + kolibri stop [options] [-- DJANGO_OPTIONS ...] + kolibri restart [options] [-- DJANGO_OPTIONS ...] + kolibri status [options] + kolibri shell [options] [-- DJANGO_OPTIONS ...] + kolibri manage [options] COMMAND [-- DJANGO_OPTIONS ...] + kolibri diagnose [options] + kolibri plugin PLUGIN (enable | disable) + kolibri plugin --list + kolibri -h | --help + kolibri --version + +Options: + -h --help Show this screen. + --version Show version. + COMMAND The name of any available django manage command. For + help, type `kolibri manage help` + --debug Output debug messages (for development) + --port= Use a non-default port on which to start the HTTP server + or to query an existing server (stop/status) + DJANGO_OPTIONS All options are passed on to the django manage command. + Notice that all django options must appear *last* and + should not be mixed with other options. Only long-name + options ('--long-name') are supported. + +Examples: + kolibri start Start Kolibri + kolibri stop Stop Kolibri + kolibri status How is Kolibri doing? + kolibri url Tell me the address of Kolibri + kolibri shell Display a Django shell + kolibri manage help Show the Django management usage dialogue + kolibri manage runserver Runs Django's development server + kolibri diagnose Show system information for debugging + + +Environment: + + DJANGO_SETTINGS_MODULE + - The Django settings module to load. Useful if you are deploying Kolibri + in a specific setup such as your own web server. + - Default: "kolibri.deployment.default.settings.base" + + KOLIBRI_HOME + - Where Kolibri will store its data and configuration files. If you are using + an external drive + + +""" + +__doc__ = """ +Kolibri Command Line Interface (CLI) +==================================== + +Auto-generated usage instructions from ``kolibri -h``:: + +{usage:s} + +""".format(usage="\n".join(map(lambda x: " " + x, USAGE.split("\n")))) + +import os +import signal +import sys +import kolibri + +from docopt import docopt + + +# Set default env +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") +os.environ.setdefault("KOLIBRI_HOME", os.path.join(os.path.expanduser("~"), ".kalite")) +os.environ.setdefault("KOLIBRI_LISTEN_PORT", "8008") + + +from kolibri.logger import logger + + +def manage(cmd, args=[]): + """ + Invokes a django command + + :param: cmd: The command to invoke, for instance "runserver" + :param: args: arguments for the command + """ + # Set sys.argv to correctly reflect the way we invoke kolibri as a Python + # module + sys.argv = ["-m", "kolibri"] + sys.argv[1:] + from django.core.management import execute_from_command_line + argv = ['kolibri manage', cmd] + args + execute_from_command_line(argv=argv) + + +def plugin(plugin_name, args): + """ + Receives a plugin identifier and tries to load its main class. Calls class + functions. + """ + from kolibri.utils import conf + plugin_classes = [] + + # Try to load kolibri_plugin from given plugin module identifier + try: + plugin_module = importlib.import_module(plugin_name + ".kolibri_plugin") + for obj in plugin_module.__dict__.values(): + if type(obj) == type and obj is not KolibriPluginBase and issubclass(obj, KolibriPluginBase): + plugin_classes.append(obj) + except ImportError: + raise RuntimeError("Plugin does not exist") + + if args['enable']: + for klass in plugin_classes: + klass.enable(conf.config) + + if args['disable']: + for klass in plugin_classes: + klass.disable(conf.config) + + conf.save() + + +def main(args=None): + """ + Kolibri's main function. Parses arguments and calls utility functions. + Utility functions should be callable for unit testing purposes, but remember + to use main() for integration tests in order to test the argument API. + """ + + if not args: + args = sys.argv[1:] + + signal.signal(signal.SIGINT, signal.SIG_DFL) + + # Split out the parts of the argument list that we pass on to Django + # and don't feed to docopt. + if '--' in args: + pivot = args.index('--') + args, django_args = args[:pivot], args[pivot:] + else: + django_args = [] + + docopt_kwargs = dict( + version=str(kolibri.__version__), + options_first=False, + ) + + if args: + docopt_kwargs['argv'] = args + + arguments = docopt(USAGE, **docopt_kwargs) + + if arguments['manage']: + command = arguments['COMMAND'] + manage(command, args=django_args) + return + + if arguments['plugin']: + plugin_name = arguments['PLUGIN'] + plugin(plugin_name, arguments) + return + + logger.info(arguments) diff --git a/kolibri/utils/conf.py b/kolibri/utils/conf.py new file mode 100644 index 00000000000..ec3cc3da34d --- /dev/null +++ b/kolibri/utils/conf.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +"""Reading and writing of kolibri configuration. + +TODO: We need to figure out our conf API. Do we store in ini/json/yaml? + + * How do we retrieve config data? + * When should configuration files be loaded and written? + +This module should be easier to document, for instance by having VARIABLES +instead of a dict. + +.. moduleauthor:: Learning Equality + +""" +from __future__ import print_function +from __future__ import unicode_literals +from __future__ import absolute_import + +import os +import json + +KOLIBRI_HOME = os.environ["KOLIBRI_HOME"] + +conf_file = os.path.join(KOLIBRI_HOME, "kolibri_settings.json") +if not os.path.isfile(conf_file): + open(conf_file, "w").write("{}") + +#: Set defaults before updating the dict +config = {} + +#: Everything in this list is added to django.conf.settings.INSTALLED_APPS +config['INSTALLED_APPS'] = [] + +#: Well-known plugin names that are automatically searched for and enabled on +#: first-run. +config['AUTO_SEARCH_PLUGINS'] = ['some.plugin.module.path'] + +#: If a config file does not exist, we assume it's the first run +config['FIRST_RUN'] = True + +# Open up the config file and overwrite defaults +with open(conf_file, 'r') as kolibri_conf_file: + config.update(json.load(kolibri_conf_file)) + +def save(first_run=False): + """Saves the current state of the configuration""" + config['FIRST_RUN'] = first_run + with open(conf_file, 'w') as kolibri_conf_file: + json.dump(config, kolibri_conf_file) diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000000..f78a01a4e96 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +testpaths = test/ kolibri/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000..5603c3777cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +-r requirements/base.txt diff --git a/requirements/base.txt b/requirements/base.txt new file mode 100644 index 00000000000..5f6587590c7 --- /dev/null +++ b/requirements/base.txt @@ -0,0 +1,5 @@ +# Kolibri runtime requirements +wheel>=0.22 +docopt +colorlog==2.6.0 +django>=1.8,<1.9 diff --git a/requirements/dev.txt b/requirements/dev.txt new file mode 100644 index 00000000000..a3e81b8dcf5 --- /dev/null +++ b/requirements/dev.txt @@ -0,0 +1 @@ +-r base.txt diff --git a/requirements/docs.txt b/requirements/docs.txt new file mode 100644 index 00000000000..5b8825ddbe9 --- /dev/null +++ b/requirements/docs.txt @@ -0,0 +1,5 @@ +-r base.txt + +# These are for building the docs +sphinx +sphinx_rtd_theme diff --git a/requirements/test.txt b/requirements/test.txt new file mode 100644 index 00000000000..887744312c5 --- /dev/null +++ b/requirements/test.txt @@ -0,0 +1,7 @@ +-r base.txt +# These are for testing +pytest +pytest-django +pytest-cov +pep8 +pyflakes diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..24776bfc9d4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[wheel] +universal = 1 + +[aliases] +test = pytest + +[flake8] +ignore = E226,E302,E41 +max-line-length = 160 +max-complexity = 10 + +[pep8] +ignore = E226,E302,E41,E402 +max-line-length = 160 +exclude = kolibri/*/migrations/* diff --git a/setup.py b/setup.py new file mode 100644 index 00000000000..4d6ce9a46c3 --- /dev/null +++ b/setup.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import sys + +from setuptools import setup +from setuptools.command.test import test as TestCommand + + +readme = open('README.rst').read() +doclink = """ +Documentation +------------- + +The full documentation is at http://kolibri_skeleton.rtfd.org.""" +history = open('CHANGELOG.rst').read().replace('.. :changelog:', '') + +setup( + name='kolibri', + version='0.0.1', + description='Kolibri', + long_description=readme + '\n\n' + doclink + '\n\n' + history, + author='Learning Equality', + author_email='info@learningequality.org', + url='https://github.com/benjaoming/kolibri_skeleton', + packages=[ + 'kolibri', + ], + entry_points={ + 'console_scripts': [ + 'kolibri = kolibri.utils.cli:main' + ] + }, + package_dir={'kolibri': 'kolibri'}, + include_package_data=True, + install_requires=[ + 'docopt', + 'colorlog', + ], + setup_requires=['pytest-runner'], + tests_require=['pytest', 'tox', 'pep8', 'pyflakes', 'docopt', 'colorlog'], + license='MIT', + zip_safe=False, + keywords='kolibri', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: Implementation :: PyPy', + ], +) diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/test_cli.py b/test/test_cli.py new file mode 100755 index 00000000000..cd66efb7a3c --- /dev/null +++ b/test/test_cli.py @@ -0,0 +1,35 @@ +""" +Tests for `kolibri` module. +""" +import os +import shutil +import tempfile +import unittest + +from kolibri.logger import test_logger + +logger = test_logger + + +from kolibri.utils.cli import main + + +class TestKolibriCLI(unittest.TestCase): + + @classmethod + def setup_class(cls): + os.environ["KOLIBRI_HOME"] = tempfile.mkdtemp() + + def test_cli(self): + logger.debug("This is a unit test in the main Kolibri app space") + # Test the -h + with self.assertRaises(SystemExit): + main("-h") + + def test_plugin_cli(self): + main(("plugin", "kolibri.plugins.example_plugin", "enable")) + main(("plugin", "kolibri.plugins.example_plugin", "disable")) + + @classmethod + def teardown_class(cls): + shutil.rmtree(os.environ["KOLIBRI_HOME"]) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000000..d01584f0e4d --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +[tox] +envlist = py{2.7,3.4,3.5,pypy}, lint, docs + +[testenv] +basepython = + py2.7: python2.7 + py3.4: python3.4 + py3.5: python3.5 + pypypy: pypy + docs: python2.7 + lint: python +deps = + -r{toxinidir}/requirements/test.txt +commands = + py.test --cov=kolibri {posargs} + +[testenv:lint] +deps = + flake8 +commands = + flake8 kolibri + +[testenv:docs] +changedir=docs/ +deps = + -r{toxinidir}/requirements/docs.txt +commands = + sphinx-build -b linkcheck ./ _build/ + # sphinx-build -b html ./ _build/ From 84e3d3295c6367242d44f813767d452d24141274 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 03:46:19 +0100 Subject: [PATCH 02/32] rm print stm --- kolibri/plugins/example_plugin/kolibri_plugin.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py index a7ad4493698..6c891ffab2b 100644 --- a/kolibri/plugins/example_plugin/kolibri_plugin.py +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -10,7 +10,11 @@ from __future__ import print_function from __future__ import unicode_literals + +from django.utils.translation import ugettext as _ + from kolibri.plugins.base import KolibriPluginBase +from kolibri.plugins.hooks import NAVIGATION_POPULATE class ExamplePlugin(KolibriPluginBase): @@ -26,3 +30,14 @@ def disable(cls, config): print("Deactivating example plugin") # Make this automatic and use __name__ ? config["INSTALLED_APPS"].remove("kolibri.plugins.example_plugin") + + def main_navigation(self): + return [{ + 'menu_name': _("Google"), + 'menu_url': 'http://google.com', + }] + + def hooks(self): + return { + NAVIGATION_POPULATE: self.main_navigation + } From f2f749dd36dddad73e89e7dbe35578001d95d7e7 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 03:49:38 +0100 Subject: [PATCH 03/32] learn to use flake8 ben --- kolibri/core/templatetags/kolibri_tags.py | 4 ++-- kolibri/utils/cli.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/kolibri/core/templatetags/kolibri_tags.py b/kolibri/core/templatetags/kolibri_tags.py index df0e1ac3000..36038fdc8e5 100644 --- a/kolibri/core/templatetags/kolibri_tags.py +++ b/kolibri/core/templatetags/kolibri_tags.py @@ -22,10 +22,10 @@ from django import template -register = template.Library() +from kolibri.plugins import hooks -from kolibri.plugins import hooks +register = template.Library() @register.assignment_tag() diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py index f544c08ebe3..ffb796a0a84 100644 --- a/kolibri/utils/cli.py +++ b/kolibri/utils/cli.py @@ -2,8 +2,15 @@ from __future__ import absolute_import from __future__ import print_function from __future__ import unicode_literals + + import importlib -from kolibri.plugins.base import KolibriPluginBase +import os +import signal +import sys +import kolibri + +from docopt import docopt USAGE = """ Kolibri @@ -72,13 +79,6 @@ """.format(usage="\n".join(map(lambda x: " " + x, USAGE.split("\n")))) -import os -import signal -import sys -import kolibri - -from docopt import docopt - # Set default env os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") @@ -86,7 +86,8 @@ os.environ.setdefault("KOLIBRI_LISTEN_PORT", "8008") -from kolibri.logger import logger +from kolibri.logger import logger # NOQA +from kolibri.plugins.base import KolibriPluginBase # NOQA def manage(cmd, args=[]): From 5451981d0259525847a00c04fae2cd5c82e226fb Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 03:56:38 +0100 Subject: [PATCH 04/32] disable pypy testing --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 52362c201f5..75202251c01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,8 @@ python: - "3.4" - "3.5" - "2.7" - - "pypy" +# pypy testing currently breaks because of the tempfile dir used for KALITE_HOME +# - "pypy" before_install: - pip install codecov From ddecc974c6561e2babdb89c7a647df6ef4fa5c3e Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 04:00:01 +0100 Subject: [PATCH 05/32] Update badges to use leq repo [ci skip] --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 49407df38e7..6896110d5c3 100644 --- a/README.rst +++ b/README.rst @@ -1,10 +1,10 @@ Kolibri ============================= -.. image:: https://travis-ci.org/benjaoming/kolibri_skeleton.svg - :target: https://travis-ci.org/benjaoming/kolibri_skeleton -.. image:: http://codecov.io/github/benjaoming/kolibri_skeleton/coverage.svg?branch=master - :target: http://codecov.io/github/benjaoming/kolibri_skeleton?branch=master +.. image:: https://travis-ci.org/learningequality/kolibri.svg + :target: https://travis-ci.org/learningequality/kolibri +.. image:: http://codecov.io/github/learningequality/kolibri/coverage.svg?branch=master + :target: http://codecov.io/github/learningequality/kolibri?branch=master .. image:: https://readthedocs.org/projects/kolibri/badge/?version=latest :target: http://kolibri.readthedocs.org/en/latest/ From 9f163c3b720c8f497ed39293c9bcd0e992f5727b Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 15:31:19 +0100 Subject: [PATCH 06/32] Remove solved items from TODO [ci skip] --- TODO.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO.rst b/TODO.rst index a234ffa1279..6ae42cfea11 100644 --- a/TODO.rst +++ b/TODO.rst @@ -8,9 +8,6 @@ Skeleton TODO - Hooks? - Logging in general - Logging in tests - - Test framework and --capture - - Add codecov-io - - pytest.ini - sketch out kolibri command - implement settings pattern - python setup.py sdist bdist_wininst upload From fa8e634546c64ca9488c979ed013bd1e87f8ff48 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 21 Jan 2016 16:09:18 +0100 Subject: [PATCH 07/32] clean up deps and use only flake8 for lint checks --- Makefile | 3 +-- requirements/dev.txt | 1 + requirements/test.txt | 2 -- setup.py | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8f8fbd53b67..9d94f5f067e 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,7 @@ clean-docs: $(MAKE) -C docs clean lint: - python3 -m pyflakes kolibri - pep8 kolibri test + flake8 kolibri test: python setup.py test diff --git a/requirements/dev.txt b/requirements/dev.txt index a3e81b8dcf5..a0c91a1adf6 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1 +1,2 @@ -r base.txt +flake8 diff --git a/requirements/test.txt b/requirements/test.txt index 887744312c5..eaa9d899990 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -3,5 +3,3 @@ pytest pytest-django pytest-cov -pep8 -pyflakes diff --git a/setup.py b/setup.py index 4d6ce9a46c3..d983aa17015 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ 'colorlog', ], setup_requires=['pytest-runner'], - tests_require=['pytest', 'tox', 'pep8', 'pyflakes', 'docopt', 'colorlog'], + tests_require=['pytest', 'tox', 'flake8'], license='MIT', zip_safe=False, keywords='kolibri', From 2683c38eb3d0af0c4d6200a4967ec8ed34f8fb0c Mon Sep 17 00:00:00 2001 From: Michael Gallaspy Date: Thu, 21 Jan 2016 16:25:19 -0800 Subject: [PATCH 08/32] Demonstrate `hooks` as property & plugin inheritance Also adds quite a few docstrings. --- kolibri/core/kolibri_plugin.py | 27 +++++---- .../plugins/example_plugin/kolibri_plugin.py | 57 ++++++++++++++++++- kolibri/plugins/hooks.py | 11 +++- kolibri/plugins/registry.py | 25 ++++++-- 4 files changed, 102 insertions(+), 18 deletions(-) diff --git a/kolibri/core/kolibri_plugin.py b/kolibri/core/kolibri_plugin.py index e146ece9c36..4e5c382bf5f 100644 --- a/kolibri/core/kolibri_plugin.py +++ b/kolibri/core/kolibri_plugin.py @@ -14,15 +14,22 @@ from kolibri.plugins.hooks import NAVIGATION_POPULATE -class KolibriCore(KolibriPluginBase): +def main_navigation(): + """ + Callback for the plugin below + :return: A list of nav menu items used in the NAVIGATION_POPULATE hook. + """ + return [{ + 'menu_name': _("Start page"), + 'menu_url': reverse('kolibri:index'), + }] - def main_navigation(self): - return [{ - 'menu_name': _("Start page"), - 'menu_url': reverse('kolibri:index'), - }] - def hooks(self): - return { - NAVIGATION_POPULATE: self.main_navigation - } +class KolibriCore(KolibriPluginBase): + """ + The most minimal plugin possible. Because it's in the core, it doesn't define ``enable`` or ``disable``. Those + methods should never be called for this plugin. + """ + hooks = { + NAVIGATION_POPULATE: main_navigation + } diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py index 6c891ffab2b..65618158c5f 100644 --- a/kolibri/plugins/example_plugin/kolibri_plugin.py +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -17,27 +17,80 @@ from kolibri.plugins.hooks import NAVIGATION_POPULATE -class ExamplePlugin(KolibriPluginBase): +class NavMenuPlugin(KolibriPluginBase): + """ + An example plugin that demonstrates how the Kolibri plugin system works. Adds items to the nav menu by registering + a callback to the NAVIGATION_POPULATE hook. + """ @classmethod def enable(cls, config): + """ + A plugin must implement this abstract method. It's called by the command ``kolibri plugin enable`` to + modify the kolibri settings file. + + :param config: A dictionary of settings, like the one at ``django.conf.settings``. + :return: Nothing, though it may modify the mutable config parameter + """ print("Activating example plugin") # Make this automatic and use __name__ ? config["INSTALLED_APPS"].append("kolibri.plugins.example_plugin") @classmethod def disable(cls, config): + """ + A plugin must implement this abstract method. It's called by the command ``kolibri plugin disable`` to + modify the kolibri settings file. + + :param config: A dictionary of settings, like the one at ``django.conf.settings``. + :return: Nothing, though it may modify the mutable config parameter + """ print("Deactivating example plugin") # Make this automatic and use __name__ ? config["INSTALLED_APPS"].remove("kolibri.plugins.example_plugin") - def main_navigation(self): + @staticmethod + def main_navigation(): + """ + A callback registered in the ``hooks`` property of this class. It's defined as a method instead of a + module-level function in order to allow other plugins to inherit this class and change the behavior. + """ return [{ 'menu_name': _("Google"), 'menu_url': 'http://google.com', }] + @property def hooks(self): + """ + Normally ``hooks`` should be an attribute -- here we use the ``property`` decorator to simulate that. + This allows the callback to be changed by subclasses without changing the ``hooks`` attribute. + """ return { NAVIGATION_POPULATE: self.main_navigation } + + +class ExtendedPlugin(NavMenuPlugin): + """ + Demonstrates plugin inheritance. Notice that the ``hooks`` attribute need not be changed -- only the callback. + """ + @classmethod + def enable(cls, config): + pass + + @classmethod + def disable(cls, config): + pass + + def main_navigation(self): + return [ + { + 'menu_name': _('Disney'), + 'menu_url': 'http://disney.com', + }, + { + 'menu_name': _('Yahoo'), + 'menu_url': 'http://yahoo.com', + } + ] diff --git a/kolibri/plugins/hooks.py b/kolibri/plugins/hooks.py index 99b57c5de08..917276bcd8a 100644 --- a/kolibri/plugins/hooks.py +++ b/kolibri/plugins/hooks.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -Hooks are used for your plugin's ``hooks()`` method, returning a dictionary -with hooks you wish to use. For instance:: +Hooks are used for your plugin's ``hooks`` attribute, a dictionary +with hooks you wish to use. The keys are pre-defined constants in this module or arbitrary strings. For instance:: from kolibri.plugins.base import KolibriPluginBase from kolibri.plugins.hooks import NAVIGATION_POPULATE @@ -26,6 +26,8 @@ def hooks(self): from __future__ import unicode_literals __hook_index = -1 + + def __enumerate_hook(): global __hook_index __hook_index += 1 @@ -38,6 +40,7 @@ def __enumerate_hook(): x: [] for x in range(__hook_index + 1) } + def register_hook(hook, callback): """ Takes a hook identifier and adds it to the registry @@ -49,4 +52,8 @@ def register_hook(hook, callback): def get_callables(hook): + """ + :param hook: The hook identifier, either a constant from this module or an arbitrary string. + :return: An iterable of callbacks. + """ return REGISTERED_HOOKS[hook] diff --git a/kolibri/plugins/registry.py b/kolibri/plugins/registry.py index 3a498973c7c..b6ce59a4fac 100644 --- a/kolibri/plugins/registry.py +++ b/kolibri/plugins/registry.py @@ -1,8 +1,22 @@ # -*- coding: utf-8 -*- -"""TODO: Write something about this module (everything in the docstring -enters the docs) +""" +Plugins are initialized once when the server starts. Here are the initilization steps: + +1. Each module listed in INSTALLED_APPS (including those listed in the kolibri conf file) is searched for the special + ``kolibri_plugin`` module. +2. For each class in the module which inherits from ``KolibriPluginBase``, it's ``hooks`` method is called to inspect + which hooks it defines. +3. The callback assigned by the plugin class to the hook is registered in a module variable. +4. At the appropriate time (see below) the callbacks for a given hook are all called. + +A few notes: -.. moduleauthor:: Learning Equality +* Kolibri defines some hooks that are used in the core app. These can be found in the kolibri.plugins.registry module. +* Arbitrary new hooks can be defined. At the Python level they're just dictionary keys. *Do not* user integers for + hook names -- those are reserved for the hooks defined by the Kolibri core. *Do* namespace your hooks! +* *When* hook callbacks are called are entirely up to the hook definer. The core Kolibri app documents what hooks it + calls and when -- you can call core Kolibri hooks in your plugins too! +* Callbacks *should* be called in the same order every time, but this is not a promise! """ from __future__ import print_function @@ -23,6 +37,9 @@ __initialized = False def initialize(): + """ + Called once to register hook callbacks. + """ global __initialized if not __initialized: @@ -38,7 +55,7 @@ def initialize(): plugin_classes.append(obj) for plugin_klass in plugin_classes: plugin_obj = plugin_klass() - for hook, callback in plugin_obj.hooks().items(): + for hook, callback in plugin_obj.hooks.items(): hooks.register_hook(hook, callback) except ImportError: pass From f3e6c790873f38c769672d0d4d17b6725a2a180c Mon Sep 17 00:00:00 2001 From: Michael Gallaspy Date: Thu, 21 Jan 2016 16:53:30 -0800 Subject: [PATCH 09/32] Add Plugins documentation --- docs/dev/plugins.rst | 38 +++++++++++++++++++ docs/index.rst | 1 + .../plugins/example_plugin/kolibri_plugin.py | 11 ++++-- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 docs/dev/plugins.rst diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst new file mode 100644 index 00000000000..68c5e1dbce2 --- /dev/null +++ b/docs/dev/plugins.rst @@ -0,0 +1,38 @@ +Plugins +======= + +The behavior of Kolibri can be extended using plugins. + +How plugins work +---------------- + +.. automodule:: kolibri.plugins.registry + +Enabling and disabling plugins +------------------------------ + +Non-core plugins can be enabled or disabled using the ``kolibri plugin`` command. See doc`usage`. + +Other stuff you can do with plugins +----------------------------------- + +Plugins can be standalone Django apps in their own right, meaning they can define templates, models, new urls, and +views just like any other app. However the API for all of this hasn't yet been determined... Coming soon! + + +Core plugin example +------------------- + +View the source to learn more! + +.. automodule:: kolibri.core.kolibri_plugin + :members: + +Extended example, with inheritance +---------------------------------- + +View the source to learn more! + +.. automodule:: kolibri.plugins.example_plugin.kolibri_plugin + :members: NavMenuPlugin, ExtendedPlugin + :show-inheritance: \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index edbb82d4089..50015968ba1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,6 +9,7 @@ Contents: :maxdepth: 1 installation + dev/plugins usage contributing authors diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py index 65618158c5f..1b242e9cf49 100644 --- a/kolibri/plugins/example_plugin/kolibri_plugin.py +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- """ -Kolibri example plugin -====================== - Copy and modify this code for your own plugin. - """ from __future__ import absolute_import from __future__ import print_function @@ -54,6 +50,8 @@ def main_navigation(): """ A callback registered in the ``hooks`` property of this class. It's defined as a method instead of a module-level function in order to allow other plugins to inherit this class and change the behavior. + + :return: A list of nav menu items used in the NAVIGATION_POPULATE hook. """ return [{ 'menu_name': _("Google"), @@ -84,6 +82,11 @@ def disable(cls, config): pass def main_navigation(self): + """ + This method is overrided to return additional menu items using the core NAVIGATION_POPULATE hook. + + :return: A list of nav menu items used in the NAVIGATION_POPULATE hook. + """ return [ { 'menu_name': _('Disney'), From 61459cd52f8311dbdd64e86d058f5e9ff68d9077 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Fri, 22 Jan 2016 21:58:18 +0100 Subject: [PATCH 10/32] add isort cfg and run it on the current source --- kolibri/core/kolibri_plugin.py | 7 ++----- kolibri/core/models.py | 6 ++---- kolibri/core/templatetags/kolibri_tags.py | 5 +---- kolibri/core/urls.py | 4 +--- kolibri/deployment/default/settings/base.py | 5 +---- kolibri/deployment/default/urls.py | 4 +--- kolibri/logger.py | 4 +--- kolibri/plugins/base.py | 4 +--- kolibri/plugins/example_plugin/kolibri_plugin.py | 5 +---- kolibri/plugins/example_plugin/models.py | 4 +--- kolibri/plugins/example_plugin/urls.py | 4 +--- kolibri/plugins/example_plugin/views.py | 4 +--- kolibri/plugins/hooks.py | 4 +--- kolibri/plugins/registry.py | 4 +--- kolibri/test/test_basic.py | 1 + kolibri/utils/conf.py | 6 ++---- setup.cfg | 7 +++++++ setup.py | 1 - 18 files changed, 26 insertions(+), 53 deletions(-) diff --git a/kolibri/core/kolibri_plugin.py b/kolibri/core/kolibri_plugin.py index 4e5c382bf5f..79298dcec32 100644 --- a/kolibri/core/kolibri_plugin.py +++ b/kolibri/core/kolibri_plugin.py @@ -2,13 +2,10 @@ """ The core app of Kolibri also uses the plugin API <3 """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, print_function, unicode_literals -from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse - +from django.utils.translation import ugettext as _ from kolibri.plugins.base import KolibriPluginBase from kolibri.plugins.hooks import NAVIGATION_POPULATE diff --git a/kolibri/core/models.py b/kolibri/core/models.py index a3b4b5c610d..73a652a70bc 100644 --- a/kolibri/core/models.py +++ b/kolibri/core/models.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import - +from __future__ import absolute_import, print_function, unicode_literals from kolibri.plugins import registry + registry.initialize() diff --git a/kolibri/core/templatetags/kolibri_tags.py b/kolibri/core/templatetags/kolibri_tags.py index 36038fdc8e5..13b3672772a 100644 --- a/kolibri/core/templatetags/kolibri_tags.py +++ b/kolibri/core/templatetags/kolibri_tags.py @@ -16,15 +16,12 @@ """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, print_function, unicode_literals from django import template from kolibri.plugins import hooks - register = template.Library() diff --git a/kolibri/core/urls.py b/kolibri/core/urls.py index a343d4ee25b..02eba8985d2 100644 --- a/kolibri/core/urls.py +++ b/kolibri/core/urls.py @@ -5,9 +5,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals from django.conf.urls import url diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py index df14cba07e2..3d106b40cc2 100644 --- a/kolibri/deployment/default/settings/base.py +++ b/kolibri/deployment/default/settings/base.py @@ -10,14 +10,11 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os - # This is essential! We load the kolibri conf INSIDE the Django conf from kolibri.utils import conf diff --git a/kolibri/deployment/default/urls.py b/kolibri/deployment/default/urls.py index 41a3898b254..c66abdd2a99 100644 --- a/kolibri/deployment/default/urls.py +++ b/kolibri/deployment/default/urls.py @@ -17,9 +17,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals from django.conf.urls import include, url from django.contrib import admin diff --git a/kolibri/logger.py b/kolibri/logger.py index 5e391c57301..86ddf839024 100644 --- a/kolibri/logger.py +++ b/kolibri/logger.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals import logging diff --git a/kolibri/plugins/base.py b/kolibri/plugins/base.py index 1491e5bffa0..6192df75749 100644 --- a/kolibri/plugins/base.py +++ b/kolibri/plugins/base.py @@ -5,9 +5,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals class MandatoryPluginMethodNotImplemented(Exception): diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py index 1b242e9cf49..7327b83f489 100644 --- a/kolibri/plugins/example_plugin/kolibri_plugin.py +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -2,10 +2,7 @@ """ Copy and modify this code for your own plugin. """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals - +from __future__ import absolute_import, print_function, unicode_literals from django.utils.translation import ugettext as _ diff --git a/kolibri/plugins/example_plugin/models.py b/kolibri/plugins/example_plugin/models.py index dc487f8d284..1bdfeb5543b 100644 --- a/kolibri/plugins/example_plugin/models.py +++ b/kolibri/plugins/example_plugin/models.py @@ -5,9 +5,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals from django.db import models diff --git a/kolibri/plugins/example_plugin/urls.py b/kolibri/plugins/example_plugin/urls.py index 39f894c101b..f53da9a1c4b 100644 --- a/kolibri/plugins/example_plugin/urls.py +++ b/kolibri/plugins/example_plugin/urls.py @@ -4,9 +4,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals from django.conf.urls import url diff --git a/kolibri/plugins/example_plugin/views.py b/kolibri/plugins/example_plugin/views.py index b78611557bc..cfd59205813 100644 --- a/kolibri/plugins/example_plugin/views.py +++ b/kolibri/plugins/example_plugin/views.py @@ -5,9 +5,7 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals from django.views.generic.base import TemplateView diff --git a/kolibri/plugins/hooks.py b/kolibri/plugins/hooks.py index 917276bcd8a..77638003e52 100644 --- a/kolibri/plugins/hooks.py +++ b/kolibri/plugins/hooks.py @@ -21,9 +21,7 @@ def hooks(self): NAVIGATION_POPULATE: self.my_navigation } """ -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __hook_index = -1 diff --git a/kolibri/plugins/registry.py b/kolibri/plugins/registry.py index b6ce59a4fac..70d78d514ff 100644 --- a/kolibri/plugins/registry.py +++ b/kolibri/plugins/registry.py @@ -19,9 +19,7 @@ * Callbacks *should* be called in the same order every time, but this is not a promise! """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals import importlib diff --git a/kolibri/test/test_basic.py b/kolibri/test/test_basic.py index 80024d42cac..00c54f24996 100755 --- a/kolibri/test/test_basic.py +++ b/kolibri/test/test_basic.py @@ -2,6 +2,7 @@ Tests for `kolibri` module. """ import logging + # import pytest # import kolibri diff --git a/kolibri/utils/conf.py b/kolibri/utils/conf.py index ec3cc3da34d..99d1b61a7bb 100644 --- a/kolibri/utils/conf.py +++ b/kolibri/utils/conf.py @@ -12,12 +12,10 @@ .. moduleauthor:: Learning Equality """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals -import os import json +import os KOLIBRI_HOME = os.environ["KOLIBRI_HOME"] diff --git a/setup.cfg b/setup.cfg index 24776bfc9d4..c9ae42ff37a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,3 +13,10 @@ max-complexity = 10 ignore = E226,E302,E41,E402 max-line-length = 160 exclude = kolibri/*/migrations/* + +[isort] +atomic = true +multi_line_output = 5 +line_length = 79 +combine_as_imports = true +skip = wsgi.py,docs,env,cli.py,test,.eggs,build diff --git a/setup.py b/setup.py index d983aa17015..2ea3ccedd6a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ from setuptools import setup from setuptools.command.test import test as TestCommand - readme = open('README.rst').read() doclink = """ Documentation From 515c0dabe3f884a9874110e4ccd4028494ef1a8e Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 16:56:48 +0100 Subject: [PATCH 11/32] add PR template and notes on adding to AUTHOR and CHANGELOG --- CONTRIBUTING.rst | 51 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a69f59fd841..bc3bb6edab0 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -91,14 +91,53 @@ Pull Request Guidelines Before you submit a pull request, check that it meets these guidelines: -1. The pull request should include tests. -2. If the pull request adds functionality, the docs should be updated. Put +1. For your pull request description on Github, consider using our + template, see :ref:`prtemplate`. +2. Remember to add yourself to ``AUTHORS.rst`` and fill in ``CHANGELOG.rst`` + with your feature or bug fix. +3. The pull request should include tests. +4. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. -3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. - Check https://travis-ci.org/learningequality/kolibri - under pull requests for active pull requests or run the ``tox`` command and - make sure that the tests pass for all supported Python versions. +5. The pull request should work for Python 2.7, 3.4, and 3.5, and for PyPy. + PRs will be automatically tested, we recommend running the ``tox`` command + locally before submitting your PR for review. + + +.. _prtemplate: + +Pull Request Template +~~~~~~~~~~~~~~~~~~~~~ + +Copy-paste the following to your Pull Request description on Github:: + + ## Summary + + *Short description* + + ## TODO + + - [ ] Have tests been written for the new code? + - [ ] Has documentation been written/updated? + - [ ] New dependencies (if any) added to requirements file + - [ ] Add an entry to CHANGELOG.rst + - [ ] Add yourself it AUTHORS.rst if you don't appear there + + ## Reviewer guidance + + *If you PR has a significant size, give the reviewer some helpful remarks* + + ## Issues addressed + + List the issues solved or partly solved by the PR + + ## Documentation + + If the PR has documentation, link the file here (either .rst in your repo or if built on Read The Docs) + + ## Screenshots (if appropriate) + + They're nice. :) Tips From 77226d6613e51a725ca3f24741490f5142c4c77d Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 17:01:31 +0100 Subject: [PATCH 12/32] cleanup overkill header and docstring moduleauthor --- kolibri/__init__.py | 2 -- kolibri/core/__init__.py | 7 +------ kolibri/core/kolibri_plugin.py | 1 - kolibri/core/models.py | 1 - kolibri/core/templatetags/kolibri_tags.py | 1 - kolibri/core/urls.py | 4 ---- kolibri/core/views/__init__.py | 8 +------- kolibri/deployment/default/settings/__init__.py | 5 +---- kolibri/deployment/default/settings/base.py | 1 - kolibri/logger.py | 1 - kolibri/plugins/__init__.py | 5 +---- kolibri/plugins/base.py | 4 ---- kolibri/plugins/hooks.py | 1 - kolibri/plugins/registry.py | 1 - kolibri/utils/cli.py | 5 +---- kolibri/utils/conf.py | 3 --- 16 files changed, 5 insertions(+), 45 deletions(-) diff --git a/kolibri/__init__.py b/kolibri/__init__.py index 77d1b4bd8ab..8055bf52f88 100755 --- a/kolibri/__init__.py +++ b/kolibri/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - __author__ = 'Learning Equality' __email__ = 'info@learningequality.org' __version__ = '0.0.1' diff --git a/kolibri/core/__init__.py b/kolibri/core/__init__.py index 3e1dbb7dc85..c2ab8003f1b 100644 --- a/kolibri/core/__init__.py +++ b/kolibri/core/__init__.py @@ -1,10 +1,5 @@ -# -*- coding: utf-8 -*- """TODO: Write something about this module (everything in the docstring enters the docs) -.. moduleauthor:: Learning Equality - """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import print_function, unicode_literals, absolute_import diff --git a/kolibri/core/kolibri_plugin.py b/kolibri/core/kolibri_plugin.py index 79298dcec32..8bc972e5f59 100644 --- a/kolibri/core/kolibri_plugin.py +++ b/kolibri/core/kolibri_plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ The core app of Kolibri also uses the plugin API <3 """ diff --git a/kolibri/core/models.py b/kolibri/core/models.py index 73a652a70bc..0758fc748cb 100644 --- a/kolibri/core/models.py +++ b/kolibri/core/models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals from kolibri.plugins import registry diff --git a/kolibri/core/templatetags/kolibri_tags.py b/kolibri/core/templatetags/kolibri_tags.py index 13b3672772a..79353287336 100644 --- a/kolibri/core/templatetags/kolibri_tags.py +++ b/kolibri/core/templatetags/kolibri_tags.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Kolibri template tags ===================== diff --git a/kolibri/core/urls.py b/kolibri/core/urls.py index 02eba8985d2..41e4099382c 100644 --- a/kolibri/core/urls.py +++ b/kolibri/core/urls.py @@ -1,9 +1,5 @@ -# -*- coding: utf-8 -*- """TODO: Write something about this module (everything in the docstring enters the docs) - -.. moduleauthor:: Learning Equality - """ from __future__ import absolute_import, print_function, unicode_literals diff --git a/kolibri/core/views/__init__.py b/kolibri/core/views/__init__.py index 5e27a880335..4968253e0bb 100644 --- a/kolibri/core/views/__init__.py +++ b/kolibri/core/views/__init__.py @@ -1,13 +1,7 @@ -# -*- coding: utf-8 -*- """TODO: Write something about this module (everything in the docstring enters the docs) - -.. moduleauthor:: Learning Equality - """ -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import print_function, unicode_literals, absolute_import from django.views.generic.base import TemplateView diff --git a/kolibri/deployment/default/settings/__init__.py b/kolibri/deployment/default/settings/__init__.py index a8d91ca6988..e3f5c6f6c0e 100644 --- a/kolibri/deployment/default/settings/__init__.py +++ b/kolibri/deployment/default/settings/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import print_function, unicode_literals, absolute_import diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py index 3d106b40cc2..8abb86a604b 100644 --- a/kolibri/deployment/default/settings/base.py +++ b/kolibri/deployment/default/settings/base.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Django settings for kolibri project. diff --git a/kolibri/logger.py b/kolibri/logger.py index 86ddf839024..b260b86f232 100644 --- a/kolibri/logger.py +++ b/kolibri/logger.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals import logging diff --git a/kolibri/plugins/__init__.py b/kolibri/plugins/__init__.py index a8d91ca6988..e3f5c6f6c0e 100644 --- a/kolibri/plugins/__init__.py +++ b/kolibri/plugins/__init__.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals -from __future__ import absolute_import +from __future__ import print_function, unicode_literals, absolute_import diff --git a/kolibri/plugins/base.py b/kolibri/plugins/base.py index 6192df75749..bf6ce907f26 100644 --- a/kolibri/plugins/base.py +++ b/kolibri/plugins/base.py @@ -1,9 +1,5 @@ -# -*- coding: utf-8 -*- """The base of a Kolibri plugin is the inheritence from :class:`.KolibriPluginBase`. - -.. moduleauthor:: Learning Equality - """ from __future__ import absolute_import, print_function, unicode_literals diff --git a/kolibri/plugins/hooks.py b/kolibri/plugins/hooks.py index 77638003e52..c16050fece9 100644 --- a/kolibri/plugins/hooks.py +++ b/kolibri/plugins/hooks.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Hooks are used for your plugin's ``hooks`` attribute, a dictionary with hooks you wish to use. The keys are pre-defined constants in this module or arbitrary strings. For instance:: diff --git a/kolibri/plugins/registry.py b/kolibri/plugins/registry.py index 70d78d514ff..f203372d19a 100644 --- a/kolibri/plugins/registry.py +++ b/kolibri/plugins/registry.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Plugins are initialized once when the server starts. Here are the initilization steps: diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py index ffb796a0a84..f702ccab3d1 100644 --- a/kolibri/utils/cli.py +++ b/kolibri/utils/cli.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import absolute_import, print_function, unicode_literals import importlib diff --git a/kolibri/utils/conf.py b/kolibri/utils/conf.py index 99d1b61a7bb..82c92bcfb09 100644 --- a/kolibri/utils/conf.py +++ b/kolibri/utils/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Reading and writing of kolibri configuration. TODO: We need to figure out our conf API. Do we store in ini/json/yaml? @@ -9,8 +8,6 @@ This module should be easier to document, for instance by having VARIABLES instead of a dict. -.. moduleauthor:: Learning Equality - """ from __future__ import absolute_import, print_function, unicode_literals From d01d3141e4219578a8ebc4a785a767ff4fa33a20 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 17:02:41 +0100 Subject: [PATCH 13/32] Correctly mention Travis --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6896110d5c3..4c634f79884 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ Software architecture * Using tox to build py 2.7, 3.4, 3.5 and pypy * Automatic linting test (pep8) * Static code analysis check (pyflakes) -* Circle CI +* Travis CI (intention to replace with Circle) * Integration tests are separate from application code in ``test/`` * Unit tests live in ``kolibri/test`` and ``kolibri/plugins/core/plugin_name/tests`` * An example plugin is provided in ``kolibri/plugins/core/example`` From 14fc1f9b83450fdda4a5ba0115594e8c8db98b5a Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 17:28:21 +0100 Subject: [PATCH 14/32] rm more code bloat --- kolibri/__init__.py | 2 ++ kolibri/__main__.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/kolibri/__init__.py b/kolibri/__init__.py index 8055bf52f88..0553a071f68 100755 --- a/kolibri/__init__.py +++ b/kolibri/__init__.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import, print_function, unicode_literals + __author__ = 'Learning Equality' __email__ = 'info@learningequality.org' __version__ = '0.0.1' diff --git a/kolibri/__main__.py b/kolibri/__main__.py index e3652434316..ba96d56a71c 100644 --- a/kolibri/__main__.py +++ b/kolibri/__main__.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import, print_function, unicode_literals + import sys if __name__ == "__main__": From 637daca997591a38b2c8e3f46df3247b7080b158 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 17:29:20 +0100 Subject: [PATCH 15/32] showcase tox -e bdd command + python setup.py bdd --- pytest.bdd.ini | 3 +++ requirements/bdd.txt | 2 ++ setup.cfg | 1 + test/bdd/__init__.py | 0 test/bdd/bdd_basic.py | 16 ++++++++++++++++ test/test_cli.py | 18 +++++++++++++++++- tox.ini | 7 +++++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pytest.bdd.ini create mode 100644 requirements/bdd.txt create mode 100644 test/bdd/__init__.py create mode 100644 test/bdd/bdd_basic.py diff --git a/pytest.bdd.ini b/pytest.bdd.ini new file mode 100644 index 00000000000..f6ac0e88334 --- /dev/null +++ b/pytest.bdd.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = test/bdd/ +python_files = bdd_* diff --git a/requirements/bdd.txt b/requirements/bdd.txt new file mode 100644 index 00000000000..06e88f82764 --- /dev/null +++ b/requirements/bdd.txt @@ -0,0 +1,2 @@ +-r test.txt +pytest-bdd diff --git a/setup.cfg b/setup.cfg index c9ae42ff37a..c46b6dd5624 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,7 @@ universal = 1 [aliases] test = pytest +bdd = pytest --addopts "-c pytest.bdd.ini" [flake8] ignore = E226,E302,E41 diff --git a/test/bdd/__init__.py b/test/bdd/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/bdd/bdd_basic.py b/test/bdd/bdd_basic.py new file mode 100644 index 00000000000..b0f583d8b8e --- /dev/null +++ b/test/bdd/bdd_basic.py @@ -0,0 +1,16 @@ +""" +BDD tests +""" +from __future__ import absolute_import, print_function, unicode_literals + +from test.test_cli import KolibriTestBase + +from kolibri.logger import test_logger + +logger = test_logger + + +class BDDTestCase(KolibriTestBase): + + def test_cli(self): + logger.debug("Here's a place to put our BDD tests separately") diff --git a/test/test_cli.py b/test/test_cli.py index cd66efb7a3c..33f5b0e186b 100755 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1,6 +1,8 @@ """ Tests for `kolibri` module. """ +from __future__ import absolute_import, print_function, unicode_literals + import os import shutil import tempfile @@ -14,7 +16,21 @@ from kolibri.utils.cli import main -class TestKolibriCLI(unittest.TestCase): +class KolibriTestBase(unittest.TestCase): + """ + Sets up an isolated,temporary environment for testing Kolibri + """ + + @classmethod + def setup_class(cls): + os.environ["KOLIBRI_HOME"] = tempfile.mkdtemp() + + @classmethod + def teardown_class(cls): + shutil.rmtree(os.environ["KOLIBRI_HOME"]) + + +class TestKolibriCLI(KolibriTestBase): @classmethod def setup_class(cls): diff --git a/tox.ini b/tox.ini index d01584f0e4d..feeab4b64fc 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ basepython = pypypy: pypy docs: python2.7 lint: python + bdd: python deps = -r{toxinidir}/requirements/test.txt commands = @@ -27,3 +28,9 @@ deps = commands = sphinx-build -b linkcheck ./ _build/ # sphinx-build -b html ./ _build/ + +[testenv:bdd] +deps = + -r{toxinidir}/requirements/bdd.txt +commands = + python setup.py bdd From 7d9c2f26b4630be717dc10d1ffa1b65bb1ab7444 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 17:38:25 +0100 Subject: [PATCH 16/32] create kolibri home in the _build folder so it's removed by make clean --- docs/conf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 57cf34e83ea..f43acae4173 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,6 @@ import sys import os -import tempfile # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -24,11 +23,16 @@ parent = os.path.dirname(cwd) sys.path.insert(0, parent) -import kolibri +builddir = os.path.join(cwd, '_build') # When we start loading stuff from kolibri, we're gonna need this os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") -os.environ["KOLIBRI_HOME"] = tempfile.mkdtemp() +os.environ["KOLIBRI_HOME"] = os.path.join(builddir, 'kolibri_home') + +if not os.path.exists(os.environ["KOLIBRI_HOME"]): + os.mkdir(os.environ["KOLIBRI_HOME"]) + +import kolibri # -- General configuration ----------------------------------------------------- From 5b1cc9924aebc4345c19d52b5a8d3efd698d8eaa Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:01:05 +0100 Subject: [PATCH 17/32] Use conventional logging and configure with django settings.LOGGERS --- kolibri/deployment/default/settings/base.py | 79 ++++++++++++++++++--- kolibri/logger.py | 23 ------ kolibri/plugins/registry.py | 5 +- kolibri/test/test_basic.py | 5 +- kolibri/utils/cli.py | 5 +- test/bdd/bdd_basic.py | 4 +- test/test_cli.py | 5 +- 7 files changed, 86 insertions(+), 40 deletions(-) delete mode 100644 kolibri/logger.py diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py index 8abb86a604b..ae6d0dfd939 100644 --- a/kolibri/deployment/default/settings/base.py +++ b/kolibri/deployment/default/settings/base.py @@ -1,13 +1,11 @@ """ Django settings for kolibri project. -Generated by 'django-admin startproject' using Django 1.8.4. - For more information on this file, see -https://docs.djangoproject.com/en/1.8/topics/settings/ +https://docs.djangoproject.com/en/1.9/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.8/ref/settings/ +https://docs.djangoproject.com/en/1.9/ref/settings/ """ from __future__ import absolute_import, print_function, unicode_literals @@ -17,11 +15,12 @@ # This is essential! We load the kolibri conf INSIDE the Django conf from kolibri.utils import conf + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'f@ey3)y^03r9^@mou97apom*+c1m#b1!cwbm50^s4yk72xce27' @@ -77,7 +76,7 @@ # Database -# https://docs.djangoproject.com/en/1.8/ref/settings/#databases +# https://docs.djangoproject.com/en/1.9/ref/settings/#databases DATABASES = { 'default': { @@ -88,7 +87,7 @@ # Internationalization -# https://docs.djangoproject.com/en/1.8/topics/i18n/ +# https://docs.djangoproject.com/en/1.9/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -102,6 +101,70 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.8/howto/static-files/ +# https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_URL = '/static/' + + +# https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-LOGGING +# https://docs.djangoproject.com/en/1.9/topics/logging/ + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' + }, + 'simple': { + 'format': '%(levelname)s %(message)s' + }, + 'color': { + '()': 'colorlog.ColoredFormatter', + 'format': '%(log_color)s%(levelname)-8s %(message)s', + 'log_colors': { + 'DEBUG': 'bold_black', + 'INFO': 'white', + 'WARNING': 'yellow', + 'ERROR': 'red', + 'CRITICAL': 'bold_red', + }, + } + }, + 'filters': { + 'require_debug_true': { + '()': 'django.utils.log.RequireDebugTrue', + }, + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse', + }, + }, + 'handlers': { + 'console': { + 'level': 'INFO', + 'filters': ['require_debug_true'], + 'class': 'logging.StreamHandler', + 'formatter': 'color' + }, + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler', + 'filters': ['require_debug_false'], + } + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'propagate': True, + }, + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': False, + }, + 'kolibri': { + 'handlers': ['console', 'mail_admins'], + 'level': 'INFO', + } + } +} diff --git a/kolibri/logger.py b/kolibri/logger.py deleted file mode 100644 index b260b86f232..00000000000 --- a/kolibri/logger.py +++ /dev/null @@ -1,23 +0,0 @@ -from __future__ import absolute_import, print_function, unicode_literals - -import logging - -from colorlog import ColoredFormatter - -# TODO: Logging decision. -# The main Kolibri logger always logs to console and does not propagate. - -LOG_LEVEL = logging.DEBUG -LOGFORMAT = " %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s" -logging.root.setLevel(LOG_LEVEL) -formatter = ColoredFormatter(LOGFORMAT) -stream = logging.StreamHandler() -stream.setLevel(LOG_LEVEL) -stream.setFormatter(formatter) -logger = logging.getLogger(__name__) -logger.setLevel(LOG_LEVEL) -logger.addHandler(stream) -logger.propagate = False - -# For now, logging for test output is the same -test_logger = logger diff --git a/kolibri/plugins/registry.py b/kolibri/plugins/registry.py index f203372d19a..96dbb6af099 100644 --- a/kolibri/plugins/registry.py +++ b/kolibri/plugins/registry.py @@ -21,14 +21,15 @@ from __future__ import absolute_import, print_function, unicode_literals import importlib +import logging from django.conf import settings -from kolibri.logger import logger - from . import hooks from .base import KolibriPluginBase +logger = logging.getLogger(__name__) + registry = {} __initialized = False diff --git a/kolibri/test/test_basic.py b/kolibri/test/test_basic.py index 00c54f24996..99041ebe412 100755 --- a/kolibri/test/test_basic.py +++ b/kolibri/test/test_basic.py @@ -1,12 +1,13 @@ """ Tests for `kolibri` module. """ -import logging # import pytest # import kolibri -logger = logging.getLogger('kolibri_tests') +import logging + +logger = logging.getLogger(__name__) class TestKolibri_prototype(object): diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py index f702ccab3d1..032ee64ae87 100644 --- a/kolibri/utils/cli.py +++ b/kolibri/utils/cli.py @@ -83,9 +83,12 @@ os.environ.setdefault("KOLIBRI_LISTEN_PORT", "8008") -from kolibri.logger import logger # NOQA from kolibri.plugins.base import KolibriPluginBase # NOQA +import logging + +logger = logging.getLogger(__name__) + def manage(cmd, args=[]): """ diff --git a/test/bdd/bdd_basic.py b/test/bdd/bdd_basic.py index b0f583d8b8e..b68aacfcd7f 100644 --- a/test/bdd/bdd_basic.py +++ b/test/bdd/bdd_basic.py @@ -5,9 +5,9 @@ from test.test_cli import KolibriTestBase -from kolibri.logger import test_logger +import logging -logger = test_logger +logger = logging.getLogger(__name__) class BDDTestCase(KolibriTestBase): diff --git a/test/test_cli.py b/test/test_cli.py index 33f5b0e186b..6c39458fcfa 100755 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -8,9 +8,10 @@ import tempfile import unittest -from kolibri.logger import test_logger -logger = test_logger +import logging + +logger = logging.getLogger(__name__) from kolibri.utils.cli import main From 5909e87fe1a6b466fb415c4d28eb32665a0d161c Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:01:15 +0100 Subject: [PATCH 18/32] use latest django --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 5f6587590c7..c1819fcda06 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,4 +2,4 @@ wheel>=0.22 docopt colorlog==2.6.0 -django>=1.8,<1.9 +django==1.9.1 From 0f4a3bb086018d8168d4b01bd9cfb8452ff64e7d Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:02:11 +0100 Subject: [PATCH 19/32] latest django has urls.app_name --- kolibri/core/urls.py | 2 ++ kolibri/deployment/default/urls.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kolibri/core/urls.py b/kolibri/core/urls.py index 41e4099382c..36eb39fd940 100644 --- a/kolibri/core/urls.py +++ b/kolibri/core/urls.py @@ -7,6 +7,8 @@ from . import views +app_name = 'kolibri' + urlpatterns = [ url('^', views.IndexView.as_view(), name='index'), # url('.* ', views.TODOView.as_view()) diff --git a/kolibri/deployment/default/urls.py b/kolibri/deployment/default/urls.py index c66abdd2a99..317b1a693a8 100644 --- a/kolibri/deployment/default/urls.py +++ b/kolibri/deployment/default/urls.py @@ -24,5 +24,5 @@ urlpatterns = [ url(r'^admin/', include(admin.site.urls)), - url(r'', include('kolibri.core.urls', namespace='kolibri')), + url(r'', include('kolibri.core.urls')), ] From 9bb31adf9ba5ea80c1fabfa9c8624fe1aa8e5de4 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:12:25 +0100 Subject: [PATCH 20/32] clean up imports and pep8 --- kolibri/deployment/default/settings/base.py | 1 - kolibri/utils/cli.py | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py index ae6d0dfd939..2c133b1cfc5 100644 --- a/kolibri/deployment/default/settings/base.py +++ b/kolibri/deployment/default/settings/base.py @@ -15,7 +15,6 @@ # This is essential! We load the kolibri conf INSIDE the Django conf from kolibri.utils import conf - BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py index 032ee64ae87..2622542a019 100644 --- a/kolibri/utils/cli.py +++ b/kolibri/utils/cli.py @@ -2,6 +2,7 @@ import importlib +import logging import os import signal import sys @@ -83,10 +84,6 @@ os.environ.setdefault("KOLIBRI_LISTEN_PORT", "8008") -from kolibri.plugins.base import KolibriPluginBase # NOQA - -import logging - logger = logging.getLogger(__name__) @@ -113,6 +110,8 @@ def plugin(plugin_name, args): from kolibri.utils import conf plugin_classes = [] + from kolibri.plugins.base import KolibriPluginBase # NOQA + # Try to load kolibri_plugin from given plugin module identifier try: plugin_module = importlib.import_module(plugin_name + ".kolibri_plugin") From c619d31097d67cf5f575432337236ea81255a8de Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:42:25 +0100 Subject: [PATCH 21/32] clean up inheritance in enable/disable calls and use django configured logging outside django env --- kolibri/plugins/base.py | 51 ++++++++++++++++--- .../plugins/example_plugin/kolibri_plugin.py | 25 +++++---- kolibri/utils/cli.py | 15 ++++-- kolibri/utils/conf.py | 11 ++++ 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/kolibri/plugins/base.py b/kolibri/plugins/base.py index bf6ce907f26..30814662ef7 100644 --- a/kolibri/plugins/base.py +++ b/kolibri/plugins/base.py @@ -3,6 +3,12 @@ """ from __future__ import absolute_import, print_function, unicode_literals +import logging + +from kolibri.utils.conf import config + +logger = logging.getLogger(__name__) + class MandatoryPluginMethodNotImplemented(Exception): @@ -15,15 +21,26 @@ class KolibriPluginBase(object): This is the base class that all Kolibri plugins need to implement. """ - #: Suggested property, not yet in use + # : Suggested property, not yet in use migrate_on_enable = False - #: Suggested property, not yet in use + # : Suggested property, not yet in use collect_static_on_enable = False - #: Suggested property, not yet in use + # : Suggested property, not yet in use collect_static_on_enable = False + @classmethod + def _module_path(cls): + """ + Returns the path of the class inheriting this classmethod. + There is no such thing as Class properties, that's why it's implemented + as such. + + Used in KolibriPluginBase._installed_apps_add + """ + return ".".join(cls.__module__.split(".")[:-1]) + def hooks(self): """ Return a list of hooks and callables for each hook. To make your plugin @@ -33,11 +50,31 @@ def hooks(self): return {} @classmethod - def enable(cls, kolibri_config): + def _installed_apps_add(cls): + """Call this from your enable() method to have the plugin automatically + added to Kolibri configuration""" + module_path = cls._module_path() + if module_path not in config['INSTALLED_APPS']: + config['INSTALLED_APPS'].append(module_path) + else: + logger.warning("{} already enabled".format(module_path)) + + @classmethod + def _installed_apps_remove(cls): + """Call this from your enable() method to have the plugin automatically + added to Kolibri configuration""" + module_path = cls._module_path() + if module_path in config['INSTALLED_APPS']: + config['INSTALLED_APPS'].remove(module_path) + else: + logger.warning("{} already disabled".format(module_path)) + + @classmethod + def enable(cls): """Modify the kolibri config dict to your plugin's needs""" - raise MandatoryPluginMethodNotImplemented() + cls._installed_apps_add() @classmethod - def disable(cls, kolibri_config): + def disable(cls): """Modify the kolibri config dict to your plugin's needs""" - raise MandatoryPluginMethodNotImplemented() + cls._installed_apps_remove() diff --git a/kolibri/plugins/example_plugin/kolibri_plugin.py b/kolibri/plugins/example_plugin/kolibri_plugin.py index 7327b83f489..a12b2f163cf 100644 --- a/kolibri/plugins/example_plugin/kolibri_plugin.py +++ b/kolibri/plugins/example_plugin/kolibri_plugin.py @@ -4,12 +4,17 @@ """ from __future__ import absolute_import, print_function, unicode_literals +import logging + from django.utils.translation import ugettext as _ from kolibri.plugins.base import KolibriPluginBase from kolibri.plugins.hooks import NAVIGATION_POPULATE +logger = logging.getLogger(__name__) + + class NavMenuPlugin(KolibriPluginBase): """ An example plugin that demonstrates how the Kolibri plugin system works. Adds items to the nav menu by registering @@ -17,7 +22,7 @@ class NavMenuPlugin(KolibriPluginBase): """ @classmethod - def enable(cls, config): + def enable(cls): """ A plugin must implement this abstract method. It's called by the command ``kolibri plugin enable`` to modify the kolibri settings file. @@ -25,12 +30,11 @@ def enable(cls, config): :param config: A dictionary of settings, like the one at ``django.conf.settings``. :return: Nothing, though it may modify the mutable config parameter """ - print("Activating example plugin") - # Make this automatic and use __name__ ? - config["INSTALLED_APPS"].append("kolibri.plugins.example_plugin") + super(NavMenuPlugin, cls).enable() + logger.info("Enabled example plugin") @classmethod - def disable(cls, config): + def disable(cls): """ A plugin must implement this abstract method. It's called by the command ``kolibri plugin disable`` to modify the kolibri settings file. @@ -38,9 +42,8 @@ def disable(cls, config): :param config: A dictionary of settings, like the one at ``django.conf.settings``. :return: Nothing, though it may modify the mutable config parameter """ - print("Deactivating example plugin") - # Make this automatic and use __name__ ? - config["INSTALLED_APPS"].remove("kolibri.plugins.example_plugin") + super(NavMenuPlugin, cls).disable() + logger.info("Disable example plugin") @staticmethod def main_navigation(): @@ -71,11 +74,13 @@ class ExtendedPlugin(NavMenuPlugin): Demonstrates plugin inheritance. Notice that the ``hooks`` attribute need not be changed -- only the callback. """ @classmethod - def enable(cls, config): + def enable(cls): + # Do nothing because the parent will initialize the plugin as we want pass @classmethod - def disable(cls, config): + def disable(cls): + # Do nothing because the parent will initialize the plugin as we want pass def main_navigation(self): diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py index 2622542a019..372b6a80a8a 100644 --- a/kolibri/utils/cli.py +++ b/kolibri/utils/cli.py @@ -9,6 +9,7 @@ import kolibri from docopt import docopt +from logging import config as logging_config USAGE = """ Kolibri @@ -80,13 +81,20 @@ # Set default env os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kolibri.deployment.default.settings.base") -os.environ.setdefault("KOLIBRI_HOME", os.path.join(os.path.expanduser("~"), ".kalite")) +os.environ.setdefault("KOLIBRI_HOME", os.path.join(os.path.expanduser("~"), ".kolibri")) os.environ.setdefault("KOLIBRI_LISTEN_PORT", "8008") logger = logging.getLogger(__name__) +def setup_logging(): + """Configures logging in cases where a Django environment is not supposed + to be configured""" + from kolibri.deployment.default.settings.base import LOGGING + logging_config.dictConfig(LOGGING) + + def manage(cmd, args=[]): """ Invokes a django command @@ -107,6 +115,7 @@ def plugin(plugin_name, args): Receives a plugin identifier and tries to load its main class. Calls class functions. """ + setup_logging() from kolibri.utils import conf plugin_classes = [] @@ -123,11 +132,11 @@ def plugin(plugin_name, args): if args['enable']: for klass in plugin_classes: - klass.enable(conf.config) + klass.enable() if args['disable']: for klass in plugin_classes: - klass.disable(conf.config) + klass.disable() conf.save() diff --git a/kolibri/utils/conf.py b/kolibri/utils/conf.py index 82c92bcfb09..c8e7bf00139 100644 --- a/kolibri/utils/conf.py +++ b/kolibri/utils/conf.py @@ -12,12 +12,23 @@ from __future__ import absolute_import, print_function, unicode_literals import json +import logging import os +logger = logging.getLogger(__name__) + KOLIBRI_HOME = os.environ["KOLIBRI_HOME"] +if not os.path.exists(KOLIBRI_HOME): + parent = os.path.dirname(KOLIBRI_HOME) + if not os.path.exists(parent): + raise RuntimeError("The parent of your KOLIBRI_HOME does not exist: {}".format(parent)) + os.mkdir(KOLIBRI_HOME) + conf_file = os.path.join(KOLIBRI_HOME, "kolibri_settings.json") + if not os.path.isfile(conf_file): + logger.info("Writing default config file in {}".format(conf_file)) open(conf_file, "w").write("{}") #: Set defaults before updating the dict From ee659c405727b7a96c5368cba429017157310f22 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:44:23 +0100 Subject: [PATCH 22/32] add bdd to test matrix --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 75202251c01..5e7e444014d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ python: - "3.4" - "3.5" - "2.7" + - "bdd" # pypy testing currently breaks because of the tempfile dir used for KALITE_HOME # - "pypy" From bda6c72d6ea85003511a613730ebd2fb24d05fd6 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 18:44:41 +0100 Subject: [PATCH 23/32] remember django 1.9.1 in the non-dry setup requirements --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 2ea3ccedd6a..afdb20fcaf4 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ package_dir={'kolibri': 'kolibri'}, include_package_data=True, install_requires=[ + 'django==1.9.1', 'docopt', 'colorlog', ], From 28a6ac6e32aecbfca526993c635af1f084292310 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 19:17:24 +0100 Subject: [PATCH 24/32] store log in a file --- kolibri/deployment/default/settings/base.py | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py index 2c133b1cfc5..91a25ef427a 100644 --- a/kolibri/deployment/default/settings/base.py +++ b/kolibri/deployment/default/settings/base.py @@ -17,6 +17,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +KOLIBRI_HOME = os.environ['KOLIBRI_HOME'] # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ @@ -118,6 +119,9 @@ 'simple': { 'format': '%(levelname)s %(message)s' }, + 'simple_date': { + 'format': '%(levelname)s %(asctime)s %(module)s %(message)s' + }, 'color': { '()': 'colorlog.ColoredFormatter', 'format': '%(log_color)s%(levelname)-8s %(message)s', @@ -149,20 +153,34 @@ 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', 'filters': ['require_debug_false'], - } + }, + 'file_debug': { + 'level': 'DEBUG', + 'filters': ['require_debug_true'], + 'class': 'logging.FileHandler', + 'filename': os.path.join(KOLIBRI_HOME, 'debug.log'), + 'formatter': 'simple_date', + }, + 'file': { + 'level': 'INFO', + 'filters': [], + 'class': 'logging.FileHandler', + 'filename': os.path.join(KOLIBRI_HOME, 'kolibri.log'), + 'formatter': 'simple_date', + }, }, 'loggers': { 'django': { - 'handlers': ['console'], + 'handlers': ['console', 'file'], 'propagate': True, }, 'django.request': { - 'handlers': ['mail_admins'], + 'handlers': ['mail_admins', 'file'], 'level': 'ERROR', 'propagate': False, }, 'kolibri': { - 'handlers': ['console', 'mail_admins'], + 'handlers': ['console', 'mail_admins', 'file', 'file_debug'], 'level': 'INFO', } } From 3dfbae3038257549156259947d8bb38f564f97d4 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 19:20:07 +0100 Subject: [PATCH 25/32] use python2.7 for bdd tests --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index feeab4b64fc..c9fa4c94437 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{2.7,3.4,3.5,pypy}, lint, docs +envlist = py{2.7,3.4,3.5,pypy}, lint, docs, bdd [testenv] basepython = @@ -9,7 +9,7 @@ basepython = pypypy: pypy docs: python2.7 lint: python - bdd: python + bdd: python2.7 deps = -r{toxinidir}/requirements/test.txt commands = From 60b36ba774906fab89816c72ac0fb1695d1317d3 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 19:49:51 +0100 Subject: [PATCH 26/32] Move bdd test env and add docs testing --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e7e444014d..5b59ce37589 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ python: - "3.4" - "3.5" - "2.7" - - "bdd" # pypy testing currently breaks because of the tempfile dir used for KALITE_HOME # - "pypy" @@ -26,6 +25,8 @@ install: # command to run tests, e.g. python setup.py test script: - tox -e $TOX_ENV + - tox -e bdd + - tox -e docs after_success: - codecov From cef58c81117cdd03f4eabc47d8bbfddbc80c1ecb Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 20:04:08 +0100 Subject: [PATCH 27/32] Remove broken fork link --- CONTRIBUTING.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index bc3bb6edab0..e9fa5e8a545 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -84,7 +84,7 @@ To get tox, just pip install it. 6. Submit a pull request through the GitHub website. -.. _Fork: https://github.com/learningequality/kolibri/fork +.. _Fork: https://github.com/learningequality/kolibri Pull Request Guidelines ----------------------- From c809fc76d4543736572f11766b2236a0e1109c09 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 20:10:17 +0100 Subject: [PATCH 28/32] fix broken link, ignore google link, test docs and bdd separately from python envs --- .travis.yml | 4 ++-- docs/conf.py | 4 ++++ tox.ini | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b59ce37589..f178f17c031 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ python: - "3.4" - "3.5" - "2.7" + - "docs" + - "bdd" # pypy testing currently breaks because of the tempfile dir used for KALITE_HOME # - "pypy" @@ -25,8 +27,6 @@ install: # command to run tests, e.g. python setup.py test script: - tox -e $TOX_ENV - - tox -e bdd - - tox -e docs after_success: - codecov diff --git a/docs/conf.py b/docs/conf.py index f43acae4173..0bce4aca0b6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -43,6 +43,10 @@ # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] +linkcheck_ignore = [ + 'https://groups.google.com/a/learningequality.org/forum/#!forum/dev', +] + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/tox.ini b/tox.ini index c9fa4c94437..0269a3c53dd 100644 --- a/tox.ini +++ b/tox.ini @@ -7,9 +7,9 @@ basepython = py3.4: python3.4 py3.5: python3.5 pypypy: pypy - docs: python2.7 + pydocs: python2.7 lint: python - bdd: python2.7 + pybdd: python2.7 deps = -r{toxinidir}/requirements/test.txt commands = @@ -21,7 +21,7 @@ deps = commands = flake8 kolibri -[testenv:docs] +[testenv:pydocs] changedir=docs/ deps = -r{toxinidir}/requirements/docs.txt @@ -29,7 +29,7 @@ commands = sphinx-build -b linkcheck ./ _build/ # sphinx-build -b html ./ _build/ -[testenv:bdd] +[testenv:pybdd] deps = -r{toxinidir}/requirements/bdd.txt commands = From dd5ae766add989b1a8dc4653c9d8bd1b3aba6865 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 20:41:18 +0100 Subject: [PATCH 29/32] move coveragerc to setup.cfg, add django coverage plugin for template file coverage --- .coveragerc | 8 -------- requirements/test.txt | 2 ++ setup.cfg | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index a580f998478..00000000000 --- a/.coveragerc +++ /dev/null @@ -1,8 +0,0 @@ -[run] -branch = true - -[report] -show_missing = true -precision = 2 -exclude_lines = raise NotImplementedError - diff --git a/requirements/test.txt b/requirements/test.txt index eaa9d899990..5245b53e8e9 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -3,3 +3,5 @@ pytest pytest-django pytest-cov +coverage +django_coverage_plugin diff --git a/setup.cfg b/setup.cfg index c46b6dd5624..2131306b991 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,3 +21,19 @@ multi_line_output = 5 line_length = 79 combine_as_imports = true skip = wsgi.py,docs,env,cli.py,test,.eggs,build + + +[coverage:run] +branch = true +source = kolibri +plugins = django_coverage_plugin +omit = + */migrations/* + */tests/* + */test_*.py + +[coverage:report] +ignore_errors = True +show_missing = True +precision = 2 +exclude_lines = raise NotImplementedError From 85ef4894588cf7552522d4690ba1b64a5bd9b4a9 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 20:45:26 +0100 Subject: [PATCH 30/32] remove django_coverage_plugin as dj 1.9 is not supported --- requirements/test.txt | 1 - setup.cfg | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements/test.txt b/requirements/test.txt index 5245b53e8e9..63710f87967 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -4,4 +4,3 @@ pytest pytest-django pytest-cov coverage -django_coverage_plugin diff --git a/setup.cfg b/setup.cfg index 2131306b991..03575e4bcc9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,7 @@ skip = wsgi.py,docs,env,cli.py,test,.eggs,build [coverage:run] branch = true source = kolibri -plugins = django_coverage_plugin +# plugins = django_coverage_plugin # No Django 1.9 support yet omit = */migrations/* */tests/* From 77888735917a122f2d0be159a8bfa19326bff992 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 21:36:51 +0100 Subject: [PATCH 31/32] reconfigure travis script matrix --- .travis.yml | 17 +++++++++++------ tox.ini | 10 +++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index f178f17c031..c7c38e911a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,20 @@ python: - "3.4" - "3.5" - "2.7" - - "docs" - - "bdd" # pypy testing currently breaks because of the tempfile dir used for KALITE_HOME # - "pypy" +matrix: + include: + - python: "2.7" + env: TOX_ENV=py2.7 + env: TOX_ENV=docs + env: TOX_ENV=bdd + - python: "3.4" + env: TOX_ENV=py3.4 + - python: "3.5" + env: TOX_ENV=py3.5 + before_install: - pip install codecov - pip install tox @@ -20,10 +29,6 @@ before_install: before_script: - tox -e lint -# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors -install: - - TOX_ENV=py${TRAVIS_PYTHON_VERSION} - # command to run tests, e.g. python setup.py test script: - tox -e $TOX_ENV diff --git a/tox.ini b/tox.ini index 0269a3c53dd..aae09af2ae5 100644 --- a/tox.ini +++ b/tox.ini @@ -6,10 +6,10 @@ basepython = py2.7: python2.7 py3.4: python3.4 py3.5: python3.5 - pypypy: pypy - pydocs: python2.7 + pypy: pypy + docs: python2.7 lint: python - pybdd: python2.7 + bdd: python2.7 deps = -r{toxinidir}/requirements/test.txt commands = @@ -21,7 +21,7 @@ deps = commands = flake8 kolibri -[testenv:pydocs] +[testenv:docs] changedir=docs/ deps = -r{toxinidir}/requirements/docs.txt @@ -29,7 +29,7 @@ commands = sphinx-build -b linkcheck ./ _build/ # sphinx-build -b html ./ _build/ -[testenv:pybdd] +[testenv:bdd] deps = -r{toxinidir}/requirements/bdd.txt commands = From 2f29797ba6bafdab4cc5992e06ef48a5812d4626 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 25 Jan 2016 22:36:37 +0100 Subject: [PATCH 32/32] do not run with empty env --- .travis.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7c38e911a8..5987946b5e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,18 +4,13 @@ language: python sudo: false -python: - - "3.4" - - "3.5" - - "2.7" -# pypy testing currently breaks because of the tempfile dir used for KALITE_HOME -# - "pypy" - matrix: include: - python: "2.7" env: TOX_ENV=py2.7 + - python: "2.7" env: TOX_ENV=docs + - python: "2.7" env: TOX_ENV=bdd - python: "3.4" env: TOX_ENV=py3.4