Skip to content

Commit

Permalink
Merge 4aa8e31 into 9537671
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Jun 1, 2020
2 parents 9537671 + 4aa8e31 commit f50fc26
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
env: TOXENV=py37-alldeps-withcov-posix,coverage-prepare,codecov-push,coveralls-push
- python: 3.8
env: TOXENV=py38-alldeps-withcov-posix,coverage-prepare,codecov-push,coveralls-push
- python: 3.6
- python: 3.5
env: TOXENV=lint
# We need a builder without IPv6. This is going to be slower than all the
# others, but that's ok.
Expand Down
137 changes: 0 additions & 137 deletions admin/pycodestyle-twisted.py

This file was deleted.

1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ skip_branch_with_pr: true
cache:
- '%LOCALAPPDATA%\pip\Cache'


environment:
global:
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
Expand Down
79 changes: 11 additions & 68 deletions docs/core/development/policy/coding-standard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,11 @@ Whenever a new file is added to the repository, add the following license header
When you update existing files, if there is no copyright header, add one.


Whitespace
Formatting
----------

Indentation is 4 spaces per indent.
Tabs are not allowed.
It is preferred that every block appears on a new line, so that control structure indentation is always visible.
Code must be formatted by ``black``.

Lines are flowed at 79 columns.
They must not have trailing whitespace.
Long lines must be wrapped using implied line continuation inside parentheses; backslashes aren't allowed.
To handle long import lines, please wrap them inside parentheses:

.. code-block:: python
from very.long.package import (foo, bar, baz,
qux, quux, quuux)
Top-level classes and functions must be separated with 3 blank lines, and class-level functions with 2 blank lines.
The control-L (i.e. ``^L``) form feed character must not be used.


Expand Down Expand Up @@ -178,17 +164,17 @@ While this applies to all packages within Twisted, one ``twisted.python`` deserv
Strings
-------

All strings in Twisted which are not interfacing directly with Python (e.g. ``sys.path`` contents, module names, and anything which returns ``str`` on both Python 2 and 3) should be marked explicitly as "bytestrings" or "text/Unicode strings".
This is done by using the ``b`` (for bytestrings) or ``u`` (for Unicode strings) prefixes when using string literals.
String literals not marked with this are "native/bare strings", and have a different meaning on Python 2 (where a bare string is a bytestring) and Python 3 (where a bare string is a Unicode string).
All literal strings in Twisted which contain binary data must be prefixed with ``b`` (for bytestring).
String literals not marked with this are "native/bare strings", which are Unicode text strings.
The ``u`` prefix for text strings was required to maintain Python 2 and 3 compatibility, but this is no longer required in new code.

.. code-block:: python
u"I am text, also known as a Unicode string!"
"I am a native bare string, and also Unicode!"
b"I am a bytestring!"
"I am a native bare string, and therefore may be either!"
Bytestrings and text must not be implicitly concatenated, as this causes an invisible ASCII encode/decode on Python 2, and causes an exception on Python 3.
Bytestrings and text must not be implicitly concatenated, as this causes an exception.

Use ``+`` to combine bytestrings, not string formatting (either "percent formatting" or ``.format()``).

