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

Add __init__.py files in all the directories #2503

Merged
merged 1 commit into from Sep 28, 2020

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 28, 2020

Fixes: #2502

Please check if there's any directory where it's not needed.

Describe your change:

  • Fix a bug or typo in an existing algorithm?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
@TravisBuddy
Copy link

@TravisBuddy TravisBuddy commented Sep 28, 2020

Travis tests have failed

Hey @dhruvmanila,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: f7a588e0-017e-11eb-9be6-0d9634a5fbe7
@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Sep 28, 2020

That was a disaster! Let me see what's going on in there.

@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Sep 28, 2020

@cclauss Ok, I found the reason for all the errors.
The errors are happening because of how namespace packages work. As we're adding all the __init__.py files, we're basically creating sub-packages in our parent directory (Python/). What this means is that if we want to use import in a file inside a sub-directory, then we need to import using the dot notation or relative to the parent directory.

For example:
In ciphers/affine_cipher.py, instead of import cryptomath_module as cryptomath we will have to do import ciphers.cryptomath_module as cryptomath

This doesn't seem like a viable solution so I will take a further look into this.

@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Sep 28, 2020

I don't think there's any other choice if we're adding the __init__.py files.
It also seems that in some of the files we're using relative imports and in others we're using absolute. It would be better, in the long run, to stick with one. For more information on relative imports: https://docs.python.org/3/reference/import.html#package-relative-imports

If we're importing a module from the current directory we should use either relative or absolute imports and not just import module or from module import function:

  • from parent.module import function
  • from . import module
  • from ..module import function
  • import parent.module

Remember that a module is just another Python file.

@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Sep 28, 2020

I fixed all the imports on my local copy and it fixes everything up.
Shall I make a PR to fix the imports? @cclauss

@cclauss cclauss merged commit 48357ce into TheAlgorithms:master Sep 28, 2020
1 of 2 checks passed
1 of 2 checks passed
codespell
Details
Travis CI - Pull Request Build Failed
Details
@cclauss
Copy link
Member

@cclauss cclauss commented Sep 28, 2020

Yes. please. Just the changes required to get Travis CI to be again.

@dhruvmanila dhruvmanila deleted the dhruvmanila:patch-mypy branch Sep 28, 2020
@dhruvmanila dhruvmanila mentioned this pull request Sep 28, 2020
5 of 5 tasks complete
@AayushDadhich
Copy link

@AayushDadhich AayushDadhich commented Oct 1, 2020

Typo

in data structures directory folder is named as trie instead of tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.