2015-03-20 12:16:00 +01:00
Contributing to qutebrowser
===========================
2014-06-20 07:52:56 +02:00
The Compiler <mail@qutebrowser.org>
:icons:
:data-uri:
:toc:
2014-06-18 20:35:08 +02:00
2014-06-20 07:52:56 +02:00
I `<3` footnote:[Of course, that says `<3` in HTML.] contributors!
2014-06-20 11:07:03 +02:00
This document contains guidelines for contributing to qutebrowser, as well as
useful hints when doing so.
If anything mentioned here would prevent you from contributing, please let me
2016-08-01 06:43:54 +02:00
know, and contribute anyways! The guidelines are meant to make life easier for
me, but if you don't follow everything in here, I won't be mad at you. In
fact, I will probably change it for you.
2014-06-20 07:52:56 +02:00
2014-06-20 11:07:03 +02:00
If you have any problems, I'm more than happy to help! You can get help in
several ways:
2014-06-20 07:52:56 +02:00
2014-07-23 20:17:08 +02:00
* Send a mail to the mailing list at mailto:qutebrowser@lists.qutebrowser.org[]
2014-06-20 07:52:56 +02:00
(optionally
https://lists.schokokeks.org/mailman/listinfo.cgi/qutebrowser[subscribe]
first).
2014-07-23 20:17:08 +02:00
* Join the IRC channel irc://irc.freenode.org/#qutebrowser[`#qutebrowser`] on
http://freenode.net/[Freenode]
(https://webchat.freenode.net/?channels=#qutebrowser[webchat]).
2014-06-20 07:52:56 +02:00
Finding something to work on
----------------------------
Chances are you already know something to improve or add when you're reading
2014-06-20 11:07:03 +02:00
this. It might be a good idea to ask on the mailing list or IRC channel to make
sure nobody else started working on the same thing already.
2014-06-20 07:52:56 +02:00
2014-10-02 07:05:56 +02:00
If you want to find something useful to do, check the
2017-02-05 00:13:11 +01:00
https://github.com/qutebrowser/qutebrowser/issues[issue tracker]. Some
2014-10-02 07:05:56 +02:00
pointers:
2017-02-05 00:13:11 +01:00
* https://github.com/qutebrowser/qutebrowser/labels/easy[Issues which should
2014-10-02 07:05:56 +02:00
be easy to solve]
2017-10-05 13:31:01 +02:00
* https://github.com/qutebrowser/qutebrowser/labels/component%3A%20docs[Documentation issues which require little/no coding]
2014-06-20 07:52:56 +02:00
2017-04-25 22:57:39 +02:00
If you prefer C++ or Javascript to Python, see the relevant issues which involve
work in those languages:
2018-02-14 17:40:51 +01:00
* https://github.com/qutebrowser/qutebrowser/issues?q=is%3Aopen+is%3Aissue+label%3A%22language%3A+c%2B%2B%22[C++] (mostly work on Qt, the library behind qutebrowser)
* https://github.com/qutebrowser/qutebrowser/issues?q=is%3Aopen+is%3Aissue+label%3A%22language%3A+javascript%22[JavaScript]
2017-04-25 22:57:39 +02:00
2014-06-20 07:52:56 +02:00
There are also some things to do if you don't want to write code:
2016-08-01 06:43:54 +02:00
* Help the community, e.g., on the mailinglist and the IRC channel.
2014-06-20 07:52:56 +02:00
* Improve the documentation.
2014-06-20 11:07:03 +02:00
* Help on the website and graphics (logo, etc.).
2014-06-20 07:52:56 +02:00
Using git
---------
qutebrowser uses http://git-scm.com/[git] for its development. You can clone
the repo like this:
----
2017-02-05 00:13:11 +01:00
git clone https://github.com/qutebrowser/qutebrowser.git
2014-06-20 07:52:56 +02:00
----
If you don't know git, a http://git-scm.com/[git cheatsheet] might come in
handy. Of course, if using git is the issue which prevents you from
2016-08-01 06:43:54 +02:00
contributing, feel free to send normal patches instead, e.g., generated via
2014-06-20 07:52:56 +02:00
`diff -Nur`.
Getting patches
~~~~~~~~~~~~~~~
2015-03-20 12:16:00 +01:00
The preferred way of submitting changes is to
https://help.github.com/articles/fork-a-repo/[fork the repository] and to
https://help.github.com/articles/creating-a-pull-request/[submit a pull
request].
If you prefer to send a patch to the mailinglist, you can generate a patch
based on your changes like this:
2014-06-20 07:52:56 +02:00
----
git format-patch origin/master <1>
----
2016-08-01 06:43:54 +02:00
<1> Replace `master` by the branch your work was based on, e.g.,
2014-06-20 07:52:56 +02:00
`origin/develop`.
2018-06-09 21:56:56 +02:00
Running qutebrowser
-------------------
2018-09-08 18:59:54 +02:00
After link:install{outfilesuffix}#tox[installing qutebrowser via tox], you can run
2018-06-09 21:56:56 +02:00
`.venv/bin/qutebrowser --debug --temp-basedir` to test your changes with debug
logging enabled and without affecting existing running instances.
Alternatively, you can install qutebrowser's dependencies system-wide and run
`python3 -m qutebrowser --debug --temp-basedir`.
2014-06-20 07:52:56 +02:00
Useful utilities
----------------
Checkers
~~~~~~~~
2014-06-18 20:35:08 +02:00
2015-05-29 16:52:54 +02:00
qutebrowser uses http://tox.readthedocs.org/en/latest/[tox] to run its
2015-03-26 19:47:34 +01:00
unittests and several linters/checkers.
2014-06-18 20:35:08 +02:00
2016-08-01 06:43:54 +02:00
Currently, the following tox environments are available:
2016-02-10 18:37:07 +01:00
2016-02-10 22:12:48 +01:00
* Tests using https://www.pytest.org[pytest]:
2017-09-17 22:06:56 +02:00
- `py35`, `py36`: Run pytest for python 3.5/3.6 with the system-wide PyQt.
2017-10-05 14:05:26 +02:00
- `py36-pyqt57`, ..., `py36-pyqt59`: Run pytest with the given PyQt version (`py35-*` also works).
- `py36-pyqt59-cov`: Run with coverage support (other Python/PyQt versions work too).
2017-11-21 09:24:43 +01:00
* `flake8`: Run various linting checks via https://pypi.python.org/pypi/flake8[flake8].
2016-02-10 18:37:07 +01:00
* `vulture`: Run https://pypi.python.org/pypi/vulture[vulture] to find
unused code portions.
* `pylint`: Run http://pylint.org/[pylint] static code analysis.
* `pyroma`: Check packaging practices with
2017-10-05 14:05:26 +02:00
https://pypi.python.org/pypi/pyroma/[pyroma].
2016-02-10 18:37:07 +01:00
* `eslint`: Run http://eslint.org/[ESLint] javascript checker.
* `check-manifest`: Check MANIFEST.in completeness with
2017-10-05 14:05:26 +02:00
https://github.com/mgedmin/check-manifest[check-manifest].
2016-02-10 18:37:07 +01:00
* `mkvenv`: Bootstrap a virtualenv for testing.
* `misc`: Run `scripts/misc_checks.py` to check for:
2014-06-20 11:07:03 +02:00
- untracked git files
2014-07-23 20:17:08 +02:00
- VCS conflict markers
2016-02-10 18:37:07 +01:00
- common spelling mistakes
2016-08-01 06:43:54 +02:00
The default test suite is run with `tox`; the list of default
environments is obtained with `tox -l`.
2014-06-18 20:35:08 +02:00
2015-03-26 19:47:34 +01:00
Please make sure the checks run without any warnings on your new contributions.
2016-02-10 22:12:48 +01:00
2016-08-01 06:43:54 +02:00
There's always the possibility of false positives; the following
2015-03-26 19:47:34 +01:00
techniques are useful to handle these:
2014-06-18 20:35:08 +02:00
* Use `_foo` for unused parameters, with `foo` being a descriptive name. Using
`_` is discouraged.
2017-10-05 13:31:01 +02:00
* If you think you have a good reason to suppress a message, then add the
2016-08-01 06:43:54 +02:00
following comment:
2014-06-18 20:35:08 +02:00
+
----
# pylint: disable=message-name
----
+
Note you can add this per line, per function/class, or per file. Please use the
smallest scope which makes sense. Most of the time, this will be line scope.
+
* If you really think a check shouldn't be done globally as it yields a lot of
false-positives, let me know! I'm still tweaking the parameters.
2016-02-10 18:37:07 +01:00
Running Specific Tests
~~~~~~~~~~~~~~~~~~~~~~
While you are developing you often don't want to run the full test
suite each time.
Specific test environments can be run with `tox -e <envlist>`.
Additional parameters can be passed to the test scripts by separating
them from `tox` arguments with `--`.
Examples:
----
# run only pytest tests which failed in last run:
tox -e py35 -- --lf
2016-05-29 18:20:00 +02:00
# run only the end2end feature tests:
tox -e py35 -- tests/end2end/features
2016-02-10 18:37:07 +01:00
# run everything with undo in the generated name, based on the scenario text
2016-05-29 18:20:00 +02:00
tox -e py35 -- tests/end2end/features/test_tabs_bdd.py -k undo
2016-03-30 22:30:33 +02:00
# run coverage test for specific file (updates htmlcov/index.html)
tox -e py35-cov -- tests/unit/browser/test_webelem.py
2016-02-10 18:37:07 +01:00
----
2014-06-18 20:35:08 +02:00
Profiling
2014-06-20 07:52:56 +02:00
~~~~~~~~~
2014-06-18 20:35:08 +02:00
In the _scripts/_ subfolder there's a `run_profile.py` which profiles the code
and shows a graphical representation of what takes how much time.
2016-06-10 13:11:53 +02:00
It uses the built-in Python
2017-09-18 09:41:12 +02:00
https://docs.python.org/3.6/library/profile.html[cProfile] module and can show
2016-06-10 13:11:53 +02:00
the output in four different ways:
* Raw profile file (`--profile-tool=none`)
* https://pypi.python.org/pypi/pyprof2calltree/[pyprof2calltree] and http://kcachegrind.sourceforge.net/html/Home.html[KCacheGrind] (`--profile-tool=kcachegrind`)
* https://jiffyclub.github.io/snakeviz/[SnakeViz] (`--profile-tool=snakeviz`)
* https://github.com/jrfonseca/gprof2dot[gprof2dot] (needs `dot` from http://graphviz.org/[Graphviz] and http://feh.finalrewind.org/[feh])
2014-06-18 20:35:08 +02:00
2014-06-20 07:52:56 +02:00
Debugging
~~~~~~~~~
2014-06-18 20:35:08 +02:00
2016-08-01 06:43:54 +02:00
There are some useful functions for debugging in the `qutebrowser.utils.debug`
module.
2014-06-18 20:35:08 +02:00
2016-08-01 06:43:54 +02:00
When starting qutebrowser with the `--debug` flag, you also get useful debug
2018-06-03 12:50:53 +02:00
logs. You can add +--logfilter _[!]category[,category,...]_+ to restrict
logging to the given categories.
2014-06-18 20:35:08 +02:00
2014-06-20 11:07:03 +02:00
With `--debug` there are also some additional +debug-_*_+ commands available,
for example `:debug-all-objects` and `:debug-all-widgets` which print a list of
all Qt objects/widgets to the debug log -- this is very useful for finding
2014-06-18 20:35:08 +02:00
memory leaks.
2014-06-20 07:52:56 +02:00
Useful websites
~~~~~~~~~~~~~~~
Some resources which might be handy:
2015-06-12 16:59:33 +02:00
* http://doc.qt.io/qt-5/classes.html[The Qt5 reference]
2014-06-20 07:52:56 +02:00
* https://docs.python.org/3/library/index.html[The Python reference]
* http://httpbin.org/[httpbin, a test service for HTTP requests/responses]
* http://requestb.in/[RequestBin, a service to inspect HTTP requests]
2014-09-15 18:30:44 +02:00
Documentation of used Python libraries:
* http://jinja.pocoo.org/docs/dev/[jinja2]
* http://pygments.org/docs/[pygments]
* http://fdik.org/pyPEG/index.html[pyPEG2]
* http://pythonhosted.org/setuptools/[setuptools]
2017-05-17 11:31:14 +02:00
* http://www.pyinstaller.org/[PyInstaller]
2014-09-15 18:30:44 +02:00
* https://pypi.python.org/pypi/colorama[colorama]
2014-08-05 23:48:16 +02:00
Related RFCs and standards:
2014-09-02 09:04:47 +02:00
HTTP
^^^^
2014-08-12 06:38:30 +02:00
* https://tools.ietf.org/html/rfc2616[RFC 2616 - Hypertext Transfer Protocol
-- HTTP/1.1]
(http://www.rfc-editor.org/errata_search.php?rfc=2616[Errata])
* https://tools.ietf.org/html/rfc7230[RFC 7230 - Hypertext Transfer Protocol
(HTTP/1.1): Message Syntax and Routing]
(http://www.rfc-editor.org/errata_search.php?rfc=7230[Errata])
* https://tools.ietf.org/html/rfc7231[RFC 7231 - Hypertext Transfer Protocol
(HTTP/1.1): Semantics and Content]
(http://www.rfc-editor.org/errata_search.php?rfc=7231[Errata])
* https://tools.ietf.org/html/rfc7232[RFC 7232 - Hypertext Transfer Protocol
(HTTP/1.1): Conditional Requests]
(http://www.rfc-editor.org/errata_search.php?rfc=7232[Errata])
* https://tools.ietf.org/html/rfc7233[RFC 7233 - Hypertext Transfer Protocol
(HTTP/1.1): Range Requests]
(http://www.rfc-editor.org/errata_search.php?rfc=7233[Errata])
* https://tools.ietf.org/html/rfc7234[RFC 7234 - Hypertext Transfer Protocol
(HTTP/1.1): Caching]
(http://www.rfc-editor.org/errata_search.php?rfc=7234[Errata])
* https://tools.ietf.org/html/rfc7235[RFC 7235 - Hypertext Transfer Protocol
(HTTP/1.1): Authentication]
(http://www.rfc-editor.org/errata_search.php?rfc=7235[Errata])
2014-08-14 13:49:51 +02:00
* https://tools.ietf.org/html/rfc5987[RFC 5987 - Character Set and Language
Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters]
(http://www.rfc-editor.org/errata_search.php?rfc=5987[Errata])
2014-08-12 06:38:30 +02:00
* https://tools.ietf.org/html/rfc6266[RFC 6266 - Use of the
2014-08-05 23:48:16 +02:00
Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)]
2014-08-12 06:38:30 +02:00
(http://www.rfc-editor.org/errata_search.php?rfc=6266[Errata])
* http://tools.ietf.org/html/rfc6265[RFC 6265 - HTTP State Management Mechanism
(Cookies)] (http://www.rfc-editor.org/errata_search.php?rfc=6265[Errata])
2014-08-05 23:48:16 +02:00
* http://www.cookiecentral.com/faq/#3.5[Netscape Cookie Format]
2014-09-02 09:04:47 +02:00
Other
^^^^^
* https://tools.ietf.org/html/rfc5646[RFC 5646 - Tags for Identifying
Languages] (http://www.rfc-editor.org/errata_search.php?rfc=5646[Errata])
2014-08-05 23:48:16 +02:00
* http://www.w3.org/TR/CSS2/[Cascading Style Sheets Level 2 Revision 1 (CSS
2.1) Specification]
2015-06-12 16:59:33 +02:00
* http://doc.qt.io/qt-5/stylesheet-reference.html[Qt Style Sheets Reference]
2014-08-12 10:54:36 +02:00
* http://mimesniff.spec.whatwg.org/[MIME Sniffing Standard]
* http://spec.whatwg.org/[WHATWG specifications]
2014-09-02 09:04:47 +02:00
* http://www.w3.org/html/wg/drafts/html/master/Overview.html[HTML 5.1 Nightly]
* http://www.w3.org/TR/webstorage/[Web Storage]
2014-09-26 07:06:39 +02:00
* http://www.brynosaurus.com/cachedir/spec.html[Cache directory tagging
standard]
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html[XDG
basedir specification]
2014-08-05 23:48:16 +02:00
2014-06-20 11:49:33 +02:00
Hints
-----
2014-06-23 15:17:36 +02:00
Python and Qt objects
~~~~~~~~~~~~~~~~~~~~~
2016-08-01 06:43:54 +02:00
For many tasks, there are solutions available in both Qt and the Python
2016-08-01 09:43:46 +02:00
standard library.
2014-06-23 15:17:36 +02:00
2016-08-01 09:43:46 +02:00
In qutebrowser, the policy is usually to use the Python libraries, as they
2014-06-23 15:17:36 +02:00
provide exceptions and other benefits.
2014-07-23 20:17:08 +02:00
There are some exceptions to that:
2014-06-23 15:17:36 +02:00
* `QThread` is used instead of Python threads because it provides signals and
slots.
2017-10-05 14:05:26 +02:00
* `QProcess` is used instead of Python's `subprocess`.
2014-06-23 15:17:36 +02:00
* `QUrl` is used instead of storing URLs as string, see the
<<handling-urls,handling URLs>> section for details.
When using Qt objects, two issues must be taken care of:
2016-08-01 06:43:54 +02:00
* Methods of Qt objects report their status with their return values,
2014-06-23 15:17:36 +02:00
instead of using exceptions.
+
2016-02-10 23:01:50 +01:00
If a function gets or returns a Qt object which has an `.isValid()`
method such as `QUrl` or `QModelIndex`, there's a helper function
`ensure_valid` in `qutebrowser.utils.qtutils` which should get called
on all such objects. It will raise
`qutebrowser.utils.qtutils.QtValueError` if the value is not valid.
2014-06-23 15:17:36 +02:00
+
If a function returns something else on error, the return value should
carefully be checked.
2014-06-23 15:19:21 +02:00
2016-08-01 06:43:54 +02:00
* Methods of Qt objects have certain maximum values based on their
2016-02-10 23:01:50 +01:00
underlying C++ types.
2014-06-23 15:17:36 +02:00
+
2017-10-05 13:31:01 +02:00
To avoid passing too large of a numeric parameter to a Qt function, all
2016-08-01 06:43:54 +02:00
numbers should be range-checked using `qutebrowser.qtutils.check_overflow`,
or by other means (e.g. by setting a maximum value for a config object).
2014-06-23 15:17:36 +02:00
2014-09-25 08:28:27 +02:00
[[object-registry]]
The object registry
~~~~~~~~~~~~~~~~~~~
The object registry in `qutebrowser.utils.objreg` is a collection of
dictionaries which map object names to the actual long-living objects.
There are currently these object registries, also called 'scopes':
* The `global` scope, with objects which are used globally (`config`,
2017-10-05 14:05:26 +02:00
`cookie-jar`, etc.).
2014-09-25 08:28:27 +02:00
* The `tab` scope with objects which are per-tab (`hintmanager`, `webview`,
2014-10-06 21:28:33 +02:00
etc.). Passing this scope to `objreg.get()` selects the object in the currently
2015-03-31 20:49:29 +02:00
focused tab by default. A tab can be explicitly selected by passing
2014-10-06 21:28:33 +02:00
+tab=_tab-id_, window=_win-id_+ to it.
2014-09-25 08:28:27 +02:00
A new object can be registered by using
2014-10-06 21:28:33 +02:00
+objreg.register(_name_, _object_[, scope=_scope_, window=_win-id_,
tab=_tab-id_])+. An object should not be registered twice. To update it,
`update=True` has to be given.
2014-09-25 08:28:27 +02:00
2014-10-06 21:28:33 +02:00
An object can be retrieved by using +objreg.get(_name_[, scope=_scope_,
window=_win-id_, tab=_tab-id_])+. The default scope is `global`.
2014-09-25 08:28:27 +02:00
All objects can be printed by starting with the `--debug` flag and using the
`:debug-all-objects` command.
2016-08-01 06:43:54 +02:00
The registry is mainly used for <<commands,command handlers>>, but it can
also be useful in places where using Qt's
2015-06-12 16:59:33 +02:00
http://doc.qt.io/qt-5/signalsandslots.html[signals and slots] mechanism would
be difficult.
2014-09-25 08:28:27 +02:00
2014-06-20 11:49:33 +02:00
Logging
~~~~~~~
Logging is used at various places throughout the qutebrowser code. If you add a
new feature, you should also add some strategic debug logging.
2016-08-01 06:43:54 +02:00
Unlike other Python projects, qutebrowser doesn't use a logger per file,
2014-06-20 11:49:33 +02:00
instead it uses custom-named loggers.
The existing loggers are defined in `qutebrowser.utils.log`. If your feature
doesn't fit in any of the logging categories, simply add a new line like this:
[source,python]
----
foo = getLogger('foo')
----
2014-08-26 20:15:41 +02:00
Then in your source files, do this:
2014-06-20 11:49:33 +02:00
[source,python]
----
2014-08-26 19:10:14 +02:00
from qutebrowser.utils import log
2014-06-20 11:49:33 +02:00
...
log.foo.debug("Hello World")
----
The following logging levels are available for every logger:
2014-06-20 11:53:54 +02:00
[width="75%",cols="25%,75%"]
2014-06-20 11:49:33 +02:00
|=======================================================================
2016-05-27 12:07:00 +02:00
|critical |Critical issue, qutebrowser can't continue to run.
2014-06-20 11:49:33 +02:00
|error |There was an issue and some kind of operation was abandoned.
|warning |There was an issue but the operation can continue running.
|info |General informational messages.
2018-02-03 19:08:42 +01:00
|debug |Verbose debugging information.
2014-06-20 11:49:33 +02:00
|=======================================================================
2014-09-25 08:28:27 +02:00
[[commands]]
2014-06-20 11:49:33 +02:00
Commands
~~~~~~~~
qutebrowser has the concept of functions which are exposed to the user as
commands.
Creating a new command is straightforward:
[source,python]
----
2014-08-26 20:48:39 +02:00
import qutebrowser.commands.cmdutils
2014-06-20 11:49:33 +02:00
...
@cmdutils.register(...)
def foo():
...
----
The commands arguments are automatically deduced by inspecting your function.
If the function is a method of a class, the `@cmdutils.register` decorator
needs to have an `instance=...` parameter which points to the (single/main)
2014-09-25 08:34:20 +02:00
instance of the class.
2014-06-20 11:49:33 +02:00
2014-09-25 08:28:27 +02:00
The `instance` parameter is the name of an object in the object registry, which
then gets passed as the `self` parameter to the handler. The `scope` argument
selects which object registry (global, per-tab, etc.) to use. See the
2014-09-25 08:34:20 +02:00
<<object-registry,object registry>> section for details.
2014-06-20 11:49:33 +02:00
2016-02-10 23:01:50 +01:00
There are also other arguments to customize the way the command is
2016-08-01 06:43:54 +02:00
registered; see the class documentation for `register` in
2016-02-10 23:01:50 +01:00
`qutebrowser.commands.cmdutils` for details.
2014-06-20 11:49:33 +02:00
2014-10-20 20:25:54 +02:00
The types of the function arguments are inferred based on their default values,
2016-08-01 06:43:54 +02:00
e.g., an argument `foo=True` will be converted to a flag `-f`/`--foo` in
2014-10-20 20:25:54 +02:00
qutebrowser's commandline.
2016-05-10 22:03:10 +02:00
The type can be overridden using Python's
http://legacy.python.org/dev/peps/pep-3107/[function annotations]:
2014-10-20 20:25:54 +02:00
[source,python]
----
@cmdutils.register(...)
2016-05-10 22:03:10 +02:00
def foo(bar: int, baz=True):
2014-10-20 20:25:54 +02:00
...
----
2016-05-10 22:03:10 +02:00
Possible values:
2017-10-05 14:12:42 +02:00
2017-10-05 14:05:26 +02:00
- A callable (`int`, `float`, etc.): Gets called to validate/convert the value.
- A python enum type: All members of the enum are possible values.
- A `typing.Union` of multiple types above: Any of these types are valid
values, e.g., `typing.Union[str, int]`.
2014-10-20 20:25:54 +02:00
2016-05-10 18:58:23 +02:00
You can customize how an argument is handled using the `@cmdutils.argument`
2017-10-05 13:31:01 +02:00
decorator *after* `@cmdutils.register`. This can, for example, be used to
2016-08-01 06:43:54 +02:00
customize the flag an argument should get:
2016-05-10 18:58:23 +02:00
[source,python]
----
@cmdutils.register(...)
2016-05-10 20:15:33 +02:00
@cmdutils.argument('bar', flag='c')
2016-05-10 18:58:23 +02:00
def foo(bar):
...
----
2016-05-17 17:37:54 +02:00
For a `str` argument, you can restrict the allowed strings using `choices`:
[source,python]
----
@cmdutils.register(...)
@cmdutils.argument('bar', choices=['val1', 'val2'])
def foo(bar: str):
...
----
For `typing.Union` types, the given `choices` are only checked if other types
(like `int`) don't match.
2016-05-10 20:15:33 +02:00
The following arguments are supported for `@cmdutils.argument`:
- `flag`: Customize the short flag (`-x`) the argument will get.
2017-10-05 14:05:26 +02:00
- `win_id=True`: Mark the argument as special window ID argument.
- `count=True`: Mark the argument as special count argument.
2017-09-07 13:01:21 +02:00
- `completion`: A completion function (see `qutebrowser.completions.models.*`)
to use when completing arguments for the given command.
2016-05-17 17:37:54 +02:00
- `choices`: The allowed string choices for the argument.
2016-05-10 20:15:33 +02:00
2015-04-20 22:25:27 +02:00
The name of an argument will always be the parameter name, with any trailing
2016-05-17 17:37:54 +02:00
underscores stripped and underscores replaced by dashes.
2015-04-20 22:25:27 +02:00
2014-06-23 15:17:36 +02:00
[[handling-urls]]
2014-06-20 22:48:01 +02:00
Handling URLs
~~~~~~~~~~~~~
qutebrowser handles two different types of URLs: URLs as a string, and URLs as
the Qt `QUrl` type. As this can get confusing quickly, please follow the
following guidelines:
2016-08-01 06:43:54 +02:00
* Convert a string to a QUrl object as early as possible, i.e., directly after
2014-06-20 22:48:01 +02:00
the user did enter it.
2014-08-26 20:33:41 +02:00
- Use `utils.urlutils.fuzzy_url` if the URL is entered by the user
somewhere.
- Be sure you handle `utils.urlutils.FuzzyError` and display an error
2014-06-20 22:48:01 +02:00
message to the user.
2016-08-01 06:43:54 +02:00
* Convert a `QUrl` object to a string as late as possible, i.e., before
2014-06-20 22:48:01 +02:00
displaying it to the user.
- If you want to display the URL to the user, use `url.toDisplayString()`
so password information is removed.
- If you want to get the URL as string for some other reason, you most
likely want to add the `QUrl.EncodeFully` and `QUrl.RemovePassword`
flags.
* Name a string URL something like `urlstr`, and a `QUrl` something like `url`.
* Mention in the docstring whether your function needs a URL string or a
`QUrl`.
2014-08-26 20:38:23 +02:00
* Call `ensure_valid` from `utils.qtutils` whenever getting or creating a
2014-10-03 16:58:30 +02:00
`QUrl` and take appropriate action if not. Note the URL of the current page
always could be an invalid QUrl (if nothing is loaded yet).
2014-06-20 22:48:01 +02:00
2015-03-05 10:47:36 +01:00
Running valgrind on QtWebKit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you want to run qutebrowser (and thus QtWebKit) with
http://valgrind.org/[valgrind], you'll need to pass `--smc-check=all` to it or
recompile QtWebKit with the Javascript JIT disabled.
This is needed so valgrind handles self-modifying code correctly:
[quote]
____
This option controls Valgrind's detection of self-modifying code. If no
2016-08-01 06:43:54 +02:00
checking is done and a program executes some code, overwrites it with new
code, and then executes the new code, Valgrind will continue to execute the
2015-03-05 10:47:36 +01:00
translations it made for the old code. This will likely lead to incorrect
2015-03-31 20:49:29 +02:00
behavior and/or crashes.
2015-03-05 10:47:36 +01:00
...
Note that the default option will catch the vast majority of cases. The main
case it will not catch is programs such as JIT compilers that dynamically
generate code and subsequently overwrite part or all of it. Running with all
will slow Valgrind down noticeably.
____
2014-06-20 11:49:33 +02:00
2016-10-25 13:55:32 +02:00
Setting up a Windows Development Environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-09-18 09:41:12 +02:00
* Install https://www.python.org/downloads/release/python-362/[Python 3.6].
2017-10-05 14:05:26 +02:00
* Install PyQt via `pip install PyQt5`.
2017-09-18 09:41:12 +02:00
* Create a file at `C:\Windows\system32\python3.bat` with the following content (adjust the path as necessary):
2017-10-05 14:05:26 +02:00
`@C:\Python36\python %*`.
2017-09-18 09:41:12 +02:00
This will make the Python 3.6 interpreter available as `python3`, which is used by various development scripts.
2017-10-05 14:05:26 +02:00
* Install git from the https://git-scm.com/download/win[git-scm downloads page].
2016-10-25 13:55:32 +02:00
Try not to enable `core.autocrlf`, since that will cause `flake8` to complain a lot. Use an editor that can deal with plain line feeds instead.
* Clone your favourite qutebrowser repository.
* To install tox, open an elevated cmd, enter your working directory and run `pip install -rmisc/requirements/requirements-tox.txt`.
Note that the `flake8` tox env might not run due to encoding errors despite having LANG/LC_* set correctly.
2017-02-19 20:53:19 +01:00
Rebuilding the website
~~~~~~~~~~~~~~~~~~~~~~
If you want to rebuild the website, run `./scripts/asciidoc2html.py --website <outputdir>`.
2017-03-19 04:05:21 +01:00
Chrome URLs
~~~~~~~~~~~
2017-05-23 17:28:42 +02:00
With the QtWebEngine backend, qutebrowser supports several chrome:// urls which
can be useful for debugging:
- chrome://appcache-internals/
- chrome://blob-internals/
- chrome://gpu/
- chrome://histograms/
- chrome://indexeddb-internals/
- chrome://media-internals/
- chrome://network-errors/
- chrome://serviceworker-internals/
- chrome://webrtc-internals/
- chrome://crash/ (crashes the current renderer process!)
- chrome://kill/ (kills the current renderer process!)
- chrome://gpucrash/ (crashes qutebrowser!)
- chrome://gpuhang/ (hangs qutebrowser!)
- chrome://gpuclean/ (crashes the current renderer process!)
- chrome://ppapiflashcrash/
- chrome://ppapiflashhang/
2018-06-07 15:42:58 +02:00
- chrome://quota-internals/ (Qt 5.11)
- chrome://taskscheduler-internals/ (Qt 5.11)
- chrome://sandbox/ (Qt 5.11, Linux only)
2017-02-19 20:53:19 +01:00
2018-05-22 07:41:43 +02:00
QtWebEngine internals
~~~~~~~~~~~~~~~~~~~~~
This is mostly useful for qutebrowser maintainers to work around issues in Qt - if you don't understand it, don't worry, just ignore it.
The hierarchy of widgets when QtWebEngine is involved looks like this:
- qutebrowser has a `WebEngineTab` object, which is its abstraction over QtWebKit/QtWebEngine.
- The `WebEngineTab` has a `_widget` attribute, which is the https://doc.qt.io/qt-5/qwebengineview.html[QWebEngineView]
- That view has a https://doc.qt.io/qt-5/qwebenginepage.html[QWebEnginePage] for everything which doesn't require rendering.
- The view also has a layout with exactly one element (which also is its `focusProxy()`)
- That element is the http://code.qt.io/cgit/qt/qtwebengine.git/tree/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp[RenderWidgetHostViewQtDelegateWidget] (it inherits https://doc.qt.io/qt-5/qquickwidget.html[QQuickWidget]) - also often referred to as RWHV or RWHVQDW. It can be obtained via `sip.cast(tab._widget.focusProxy(), QQuickWidget)`.
- Calling `rootObject()` on that gives us the https://doc.qt.io/qt-5/qquickitem.html[QQuickItem] where Chromium renders into (?). With it, we can do things like `.setRotation(20)`.
2014-06-18 20:35:08 +02:00
Style conventions
-----------------
2014-04-25 17:00:40 +02:00
2014-06-18 20:35:08 +02:00
qutebrowser's coding conventions are based on
http://legacy.python.org/dev/peps/pep-0008/[PEP8] and the https://google-styleguide.googlecode.com/svn/trunk/pyguide.html[Google Python style guidelines] with some additions:
2014-10-07 23:08:37 +02:00
* The _Raise:_ section is not added to the docstring.
2014-06-18 20:35:08 +02:00
* Methods overriding Qt methods (obviously!) don't follow the naming schemes.
* Everything else does though, even slots.
2014-06-20 11:07:03 +02:00
* Docstrings should look like described in
2014-06-18 20:35:08 +02:00
http://legacy.python.org/dev/peps/pep-0257/[PEP257] and the google guidelines.
2014-06-20 11:07:03 +02:00
* Class docstrings have additional _Attributes:_, _Class attributes:_ and
2014-10-07 23:08:37 +02:00
_Signals:_ sections.
2014-07-16 20:09:41 +02:00
* In docstrings of command handlers (registered via `@cmdutils.register`), the
description should be split into two parts by using `//` - the first part is
the description of the command like it will appear in the documentation, the
second part is "internal" documentation only relevant to people reading the
sourcecode.
2014-06-18 20:35:08 +02:00
+
Example for a class docstring:
+
[source,python]
----
"""Some object.
Attributes:
2014-06-20 11:07:03 +02:00
blub: The current thing to handle.
2014-06-18 20:35:08 +02:00
Signals:
2014-06-20 11:07:03 +02:00
valueChanged: Emitted when a value changed.
arg: The new value
2014-06-18 20:35:08 +02:00
"""
----
+
Example for a method/function docstring:
+
[source,python]
----
"""Do something special.
2014-07-16 20:09:41 +02:00
This will do something.
//
It is based on http://example.com/.
2014-06-18 20:35:08 +02:00
Args:
2014-06-20 11:07:03 +02:00
foo: ...
2014-06-18 20:35:08 +02:00
Return:
2014-06-20 11:07:03 +02:00
True if something, False if something else.
2014-06-18 20:35:08 +02:00
"""
----
+
* The layout of a module should be roughly like this:
2014-06-19 09:04:37 +02:00
- Shebang (`#!/usr/bin/python`, if needed)
- vim-modeline (`# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et`)
2014-04-25 17:46:01 +02:00
- Copyright
- GPL boilerplate
- Module docstring
- Python standard library imports
- PyQt imports
- qutebrowser imports
- functions
- classes
2014-06-18 20:35:08 +02:00
* The layout of a class should be like this:
2014-04-25 17:46:01 +02:00
- docstring
2014-06-18 20:35:08 +02:00
- `__magic__` methods
2016-06-10 13:11:53 +02:00
- other methods
2014-04-25 17:46:01 +02:00
- overrides of Qt methods
2014-10-14 17:29:11 +02:00
Checklists
----------
These are mainly intended for myself, but they also fit in here well.
New Qt release
~~~~~~~~~~~~~~
* Run all tests and check nothing is broken.
* Check the
2015-06-12 16:59:33 +02:00
https://bugreports.qt.io/issues/?jql=reporter%20%3D%20%22The%20Compiler%22%20ORDER%20BY%20fixVersion%20ASC[Qt bugtracker]
2014-10-14 17:29:11 +02:00
and make sure all bugs marked as resolved are actually fixed.
2015-03-02 13:59:00 +01:00
* Update own PKGBUILDs based on upstream Archlinux updates and rebuild.
2017-10-05 14:05:26 +02:00
* Update recommended Qt version in `README`.
2014-10-14 17:29:11 +02:00
* Grep for `WORKAROUND` in the code and test if fixed stuff works without the
workaround.
2015-03-02 13:59:00 +01:00
* Check relevant
2017-02-05 00:13:11 +01:00
https://github.com/qutebrowser/qutebrowser/issues?q=is%3Aopen+is%3Aissue+label%3Aqt[qutebrowser
2015-03-02 13:59:00 +01:00
bugs] and check if they're fixed.
2014-10-14 17:29:11 +02:00
2015-11-18 07:55:39 +01:00
New PyQt release
~~~~~~~~~~~~~~~~
2017-10-05 14:05:26 +02:00
* See above.
* Update `tox.ini`/`.travis.yml`/`.appveyor.yml` to test new versions.
2015-11-18 07:55:39 +01:00
2014-10-14 17:29:11 +02:00
qutebrowser release
~~~~~~~~~~~~~~~~~~~
2016-01-05 06:49:43 +01:00
* Make sure there are no unstaged changes and the tests are green.
2018-03-14 21:50:22 +01:00
* Make sure all issues with the related milestone are closed.
2017-10-05 14:05:26 +02:00
* Run `x=... y=...` to set the respective shell variables.
2014-10-14 17:29:11 +02:00
2017-10-05 14:05:26 +02:00
* Update changelog (remove *(unreleased)*).
2018-03-14 21:50:22 +01:00
* Adjust `__version_info__` in `qutebrowser/__init__.py`.
2017-10-05 14:05:26 +02:00
* Commit.
2015-09-11 19:43:55 +02:00
2017-10-11 22:27:03 +02:00
* Create annotated git tag (`git tag -s "v1.$x.$y" -m "Release v1.$x.$y"`).
* `git push origin`; `git push origin v1.$x.$y`.
2015-10-13 23:52:13 +02:00
* If committing on minor branch, cherry-pick release commit to master.
2017-10-05 14:05:26 +02:00
* Create release on github.
2017-02-05 00:13:11 +01:00
* Mark the milestone at https://github.com/qutebrowser/qutebrowser/milestones
2014-10-14 17:29:11 +02:00
as closed.
2018-03-14 21:50:22 +01:00
* Linux: Run `git checkout v1.$x.$y && ./.venv/bin/python3 scripts/dev/build_release.py --upload v1.$x.$y`.
2018-10-03 16:14:25 +02:00
* Windows: Run `git checkout v1.X.Y; py -3 scripts\dev\build_release.py --asciidoc C:\Python27\python %userprofile%\bin\asciidoc-8.6.10\asciidoc.py --upload v1.X.Y` (replace X/Y by hand).
* macOS: Run `git checkout v1.X.Y && python3 scripts/dev/build_release.py --upload v1.X.Y` (replace X/Y by hand).
2018-03-26 22:53:13 +02:00
* On server:
- Run `python3 scripts/dev/download_release.py v1.X.Y` (replace X/Y by hand).
- Run `git pull github master && sudo python3 scripts/asciidoc2html.py --website /srv/http/qutebrowser`
2017-10-05 14:05:26 +02:00
* Update `qutebrowser-git` PKGBUILD if dependencies/install changed.
* Announce to qutebrowser and qutebrowser-announce mailinglist.