Expand All @@ -198,9 +184,6 @@ Use ``+`` to combine bytestrings, not string formatting (either "percent formatt
transport.write(b"HTTP/" + HTTPVersion)
Utilities are available in :api:`twisted.python.compat <twisted.python.compat>` to paper over some use cases where other Python code (especially the standard library) expects a "native string", or provides a native string where a bytestring is actually required (namely :api:`twisted.python.compat <twisted.python.compat.nativeString>` and :api:`twisted.python.compat <twisted.python.compat.networkString>`)


String Formatting Operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -229,6 +212,8 @@ Docstrings should always be used to describe the purpose of methods, functions,
Moreover, all methods, functions, classes, and modules must have docstrings.
In addition to documenting the purpose of the object, the docstring must document all of parameters or attributes of the object.

Docstrings must be reflowed at 79 characters.

When documenting a class with one or more attributes which are initialized directly from the value of a ``__init__`` argument by
the same name (or differing only in that the attribute is private), it is sufficient to document the ``__init__`` parameter (in the ``__init__`` docstring).
For example:
Expand Down Expand Up @@ -434,28 +419,6 @@ For example scripts you expect a Twisted user to run from the command-line, add
#!/usr/bin/env python
Standard Library Extension Modules
----------------------------------

When using the extension version of a module for which there is also a Python version, place the import statement inside a try/except block, and import the Python version if the import fails.
This allows code to work on platforms where the extension version is not available.
For example:

.. code-block:: python
try:
import cPickle as pickle
except ImportError:
import pickle
Use the "as" syntax of the import statement as well, to set the name of the extension module to the name of the Python module.

Some modules don't exist across all supported Python versions.
For example, Python 2.3's ``sets`` module was deprecated in Python 2.6 in favor of the ``set`` and ``frozenset`` builtins.
:api:`twisted.python.compat <twisted.python.compat>` would be the place to add ``set`` and ``frozenset`` implementations that work across Python versions.


Classes
-------

Expand All @@ -477,15 +440,6 @@ For example, a Service subclass for Forums might be named ``twisted.forum.servic
Since neither of these modules are volatile *(see above)* the classes may be imported directly into the user's namespace and not cause confusion.


New-style Classes
~~~~~~~~~~~~~~~~~

Classes and instances in Python come in two flavors: old-style or classic, and new-style.
Up to Python 2.1, old-style classes were the only flavour available to the user, new-style classes were introduced in Python 2.2 to unify classes and types.
All classes added to Twisted must be written as new-style classes.
If ``x`` is an instance of a new-style class, then ``type(x)`` is the same as ``x.__class__``.


Methods
-------

Expand Down Expand Up @@ -618,17 +572,6 @@ An attribute (or function, method or class) should be considered private when on
- The attribute is part of a known-to-be-sub-optimal interface and will certainly be removed in a future release.


Python 3
--------

Twisted is being ported to Python 3, targeting Python 3.5+.
Please see :doc:`Porting to Python 3 </core/howto/python3>` for details.

All new modules must be Python 2.7 & 3.5+ compatible, and all new code to ported modules must be Python 2.7 & 3.5+ compatible.
New code in non-ported modules must be written in a 2.7 & 3.5+ compatible way (explicit bytes/unicode strings, new exception raising format, etc) as to prevent extra work when that module is eventually ported.
Code targeting Python 3 specific features must gracefully fall-back on Python 2 as much as is reasonably possible (for example, Python 2 support for 'async/await' is not reasonably possible and would not be required, but code that uses a Python 3-specific module such as ipaddress should be able to use a backport to 2.7 if available).


Database
--------

Expand All @@ -644,10 +587,10 @@ All SQL keywords should be in upper case.
C Code
------

C code must be optional, and work across multiple platforms (MSVC++9/10/14 for Pythons 2.7 and 3.5+ on Windows, as well as recent GCCs and Clangs for Linux, macOS, and FreeBSD).
C code must be optional, and work across multiple platforms (MSVC++14 for Python 3.5+ on Windows, as well as recent GCCs and Clangs for Linux, macOS, and FreeBSD).

C code should be kept in external bindings packages which Twisted depends on.
If creating new C extension modules, using `cffi <https://cffi.readthedocs.io/en/latest/>`_ is highly encouraged, as it will perform well on PyPy and CPython, and be easier to use on Python 2 and 3.
If creating new C extension modules, using `cffi <https://cffi.readthedocs.io/en/latest/>`_ is highly encouraged, as it will perform well on PyPy and CPython.
Consider optimizing for `PyPy <http://pypy.org/performance.html>`_ instead of creating bespoke C code.


Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
name = "Misc"
showcontent = false

[tool.black]
target-version = ['py35', 'py36', 'py37', 'py38']

[tool.isort]
line_length = 79
line_length = 89
sections = "FUTURE,STDLIB,ZOPE,OPENSSL,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
default_section = "THIRDPARTY"
no_lines_before = "LOCALFOLDER"
Expand Down
Empty file.
26 changes: 18 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ deps =
twine: twine

lint: pyflakes
lint: twistedchecker>=0.7.4
lint: diff-cover==0.9.12
lint: pycodestyle

wheels: cibuildwheel==1.3.0

Expand All @@ -82,9 +79,6 @@ setenv =
# Help tests know where the base directory is.
TOX_INI_DIR = {toxinidir}

; Skip twistedchecker warnings that are not yet required in the required run
lint: TWISTEDCHECKER_SKIP_WARNINGS = W9208,C0302,C0103,C9302

; Configure cibuildwheel to build wheels for:
; CPython 3.5, 3.6, 3.7 and 3.8.
; This includes variants of bit depth, unicode width, etc.
Expand Down Expand Up @@ -126,8 +120,6 @@ commands =
wheel: python setup.py bdist_wheel --dist-dir {toxinidir}/dist

lint: /bin/sh -c "pyflakes $(find src/twisted admin bin \! -name "compat.py" \! -name "test_compat.py" \! -name "dict.py" -name '*.py')"
lint: {toxinidir}/.travis/twistedchecker-trunk-diff.sh {posargs:twisted}
lint: /bin/sh -c "git diff $(git merge-base trunk HEAD) | python {toxinidir}/admin/pycodestyle-twisted.py --diff"

apidocs: {toxinidir}/bin/admin/build-apidocs {toxinidir}/src/ apidocs
narrativedocs: sphinx-build -aW -b html -d {toxinidir}/docs/_build {toxinidir}/docs {toxinidir}/docs/_build/
Expand All @@ -148,6 +140,24 @@ deps=https://github.com/twisted/pydoctor/archive/3f9c64829dfa040b334c9ae27c332c7
[testenv:manifest-checker]
skip_install = true

[testenv:lint]
skip_install=True
basepython=python3.5

[testenv:black]
skip_install=True
basepython=python3.6
deps = black>=19.10b0
commands =
black --diff src/

[testenv:black-reformat]
basepython = {[testenv:black]basepython}
skip_install = {[testenv:black]skip_install}
deps = {[testenv:black]deps}
commands =
black {posargs:src/}

[testenv:coverage-prepare]
skip_install=True

Expand Down

0 comments on commit f50fc26

Please sign in to comment.