-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
[Question] __init__.py is not required in package root. #626
Comments
This is the commit message
|
Yes this is absolutely, correct with all the sub directories. This makes python see all modules in the directories as they were merged in one file on But I was just wondering, whether it is required for package root, too, as all the files there are explicitly loaded by A Same with unit testing. I have the UnitTesting package installed. It is used in GitGutter for the promise module. It works with or without Your reload module and the Automatic Package Reloader plugin recognize packages without init.py, too. On the opposite, ST3 explicitly loads init.py as it was a normal module implementing some normal functions. All those facts make me wonder, what's the sense of this file as it obviously does not have any function or meaning in this special case. So I assume it is not required and won't add such a file to GitGutter. This was the reason for my question. Thanks. |
The For example in
Without the To clarify what I meant in the commit, the use cases for this structure are for following imports outside of sublime, i.e without it the below would not be possible:
If that answers your question @deathaxe , please go ahead and close the issue. |
Ok, thanks for your answer. Never took into account, that you use some modules directly in python without ST. So I won't need such a file as ST3 always creates a package from the root directory. |
python3 disallows _implicit_ relative imports. So, I made the test utility imports _explicit_: ```python from test import libvtd_test ``` (The `from test ` prefix is new.) There's another problem: the tests can't access the library code in python3. Within this repo, `libvtd` and `test` are _sibling_ packages---but with no common _root_ package. Thus, the `test` package can't find the `libvtd` package. The simplest solution I could think of was to just make the root into a package, even though there's no python code. (A similar approach has been taken by others, e.g., timbrel/GitSavvy#626.) Now instead of 2 errors, we get 30 errors when running under python3. But that's progress: the old errors were `ImportError`, and they were masking all the runtime errors we couldn't even reach before. So we probably have something like a true burndown list, at last. Another way to test this commit is to comment out all of the test bodies (i.e., everything after the `import` section), and the tests will all pass under python3 (well, all 0 of them). Helps #3.
python3 disallows _implicit_ relative imports. So, I made the test utility imports _explicit_: ```python from test import libvtd_test ``` (The `from test ` prefix is new.) There's another problem: the tests can't access the library code in python3. Within this repo, `libvtd` and `test` are _sibling_ packages---but with no common _root_ package. Thus, the `test` package can't find the `libvtd` package. The simplest solution I could think of was to just make the root into a package, even though there's no python code. (A similar approach has been taken by others, e.g., timbrel/GitSavvy#626.) Now instead of 2 errors, we get 30 errors when running under python3. But that's progress: the old errors were `ImportError`, and they were masking all the runtime errors we couldn't even reach before. So we probably have something like a true burndown list, at last. Another way to test this commit is to comment out all of the test bodies (i.e., everything after the `import` section), and the tests will all pass under python3 (well, all 0 of them). Helps #3.
I have a kind question just for my own interest.
Why do you add an
__init__.py
to package root? None of the default packages do that and there seems absolutely no drawback when removing it.It is very fine to use it to "merge" all files in the sub directories to one package, but as far as I know, it doesn't make sense in the package root. It is explicitly loaded by ST just like a normal python file but without any functionality.
The suggestions discussed here don't use it, too, even though all python modules are placed in a
src
sub directory.I guess the git_savvy.py is the only needed python file in the root.
The text was updated successfully, but these errors were encountered: