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

Improve package layout #37

Merged
merged 3 commits into from
Jul 1, 2019
Merged

Improve package layout #37

merged 3 commits into from
Jul 1, 2019

Conversation

reyang
Copy link
Member

@reyang reyang commented Jun 27, 2019

The reason for introducing src folder:

  1. Using wildcard approach would match tests/foo/bar/opentelemetry/ as well, which we want to avoid. The name filter in setuptools is implemented using fnmatchcase, which doesn't provide a good way to workaround this.
  2. If we run setup.py under the opentelemetry-api folder, it will generate temporary folder structure build/lib/opentelemetry/, which will be accidentally included in the package.

description="OpenTelemetry Python SDK",
include_package_data=True,
long_description=open("README.rst").read(),
install_requires=[
Copy link
Member Author

Choose a reason for hiding this comment

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

opentelemetry-sdk will have dependency on opentelemetry-api, this will be a separate PR (we need to figure out how to install from local).

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

I was skeptical of src/, but this looks good and the setuptools docs confirm that this is the best way to do this.

You'll have to change the paths in tox.ini to get the tests to pass.

# See the License for the specific language governing permissions and
# limitations under the License.

from .version 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.

Why do you need this?

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 was thinking about troubleshooting scenario, where we want to see which version of the SDK customers are using, we do need to distinguish SDK versions versus API versions.
For example, if the queue for traces are full, I'd expect we log something like:

2019-06-27T22:36:59Z OpenTelemetry API loaded (version=1.0.0)
2019-06-27T22:37:15Z OpenTelemetry SDK loaded (version=1.0.3)
2019-06-27T22:38:30Z traces queue full, started to drop spans
2019-06-27T22:38:50Z traces queue recovered

Copy link
Member

Choose a reason for hiding this comment

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

I mean why do you need to import it here instead of in whatever module uses it (the trace queue in your example)?

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 see, my intent was to save some typing, so we can import sdk.__version__ instead of sdk.version.__version__. Later we can probably rename version.py to package_info.py if we have more stuff to put here.


package_info = {}
with open(os.path.join(base_dir, "src", "opentelemetry", "sdk", "version.py")) as f:
exec(f.read(), package_info)
Copy link
Member

Choose a reason for hiding this comment

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

Why use package_info instead of read/exec-ing right into globals?

Copy link
Member Author

@reyang reyang Jun 28, 2019

Choose a reason for hiding this comment

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

To prevent bad thing inside the version.py (later we might add more stuff such like SDK vendor info and rename the file to package_info.py) from polluting globals.

# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.1.dev0"
Copy link
Member

Choose a reason for hiding this comment

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

Should you move the API version file out of internal/ to match?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean something like opentelemetry/api/version.py? We decided to put version.py in internal since there is no public interface. I'm open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

I take #19 (review) to mean that we can't have a single top-level version file, but separate files under api/ and sdk/ should be fine.

@@ -8,5 +8,5 @@ deps =
py37-mypy: mypy

commands =
py37-lint: pylint opentelemetry-api/opentelemetry/
py37-mypy: mypy opentelemetry-api/opentelemetry/
py37-lint: pylint 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.

@c24t do you think it's good idea to run lint on opentelemetry-api (which includes setup.py, tests, examples)?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, if it ends up being easier to blacklist dirs that shouldn't be linted than to whitelist every one that should.

@reyang
Copy link
Member Author

reyang commented Jun 28, 2019

You'll have to change the paths in tox.ini to get the tests to pass.

I noticed that we got some trouble here. The reason why Travis + Tox work for us is because we have the file opentelemetry/__init__.py, while we shouldn't have it (since it is a namespace package).
If we want to fix this problem, we need to workaround this pylint bug.

For this PR, I reverted the __init__.py file back. Will create a separate issue to track it.

@@ -8,5 +8,5 @@ deps =
py37-mypy: mypy

commands =
py37-lint: pylint opentelemetry-api/opentelemetry/
py37-mypy: mypy opentelemetry-api/opentelemetry/
py37-lint: pylint opentelemetry-api/src/opentelemetry/
Copy link
Member

Choose a reason for hiding this comment

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

Sure, if it ends up being easier to blacklist dirs that shouldn't be linted than to whitelist every one that should.

# See the License for the specific language governing permissions and
# limitations under the License.

from .version 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 mean why do you need to import it here instead of in whatever module uses it (the trace queue in your example)?

# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.1.dev0"
Copy link
Member

Choose a reason for hiding this comment

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

I take #19 (review) to mean that we can't have a single top-level version file, but separate files under api/ and sdk/ should be fine.

@reyang reyang merged commit 7e3f9a1 into master Jul 1, 2019
@reyang reyang deleted the layout branch July 1, 2019 21:31
c24t added a commit to c24t/opentelemetry-python that referenced this pull request Jul 2, 2019
@reyang reyang mentioned this pull request Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants