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

SDK namespace package #55

Merged
merged 9 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions opentelemetry-api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import setuptools

BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(
BASE_DIR, "src", "opentelemetry", "internal", "version.py")
VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "version.py")
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO) #pylint:disable=exec-used
exec(f.read(), PACKAGE_INFO)

setuptools.setup(
name="opentelemetry-api",
version=PACKAGE_INFO["__version__"], # noqa
version=PACKAGE_INFO["__version__"],
author="OpenTelemetry Authors",
author_email="[email protected]",
classifiers=[
Expand All @@ -47,7 +46,8 @@
extras_require={},
license="Apache-2.0",
package_dir={"": "src"},
packages=setuptools.find_namespace_packages(where="src"),
packages=setuptools.find_namespace_packages(where="src",
include="opentelemetry.*"),
url=("https://github.com/open-telemetry/opentelemetry-python"
"/tree/master/opentelemetry-api"),
zip_safe=False,
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
created as children of the currently active span, and the newly-created span
becomes the new active span::

# TODO (#15): which module holds the global tracer?
from opentelemetry.api.trace import tracer
from opentelemetry.trace import tracer

# Create a new root span, set it as the current span in context
with tracer.start_span("parent"):
Expand Down
20 changes: 12 additions & 8 deletions opentelemetry-sdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import os
import setuptools

base_dir = os.path.dirname(__file__)

package_info = {}
with open(os.path.join(base_dir, "src", "opentelemetry", "sdk", "version.py")) as f:
exec(f.read(), package_info)
BASE_DIR = os.path.dirname(__file__)
VERSION_FILENAME = os.path.join(BASE_DIR, "src", "opentelemetry", "sdk",
"version.py")
PACKAGE_INFO = {}
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(
name="opentelemetry-sdk",
version=package_info["__version__"], # noqa
version=PACKAGE_INFO["__version__"],
author="OpenTelemetry Authors",
author_email="[email protected]",
classifiers=[
Expand All @@ -41,11 +42,14 @@
include_package_data=True,
long_description=open("README.rst").read(),
install_requires=[
"opentelemetry-api==0.1.dev0"
],
extras_require={},
license="Apache-2.0",
package_dir={"": "src"},
packages=setuptools.find_namespace_packages(where="src"),
url="https://github.com/open-telemetry/opentelemetry-python/tree/master/opentelemetry-sdk",
packages=setuptools.find_namespace_packages(where="src",
include="opentelemetry.sdk.*"),
url=("https://github.com/open-telemetry/opentelemetry-python"
"/tree/master/opentelemetry-sdk"),
zip_safe=False,
)
6 changes: 5 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .version import __version__
from . import trace

__all__ = [
"trace",
]
19 changes: 19 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2019, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from opentelemetry import trace as trace_api


class Tracer(trace_api.Tracer):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .version import __version__

__all__ = [
"__version__",
]
25 changes: 25 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2019, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from opentelemetry import trace as trace_api
from opentelemetry.sdk import trace


class TestTracer(unittest.TestCase):

def test_extends_api(self):
tracer = trace.Tracer()
self.assertIsInstance(tracer, trace_api.Tracer)
22 changes: 15 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist = True
envlist = py{34,35,36,37}-test, lint, py37-mypy, docs
envlist = py{34,35,36,37}-test-{api,sdk}, lint, py37-mypy, docs

[travis]
python =
Expand All @@ -11,24 +11,32 @@ deps =
mypy: mypy~=0.711

setenv =
PYTHONPATH={toxinidir}/opentelemetry-api/src/
mypy: MYPYPATH={env:PYTHONPATH}
mypy: MYPYPATH={toxinidir}/opentelemetry-api/src/
Copy link
Member Author

Choose a reason for hiding this comment

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

Setting PYTHONPATH instead of installing the package was a kludge. It may be possible to get mypy to pass without setting MYPYPATH here, but just installing the packages didn't seem to do it.


changedir =
test: opentelemetry-api/tests
test-api: opentelemetry-api/tests
test-sdk: opentelemetry-sdk/tests
Copy link
Member Author

Choose a reason for hiding this comment

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

We may not want separate test targets in the long run, but this was the easiest way to get test discovery to work since opentelemetry isn't a package (with an __init__.py) anymore.

Copy link
Member

Choose a reason for hiding this comment

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

We want to remove opentelemetry/__init__.py after we workaround the pylint discovery issue #37 (comment).


commands_pre =
test-api: pip install -e {toxinidir}/opentelemetry-api
test-sdk: pip install -e {toxinidir}/opentelemetry-api
test-sdk: pip install -e {toxinidir}/opentelemetry-sdk
Copy link
Member Author

Choose a reason for hiding this comment

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

It would be better to install these as regular deps so they're not reinstalled on each run. There may be another better way to do this.


commands =
py37-mypy: mypy opentelemetry-api/src/opentelemetry/
mypy: mypy --namespace-packages opentelemetry-api/src/opentelemetry/
Copy link
Member Author

Choose a reason for hiding this comment

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

See python/mypy#1645, mypy fails to find opentelemetry.api without this flag.

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

[testenv:lint]
deps =
pylint~=2.3
flake8~=3.7
isort~=4.3

commands_pre =
pip install -e {toxinidir}/opentelemetry-api

commands =
; Prefer putting everything in one pylint command to profit from duplication
; warnings.
Expand Down