Skip to content

Commit

Permalink
Ensure that type info is picked up from installed package. (#124)
Browse files Browse the repository at this point in the history
* Ensure that type info is picked up from installed package.

This required moving all top-level modules to a sub-package, to not
create collisions with py.typed marker files.

See https://www.python.org/dev/peps/pep-0561/#packaging-type-information

* Add MANIFEST.in for SDK package.
  • Loading branch information
Oberon00 authored Sep 16, 2019
1 parent 46ae415 commit 531d0b1
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 14 deletions.
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ abstract types for OpenTelemetry implementations.
:caption: Contents:

opentelemetry.context
opentelemetry.loader
opentelemetry.util.loader
opentelemetry.metrics
opentelemetry.trace
opentelemetry.util.loader


Indices and tables
Expand Down
4 changes: 0 additions & 4 deletions docs/opentelemetry.loader.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/opentelemetry.util.loader.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
opentelemetry.util.loader module
================================

.. automodule:: opentelemetry.util.loader
7 changes: 7 additions & 0 deletions opentelemetry-api/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prune tests
graft src
global-exclude *.pyc
global-exclude *.pyo
global-exclude __pycache__/*
include MANIFEST.in
include README.rst
4 changes: 3 additions & 1 deletion opentelemetry-api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import setuptools

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "version.py")
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "util", "version.py"
)
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import typing
from contextlib import contextmanager

from opentelemetry import loader, types
from opentelemetry.util import loader, types

# TODO: quarantine
ParentSpan = typing.Optional[typing.Union["Span", "SpanContext"]]
Expand Down Expand Up @@ -445,7 +445,7 @@ def use_span(self, span: "Span") -> typing.Iterator[None]:

# Once https://github.com/python/mypy/issues/7092 is resolved,
# the following type definition should be replaced with
# from opentelemetry.loader import ImplementationFactory
# from opentelemetry.util.loader import ImplementationFactory
ImplementationFactory = typing.Callable[
[typing.Type[Tracer]], typing.Optional[Tracer]
]
Expand Down Expand Up @@ -474,7 +474,7 @@ def set_preferred_tracer_implementation(
) -> None:
"""Set the factory to be used to create the tracer.
See :mod:`opentelemetry.loader` for details.
See :mod:`opentelemetry.util.loader` for details.
This function may not be called after a tracer is already loaded.
Expand Down
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions opentelemetry-api/tests/mypysmoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import opentelemetry.trace


def dummy_check_mypy_returntype() -> opentelemetry.trace.Tracer:
return opentelemetry.trace.tracer()
3 changes: 2 additions & 1 deletion opentelemetry-api/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import unittest
from importlib import reload

from opentelemetry import loader, trace
from opentelemetry import trace
from opentelemetry.util import loader

DUMMY_TRACER = None

Expand Down
7 changes: 7 additions & 0 deletions opentelemetry-sdk/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prune tests
graft src
global-exclude *.pyc
global-exclude *.pyo
global-exclude __pycache__/*
include MANIFEST.in
include README.rst
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from contextlib import contextmanager

from opentelemetry import trace as trace_api
from opentelemetry import types
from opentelemetry.context import Context
from opentelemetry.sdk import util
from opentelemetry.util import types

logger = logging.getLogger(__name__)

Expand Down
16 changes: 13 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
py3{4,5,6,7,8}-test-{api,sdk,example-app,ext-wsgi,ext-http-requests}
pypy3-test-{api,sdk,example-app,ext-wsgi,ext-http-requests}
lint
py37-mypy
py37-{mypy,mypyinstalled}
docs

[travis]
Expand All @@ -14,7 +14,7 @@ python =

[testenv]
deps =
mypy: mypy~=0.711
mypy,mypyinstalled: mypy~=0.711

setenv =
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/
Expand All @@ -39,11 +39,21 @@ commands_pre =
wsgi: pip install {toxinidir}/ext/opentelemetry-ext-wsgi
http-requests: pip install {toxinidir}/ext/opentelemetry-ext-http-requests

; Using file:// here because otherwise tox invokes just "pip install
; opentelemetry-api", leading to an error
mypyinstalled: pip install file://{toxinidir}/opentelemetry-api/

commands =
test: python -m unittest discover

mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
; For test code, we don't want to enforce the full mypy strictness
mypy: mypy --namespace-packages --config-file=mypy-relaxed.ini opentelemetry-api/tests/
test: python -m unittest discover

; Test that mypy can pick up typeinfo from an installed package (otherwise,
; implicit Any due to unfollowed import would result).
mypyinstalled: mypy --namespace-packages opentelemetry-api/tests/mypysmoke.py --strict


[testenv:lint]
basepython: python3.7
Expand Down

0 comments on commit 531d0b1

Please sign in to comment.