Skip to content

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

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

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}.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Nov 27, 2020
@dhruvmanila dhruvmanila requested a review from cclauss November 27, 2020 08:52
@dhruvmanila
Copy link
Member Author

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

@cclauss
Copy link
Member

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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

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

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Nov 27, 2020
@cclauss cclauss merged commit c5fb0a9 into TheAlgorithms:master Nov 27, 2020
@cclauss
Copy link
Member

cclauss commented Nov 27, 2020

Nice work. Thanks for doing this.

@dhruvmanila dhruvmanila deleted the patch-rootdir branch November 27, 2020 15:43
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
peRFectBeliever pushed 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
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 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
Development

Successfully merging this pull request may close these issues.

Let's lose the images and greedy_method directories
2 participants