Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify imports #594

Merged
merged 51 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
988fcf7
Changed import of reexport to explicit and bumped version
jmfrank63 Aug 7, 2018
a922db6
Replaced all import * with explicit imports and moved global update i…
jmfrank63 Aug 7, 2018
a9398a3
Formatting with yapf applied.\nVersion reverted to orig version 0.5.0…
jmfrank63 Aug 9, 2018
0651a6b
Added tests for pylint and jedi
jmfrank63 Aug 17, 2018
e668514
Fixed formatting
jmfrank63 Aug 17, 2018
0e1bf15
Added pylint and jedit to test-requirements.txt for tests
jmfrank63 Aug 17, 2018
6a42ded
Fixed path to be POSIX and Windows path
jmfrank63 Aug 17, 2018
e87a040
Replaced trio/__init__.py with trio.__file__
jmfrank63 Aug 17, 2018
a340b90
Module names for _core and _run are currently broken
jmfrank63 Aug 18, 2018
7421d65
replaced __all__ with namespace iteration and added pylint and jedi test
jmfrank63 Aug 22, 2018
d8cfb8e
merged with 0.6.0 rebase
jmfrank63 Aug 22, 2018
ca57e08
rebase continuation
jmfrank63 Aug 22, 2018
b99ac7e
Fix formating with yapf
jmfrank63 Aug 22, 2018
f95aeea
Removed _top_level_imports.py
jmfrank63 Aug 22, 2018
1ec2c0a
Reformatted with new yapf version 0.22 and skipped yedi test for 3.8-dev
jmfrank63 Aug 23, 2018
d8e2ac9
Fixed format in test_exports.py
jmfrank63 Aug 23, 2018
5bd0390
Fixed mising import of pytest in test_exports.py
jmfrank63 Aug 23, 2018
dde4d28
Changed reson message for jedi test being skipped
jmfrank63 Aug 23, 2018
0bd82f7
Moved to exception handling instead of pytest decorator for skipping …
jmfrank63 Aug 23, 2018
dad3880
changed TLD of readthedocs from org to io
jmfrank63 Aug 23, 2018
f13dd09
Addressed temporary issue with __all__ being still present in _core b…
jmfrank63 Aug 23, 2018
b3e4ff7
more changes accepted
jmfrank63 Aug 23, 2018
90ae080
Changed import of reexport to explicit and bumped version
jmfrank63 Aug 7, 2018
a3cb3a4
Formatting with yapf applied.\nVersion reverted to orig version 0.5.0…
jmfrank63 Aug 9, 2018
5c6f1b3
Added tests for pylint and jedi
jmfrank63 Aug 17, 2018
a90563c
Fixed path to be POSIX and Windows path
jmfrank63 Aug 17, 2018
057ed5b
Module names for _core and _run are currently broken
jmfrank63 Aug 18, 2018
61c05ce
replaced __all__ with namespace iteration and added pylint and jedi test
jmfrank63 Aug 22, 2018
19ff27e
rebasing
jmfrank63 Aug 23, 2018
cb05c86
Changed import of reexport to explicit and bumped version
jmfrank63 Aug 7, 2018
54f07de
rebase continuation
jmfrank63 Aug 22, 2018
933cdd0
Added tests for pylint and jedi
jmfrank63 Aug 17, 2018
026c380
Fixed formatting
jmfrank63 Aug 17, 2018
a38c381
Fixed path to be POSIX and Windows path
jmfrank63 Aug 17, 2018
f39acef
replaced __all__ with namespace iteration and added pylint and jedi test
jmfrank63 Aug 22, 2018
74fe457
Fix formating with yapf
jmfrank63 Aug 22, 2018
b97217d
Reformatted with new yapf version 0.22 and skipped yedi test for 3.8-dev
jmfrank63 Aug 23, 2018
e10619f
Fixed format in test_exports.py
jmfrank63 Aug 23, 2018
78dc15d
Addressed temporary issue with __all__ being still present in _core b…
jmfrank63 Aug 23, 2018
be19351
Rebase formatting
jmfrank63 Aug 23, 2018
5ad48b2
Fixed formatting after rebase
jmfrank63 Aug 23, 2018
e7d2fe0
Readded trio/_toplevel_core_reexports.py
jmfrank63 Sep 7, 2018
5fc025b
Synced .gitignore
jmfrank63 Sep 7, 2018
d569f5e
removed again TaskLocal from trio/__init__.py
jmfrank63 Sep 7, 2018
79e177e
reverted docs changes, removed TESTING variable and removed explicit …
jmfrank63 Sep 7, 2018
fe82149
Changed jedi completion test script to be an explicit script
jmfrank63 Sep 7, 2018
1520424
added open_signal_receiver to trio/__init__.py and _toplevel_core_ree…
jmfrank63 Sep 7, 2018
04106c0
Fixed formatting of trio/_toplevel_core_reexports.py
jmfrank63 Sep 7, 2018
fcc808d
Merge branch 'master' into simplify_imports
jmfrank63 Sep 8, 2018
3afdb8b
Added extra space after curly brace to check what happens about yapf …
jmfrank63 Sep 8, 2018
b492ebb
Deleted trio/_toplevel_core_reexports.py
jmfrank63 Sep 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worthwhile to factor out some of the namespace cleanup code from the two functions – I think in both cases we want to test something like: "the two sets are equivalent, if you ignore names that .startswith("_"), "tests", and "testing""?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll work myself through all the comments. Will take some time as this is all new stuff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, take your time, and don't be afraid to ask for help if you get stuck :-)

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))