-
Notifications
You must be signed in to change notification settings - Fork 12
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
Reduce the number of identical get_two_letter_dir
functions to one
#1390
Comments
This had something to do with it being needed inside "models" where it can't import from the other files. The three "commands" are going to be thrown away, basically, once it's all converted. That's why I put them there, to not import other code. It's also violating other principles because the entire file system is visible inside the models. |
To circumvent circular imports, you could do the import within a function, class or method. See Can you see whether this works on your side? |
Can we make a totally new "file system related functions" file to put it in? The problem is that it also needs to use "idgloss" but that function is full of try-except clauses. So it could be failing internally yet we don't know. The glosses where video's are being uploaded are supposed to have lemma's, dataset's, lemma translations. So this should not be failing internally. I made a separate issue a few weeks ago about the idgloss property. Because there were unexplained failings in the API I was trying to localize the code to be able to debug it. If the file system related methods can be put in a file where other functions are not imported from that would help. The "database_checks" file was made to be independent because it takes a really long time to run. I assumed it would reduce the runtime if it didn't import the function. Although it makes use of idgloss. So that doesn't really solve anything. I think the idgloss property should fail if the gloss is missing a dataset or lemma or lemma translation. (But that maks for awful code elsewhere.) The entire video upload system is using this function constantly. I merged the renaming of the backup files because it's in use and it's kind of high priority. I agree completely about the 2-char function. But it's kind of in combination with idgloss. (And then that gets worse with all the right to left and pictogram characters.) In some of the code (not reviewed) I started making the "desired relative path". In order to compare to see if something was messed up |
I removed the three commands that had included the duplicated code. |
Are they not necessary for work on the live server? |
This comment was marked as outdated.
This comment was marked as outdated.
Function to retrieve video content type of video file. Added here to avoid duplicating it in multiple files on multiple branches
@vanlummelhuizen I just tried this in the zip_interface.py file. PyCharm doe not like this:
The Nothing is importing The circular references are not just this 'get_two_letter_dir' function. |
PyCharm was flagging this as an error
I have been creating ADMIN commands to fix filenames. (See other pull requests.) This has the advantage that it is very targeted. |
Which pull requests exactly? Please always be specific so we don't have to search and/or guess what you mean. |
The 'dataset manager' available page was added later. The admin is kind of obtuse sometimes. I want to make the functionality of the two ("admin" and "manager") more similar. The "manage" page you see the result of the command immediately in the list view. (On signbank-test. It also changes the filenames in the objects when there is no video file. On the real server, it would change the filename as well. It can only inspect whether the type of video matches the extension if there is a real video though, of course.) (More buttons can be added, or a search functionality. This started out as a convenience since things were going wrong with the API video upload.) |
Circular import of
Solution (probably more like a work-around): import Patch for the solutiondiff --git a/signbank/zip_interface.py b/signbank/zip_interface.py
index 4a739866..286e8ed2 100644
--- a/signbank/zip_interface.py
+++ b/signbank/zip_interface.py
@@ -213,16 +213,8 @@ def uploaded_zip_archives(dataset):
return zip_archive
-def get_two_letter_dir(idgloss):
- foldername = idgloss[:2]
-
- if len(foldername) == 1:
- foldername += '-'
-
- return foldername
-
-
def get_gloss_filepath(video_file_path, gloss):
+ from signbank.tools import get_two_letter_dir
filename = os.path.basename(video_file_path)
filename_without_extension, _ = os.path.splitext(filename)
@@ -268,6 +260,7 @@ def get_gloss_filepath(video_file_path, gloss):
def get_gloss_filepath_glossid(video_file_path, gloss):
+ from signbank.tools import get_two_letter_dir
filename = os.path.basename(video_file_path)
filename_without_extension, _ = os.path.splitext(filename) |
In the past we had our own imposed guidelines that ll the imports should be at the top. (Rule of either you or @Woseseltops) |
#1390: Removed syntax error from very old command
@vanlummelhuizen there are some bugs in this file: signbank.dictionary.templatetags.annotation_idgloss_translation some of the functions don't work if a language is missing from a gloss. (I'm trying to browse dataset LSFB and I end up getting errors from this file. I can't actually get this dataset to be set in the signs/search form. It keeps setting it to NGT. Even though LSFB is set in the signbank banner. Somehow it's getting set back to NGT) (Because it's being set to NGT, then the language fields don't match the form fields.) |
This might have something to do with the type of selected_datasets. When it's in the templates or session variables, then it's acronyms. But some code assumes this is dataset objects. |
#1390: Removed stragglers duplicate definition get_two_letter_dir
This issue is finished. |
I noticed there are six identical
get_two_letter_dir
functions, see details below. This is a big violation of the Don't Repeat Yourself (DRY) principle in software development. We should get rid of five of them and avoid copying+pasting code or even rewriting the same thing in the future.The text was updated successfully, but these errors were encountered: