Skip to content

Commit

Permalink
Simplify imports (#594)
Browse files Browse the repository at this point in the history
* Changed import of reexport to explicit and bumped version

* Replaced all import * with explicit imports and moved global update into a function

* Formatting with yapf applied.\nVersion reverted to orig version 0.5.0+dev\nPipenv files added to gitignore

* Added tests for pylint and jedi

* Fixed formatting

* Added pylint and jedit to test-requirements.txt for tests

* Fixed path to be POSIX and Windows path

* Replaced trio/__init__.py with trio.__file__

* Module names for _core and _run are currently broken

* Changed import of reexport to explicit and bumped version

* Formatting with yapf applied.\nVersion reverted to orig version 0.5.0+dev\nPipenv files added to gitignore

* Added tests for pylint and jedi

* Fixed path to be POSIX and Windows path

* Module names for _core and _run are currently broken

* replaced __all__ with namespace iteration and added pylint and jedi test

* replaced __all__ with namespace iteration and added pylint and jedi test

* merged with 0.6.0 rebase

* rebase continuation

* Fix formating with yapf

* Removed _top_level_imports.py

* Reformatted with new yapf version 0.22 and skipped yedi test for 3.8-dev

* Fixed format in test_exports.py

* Fixed mising import of pytest in test_exports.py

* Changed reson message for jedi test being skipped

* Moved to exception handling instead of pytest decorator for skipping test on non supported jedi python version

* changed TLD of readthedocs from org to io

* Addressed temporary issue with __all__ being still present in _core but not in trio

* more changes accepted

* rebasing

* Changed import of reexport to explicit and bumped version

* Added tests for pylint and jedi

* Fixed formatting

* Fixed path to be POSIX and Windows path

* replaced __all__ with namespace iteration and added pylint and jedi test

* rebase continuation

* Fix formating with yapf

* Reformatted with new yapf version 0.22 and skipped yedi test for 3.8-dev

* Fixed format in test_exports.py

* Addressed temporary issue with __all__ being still present in _core but not in trio

* Rebase formatting

* Fixed formatting after rebase

* Synced .gitignore

* removed again TaskLocal from trio/__init__.py

* reverted docs changes, removed TESTING variable and removed explicit list from _core/__init__.py

* Changed jedi completion test script to be an explicit script

* added open_signal_receiver to trio/__init__.py and _toplevel_core_reexports.py

* Fixed formatting of trio/_toplevel_core_reexports.py

* Added extra space after curly brace to check what happens about yapf on ci complaining about formatting

* Deleted trio/_toplevel_core_reexports.py
  • Loading branch information
jmfrank63 authored and Zac-HD committed Sep 8, 2018
1 parent 8e16393 commit 312b470
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 72 deletions.
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ ipython # for the IPython traceback integration tests
pyOpenSSL # for the ssl tests
trustme # for the ssl tests
pytest-faulthandler
pylint # for pylint finding all symbols tests
jedi # for jedi code completion tests
66 changes: 34 additions & 32 deletions trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,61 @@

from ._version import __version__

__all__ = []
from ._core import (
TrioInternalError, RunFinishedError, WouldBlock, Cancelled,
ResourceBusyError, ClosedResourceError, MultiError, run, open_nursery,
open_cancel_scope, current_effective_deadline, TASK_STATUS_IGNORED,
current_time
)

from ._toplevel_core_reexports import *
__all__ += _toplevel_core_reexports.__all__
from ._timeouts import (
move_on_at, move_on_after, sleep_forever, sleep_until, sleep, fail_at,
fail_after, TooSlowError
)

from ._timeouts import *
__all__ += _timeouts.__all__
from ._sync import (
Event, CapacityLimiter, Semaphore, Lock, StrictFIFOLock, Condition, Queue
)

from ._sync import *
__all__ += _sync.__all__
from ._threads import (
run_sync_in_worker_thread, current_default_worker_thread_limiter,
BlockingTrioPortal
)

from ._threads import *
__all__ += _threads.__all__
from ._highlevel_generic import (
aclose_forcefully, BrokenStreamError, StapledStream
)

from ._highlevel_generic import *
__all__ += _highlevel_generic.__all__
from ._signals import catch_signals, open_signal_receiver

from ._signals import *
__all__ += _signals.__all__
from ._highlevel_socket import SocketStream, SocketListener

from ._highlevel_socket import *
__all__ += _highlevel_socket.__all__
from ._file_io import open_file, wrap_file

from ._file_io import *
__all__ += _file_io.__all__
from ._path import Path

from ._path import *
__all__ += _path.__all__
from ._highlevel_serve_listeners import serve_listeners

from ._highlevel_serve_listeners import *
__all__ += _highlevel_serve_listeners.__all__
from ._highlevel_open_tcp_stream import open_tcp_stream

from ._highlevel_open_tcp_stream import *
__all__ += _highlevel_open_tcp_stream.__all__
from ._highlevel_open_tcp_listeners import open_tcp_listeners, serve_tcp

from ._highlevel_open_tcp_listeners import *
__all__ += _highlevel_open_tcp_listeners.__all__
from ._highlevel_open_unix_stream import open_unix_socket

from ._highlevel_open_unix_stream import *
__all__ += _highlevel_open_unix_stream.__all__
from ._highlevel_ssl_helpers import (
open_ssl_over_tcp_stream, open_ssl_over_tcp_listeners, serve_ssl_over_tcp
)

from ._highlevel_ssl_helpers import *
__all__ += _highlevel_ssl_helpers.__all__

from ._deprecate import *
__all__ += _deprecate.__all__
from ._deprecate import TrioDeprecationWarning

# Imported by default
from . import hazmat
from . import socket
from . import abc
from . import ssl
# Not imported by default: testing
if False:
from . import testing

_deprecate.enable_attribute_deprecations(__name__)
__deprecated_attributes__ = {
Expand Down
2 changes: 0 additions & 2 deletions trio/_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import attr

__all__ = ["TrioDeprecationWarning"]


# We want our warnings to be visible by default (at least for now), but we
# also want it to be possible to override that using the -W switch. AFAICT
Expand Down
33 changes: 0 additions & 33 deletions trio/_toplevel_core_reexports.py

This file was deleted.

6 changes: 3 additions & 3 deletions trio/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def fix_one(obj):
for attr_value in obj.__dict__.values():
fix_one(attr_value)

for objname in namespace["__all__"]:
obj = namespace[objname]
fix_one(obj)
for objname, obj in namespace.items():
if not objname.startswith("_"): # ignore private attributes
fix_one(obj)


# os.fspath is defined on Python 3.6+ but we need to support Python 3.5 too
Expand Down
34 changes: 32 additions & 2 deletions trio/tests/test_exports.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
import trio
import trio.testing

import jedi
import os
import pytest
import sys

from pylint.lint import PyLinter

from .. import _core


def test_core_is_properly_reexported():
# Each export from _core should be re-exported by exactly one of these
# three modules:
sources = [trio, trio.hazmat, trio.testing]
for symbol in _core.__all__:
for symbol in dir(_core):
if symbol.startswith('_') or symbol == 'tests':
continue
found = 0
for source in sources:
if (
symbol in source.__all__
symbol in dir(source)
and getattr(source, symbol) is getattr(_core, symbol)
):
found += 1
print(symbol, found)
assert found == 1


def test_pylint_sees_all_non_underscore_symbols_in_namespace():
# Test pylints ast to contain the same content as dir(trio)
linter = PyLinter()
ast_set = set(linter.get_ast(trio.__file__, 'trio'))
trio_set = set([symbol for symbol in dir(trio) if symbol[0] != '_'])
trio_set.remove('tests')
assert trio_set - ast_set == set([])


def test_jedi_sees_all_completions():
# Test the jedi completion library get all in dir(trio)
try:
script = jedi.Script("import trio; trio.")
completions = script.completions()
trio_set = set([symbol for symbol in dir(trio) if symbol[:2] != '__'])
jedi_set = set([cmp.name for cmp in completions])
assert trio_set - jedi_set == set([])
except NotImplementedError:
pytest.skip("jedi does not yet support {}".format(sys.version))

0 comments on commit 312b470

Please sign in to comment.