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

Find project root when run from a wheel (logger module) #43

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 5 additions & 1 deletion src/databricks/labs/blueprint/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@
Idiomatic usage is: find_project_root(__file__)
"""
this_path = Path(__file)
# TODO: detect when in wheel seems to be more challenging and pkgutil.get_data() might be necessary

for leaf in ("pyproject.toml", "setup.py"):
root = find_dir_with_leaf(this_path, leaf)
if root is not None:
return root
# Wheel installation is under site-packages hence return the parent of site-packages
if "site-packages" in __file:
return Path(__file.split("site-packages")[0] + "site-packages/")

Check warning on line 51 in src/databricks/labs/blueprint/entrypoint.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/blueprint/entrypoint.py#L51

Added line #L51 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

And what if there are many modules with "about.py"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is presenting a workaround since we don't do anything with PROJECT_ROOT variables, to answer your question it doesn't matter, the path is going to be set from Python env location where wheel file is installed.

Ideally just rewriting the get_logger to get module name directly would make sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please take a look at the usages of this function in the library.

As for remoph - logging.get_logger(name) might be enough. The utility of blueprint is to help only when name is main


msg = "Cannot find project root"
raise NotADirectoryError(msg)

Expand Down
Loading