Skip to content

Initial API package layout #19

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

Merged
merged 3 commits into from
Jun 20, 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
4 changes: 4 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## Unreleased
- Initial release
19 changes: 19 additions & 0 deletions opentelemetry-api/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
OpenTelemetry Python API
============================================================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-api.svg
:target: https://pypi.org/project/opentelemetry-api/

Installation
------------

::

pip install opentelemetry-api

References
----------

* `OpenTelemetry Project <https://opentelemetry.io/>`_
1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't support Python 2 anyway (and probably not <3.3 too), why use the pkgutil style and not the implicit, native style for namespace packages? https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages

Caveat: I've never created a namespace package before, so this is just me reading the docs and wondering.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll update it in my next PR.

1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/context/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
19 changes: 19 additions & 0 deletions opentelemetry-api/opentelemetry/internal/__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 .version import __version__
Copy link
Member Author

Choose a reason for hiding this comment

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

In OpenCensus we avoid the relative import. I wonder how people think about using relative versus absolute import in OpenTelemetry.

The following article explored the pros and cons.
https://realpython.com/absolute-vs-relative-python-imports/

Copy link
Member

Choose a reason for hiding this comment

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

I like relative imports and use them in personal projects. The google style guide says to import modules using the full path, but the justification for doing this only applies to implicit relative imports:

Avoids conflicts in module names or incorrect imports due to the module search path not being what the author expected

Since implicit relative imports are gone in python 3 I think this is fine. If we decide to use it we should make sure we use this import style everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

@carlosalberto @Oberon00 I'll merge the PR first, please comment here if you see potential issue that could bite us. Thanks.


__all__ = [
"__version__",
]
15 changes: 15 additions & 0 deletions opentelemetry-api/opentelemetry/internal/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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.

__version__ = "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this in internal/ instead of the top level 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.

Put it in internal/ since version is not part the specification yet.

We don't have a good way to put it under top level opentelemetry/ if we want multiple packages to share the same namespace (namespace package).

Copy link
Member

Choose a reason for hiding this comment

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

Also, as we make a namespace package, one could, in theory, have different versions of SDK and API subpackages, so it doesn't even make sense semantically to put the version out at the top level.

1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/logs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1 change: 1 addition & 0 deletions opentelemetry-api/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
46 changes: 46 additions & 0 deletions opentelemetry-api/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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 setuptools import find_packages
from setuptools import setup
from opentelemetry.internal import __version__
Copy link
Member

Choose a reason for hiding this comment

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

I thought that does not work? I mean, importing from the package you are about to install but that is not yet installed. See https://packaging.python.org/guides/single-sourcing-package-version/. That guide notes that such an import can fail if some packages from install_requires would be required. I think, since we already have a dedicated version file now, we could use approach 3: "Set the value to a version global variable in a dedicated module in your project (e.g. version.py), then have setup.py read and exec the value into a variable."

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll investigate. Approach 3 looks reasonable.


setup(
name="opentelemetry-api",
version=__version__, # noqa
author="OpenTelemetry Authors",
author_email="[email protected]",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
description="OpenTelemetry Python API",
include_package_data=True,
long_description=open("README.rst").read(),
install_requires=[
],
Copy link
Member

Choose a reason for hiding this comment

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

Nit: lose the newline

Copy link
Member Author

Choose a reason for hiding this comment

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

I put this way as we will add the contextvars backport dependency, which will be one line change instead of three.

extras_require={},
license="Apache-2.0",
packages=find_packages(exclude=("examples", "tests",)),
namespace_packages=[],
url="https://github.com/open-telemetry/opentelemetry-python/opentelemetry-api",
Copy link
Member

Choose a reason for hiding this comment

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

That's a 404. You'd need to add /blob/master in the URL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

zip_safe=False,
)