mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Update web-platform-tests to revision 77fa639e94d19ad846db71da960d49c89578fb52
This commit is contained in:
parent
65447b44c5
commit
d5ff9803bf
293 changed files with 5028 additions and 6000 deletions
|
@ -43,6 +43,44 @@ The wptserver implements a number of Python APIs for controlling traffic.
|
|||
/tools/wptserve/docs/stash
|
||||
```
|
||||
|
||||
### Importing local helper scripts
|
||||
|
||||
Python file handlers may import local helper scripts, e.g. to share logic
|
||||
across multiple handlers. To avoid module name collision, however, imports must
|
||||
be relative to the root of WPT. For example, in an imaginary
|
||||
`cookies/resources/myhandler.py`:
|
||||
|
||||
```python
|
||||
# DON'T DO THIS
|
||||
import myhelper
|
||||
|
||||
# DO THIS
|
||||
from cookies.resources import myhelper
|
||||
```
|
||||
|
||||
Only absolute imports are allowed; do not use relative imports. If the path to
|
||||
your helper script includes a hyphen (`-`), you can use `import_module` from
|
||||
`importlib` to import it. For example:
|
||||
|
||||
```python
|
||||
import importlib
|
||||
myhelper = importlib.import_module('common.security-features.myhelper')
|
||||
```
|
||||
|
||||
**Note on __init__ files**: Until WPT moves to Python 3 only (~Q1 2021),
|
||||
importing helper scripts like this requires a 'path' of empty `__init__.py`
|
||||
files in every directory down to the helper. For example, if your helper is
|
||||
`css/css-align/resources/myhelper.py`, you need to have:
|
||||
|
||||
```
|
||||
css/__init__.py
|
||||
css/css-align/__init__.py
|
||||
css/css-align/resources/__init__.py
|
||||
```
|
||||
|
||||
This requirement will be removed once we move to Python 3, due to
|
||||
[PEP 420](https://www.python.org/dev/peps/pep-0420/).
|
||||
|
||||
### Python3 compatibility
|
||||
|
||||
Even though Python3 is not fully supported at this point, some work is being
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue