-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactoring the refactoring #10
Merged
joelgrondman
merged 8 commits into
towards_refactoring_the_api
from
refactoring_the_refactoring
May 23, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38b68af
moved file_handling to it's own module
mircealungu d441adc
created portability module
mircealungu 86a03b7
moving file handling to it's own module: part two
mircealungu 7a54b1b
finalized: moving the scripts to their own module
mircealungu e24bf24
updated path
mircealungu 9f0da16
an init in the scripts. just in case.
mircealungu 3040a3b
moved also loading_from_hermit to file_handling
mircealungu bc2a993
some renames, reorganizing
joelgrondman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from wordstats.config import DATA_FOLDER_COGNATES, WHITELIST, BLACKLIST, RULES, CANDIDATES | ||
import os | ||
|
||
|
||
def path_of_cognate_languages(primary, secondary): | ||
package_directory = os.path.dirname(os.path.abspath(__file__)) + os.sep + ".." | ||
file_path = package_directory + os.sep + "{0}{1}{2}{3}".format(DATA_FOLDER_COGNATES, os.sep, primary, secondary) | ||
return file_path | ||
|
||
|
||
def path_of_cognate_candidates(primary, secondary, method_name): | ||
return _path_to_cognate_file(primary, secondary, CANDIDATES, method_name) | ||
|
||
|
||
def path_of_cognate_blacklist(primary, secondary, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, | ||
BLACKLIST if len(author) == 0 else (BLACKLIST + "_" + author)) | ||
|
||
|
||
def path_of_cognate_whitelist(primary, secondary, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, | ||
WHITELIST if len(author) == 0 else (WHITELIST + "_" + author)) | ||
|
||
|
||
def path_of_cognate_rules(primary, secondary, method_name, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, RULES if len(author) == 0 else (RULES + "_" + author) | ||
, method_name) | ||
|
||
|
||
def _path_to_cognate_file(primary, secondary, file_name, method_name=""): | ||
file_path = path_of_cognate_languages(primary, secondary) + os.sep | ||
if method_name is not "": | ||
file_path += method_name + os.sep | ||
file_path += file_name + ".txt" | ||
|
||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
|
||
return file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import codecs | ||
|
||
|
||
# useful methods for handling files | ||
|
||
def load_from_path(path): | ||
try: | ||
with codecs.open(path, encoding="utf8") as file: | ||
content = file.read() | ||
|
||
except FileNotFoundError: | ||
print(path + " not found, creating empty file.") | ||
codecs.open(path, encoding="utf8", mode="w") | ||
content = load_from_path(path) | ||
|
||
return content | ||
|
||
|
||
def save_to_file(path, content): | ||
with codecs.open(path, encoding="utf8", mode="w") as words_file: | ||
words_file.write(content) | ||
|
||
|
||
def append_to_file(path, content): | ||
with codecs.open(path, encoding="utf8", mode="a") as words_file: | ||
words_file.writelines(content + "\n") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelgrondman - note that many of these removed imports are done automatically by Python when refactoring code since they are not used in the corresponding file.
For SQLAlchemy I have had in the past code which requires a class to be loaded, even if it's not used straight away in that file. I hope this is not the case anywhere here!