The Wayback Machine - https://web.archive.org/web/20210831161953/https://github.com/TheAlgorithms/Python/pull/3972
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

fixes: #3956 Cleaned up knapsack and images directory #3972

Merged
merged 1 commit into from Nov 27, 2020

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Nov 27, 2020

Fixes: #3956

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Nov 27, 2020

There's this README file as well which probably either needs updating or should we just remove it?

@cclauss
Copy link
Member

@cclauss cclauss commented Nov 27, 2020

Perhaps we could get the original poster @tbsschroeder to update the README to reflect that all implementations of the knapsack problem are going to be put in one directory.

Let's do this. Move the README along with the code and we will see if someone is willing to update it appropriately. If it is not updated by yearend, we can whack the README.

@dhruvmanila
Copy link
Member Author

@dhruvmanila dhruvmanila commented Nov 27, 2020

Well, then this is good to go. I haven't touched the README so it is present in the knapsack directory.

@@ -1,6 +1,6 @@
import unittest

from . import greedy_knapsack as kp
from knapsack import greedy_knapsack as kp

This comment has been minimized.

@cclauss

cclauss Nov 27, 2020
Member

Is this a vital change? There are two ways to go. Hardcode the name of the parent directory or use relative imports. Each has its pros and cons. Relative imports are better for easy refactoring and absolute imports are better for libraries and projects that need stability.

This comment has been minimized.

@dhruvmanila

dhruvmanila Nov 27, 2020
Author Member

Relative import would be like so: from .. import greedy_knapsack as kp as I created a tests directory for both test files. Here's the tree:

knapsack/
├── README.md
├── __init__.py
├── greedy_knapsack.py
├── knapsack.py
└── tests
    ├── __init__.py
    ├── test_greedy_knapsack.py
    └── test_knapsack.py

This comment has been minimized.

@dhruvmanila

dhruvmanila Nov 27, 2020
Author Member

I suppose for our use case relative imports should be de facto as we don't know from where the script is going to be called by the user.

@cclauss cclauss merged commit c5fb0a9 into TheAlgorithms:master Nov 27, 2020
2 checks passed
2 checks passed
@github-actions
build
Details
@github-actions
pre-commit
Details
@cclauss
Copy link
Member

@cclauss cclauss commented Nov 27, 2020

Nice work. Thanks for doing this.

@dhruvmanila dhruvmanila deleted the dhruvmanila:patch-rootdir branch Nov 27, 2020
s-okubanjo added a commit to s-okubanjo/Python that referenced this pull request Nov 29, 2020
stokhos added a commit to stokhos/Python that referenced this pull request Jan 3, 2021
peRFectBeliever added a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants