-
Notifications
You must be signed in to change notification settings - Fork 551
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
Don't autocreate user dirs immediately when importing classes.info #4553
Conversation
94f7380
to
2b75b88
Compare
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.
LGTM
# Migrate USER_DEFAULT_PROJECT from former name | ||
if all([ | ||
os.path.exists(LEGACY_DEFAULT_PROJECT), | ||
not os.path.exists(USER_DEFAULT_PROJECT), |
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.
neat way to make a very readable "and not"
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.
Standard disclaimer about any()
and all()
not supporting short-circuit evaluation applies (all of the conditions in the list will always be evaluated, unlike in a multi-clause if .. and/or ...
condition), but for simple, one-time tests like this one the efficiency loss is undetectable.
Merge conflicts have been detected on this PR, please resolve. |
Merging this, as it should restore our Launchpad builds to working order. |
- The directory-creation code is moved to info.setup_userdirs(), called by launch.py before creating the OpenShotApp instance - app.mode is now set by keyword-only argument, and is no longer passed to MainWindow() (as the GUI is never started in unit test mode). - Removed all references to window.mode from the GUI code
- The directory-creation code is moved to info.setup_userdirs(), called by launch.py before creating the OpenShotApp instance - app.mode is now set by keyword-only argument, and is no longer passed to MainWindow() (as the GUI is never started in unit test mode). - Removed all references to window.mode from the GUI code Co-authored-by: Jackson <jackson@openshot.org>
If the info.USER_PATH directory does not exist, load the settings defaults, but don't try to merge the user's settings or to write back the updated settings file immediately after loading.
- project.save(make_paths_relative=False, move_temp_files=False) both replaced with backup_only=True, which does the same plus adds additional protections against unwanted actions - Backup-only save files will now retain absolute paths, as was apparently intended (make_paths_relative=False was being ignored)
- clear_all_thumbnails was an unmaintainable name for a function that not only deleted three different types of working files, but ALSO deleted the (previous) project data backup! - Now uses info.get_default_path() to avoid hard-coding directory names under `info.USER_PATH`
af46db6
to
4f0b596
Compare
(Just waitin' on the CI, to merge.) |
Success! And now there's an |
|
Our PPA builds for 2.6.1 are currently broken in Launchpad, because I turned on documentation building which immediately crashed. The problem is that the Sphinx config does an import of
classes.info
to get the OpenShot version, and as soon as it's importedclasses.info
attempts to create all of the preferences directories in$HOME/.openshot_qt
, a no-no during package builds.I assume this is also why the unit tests are disabled, in the launchpad configs.
All of this makes the point, though, that we SHOULDN'T BE creating a ton of directories simply because a class was imported — especially not one we import everywhere, from
setup.py
todoc/conf.py
tofreeze.py
tosrc/tests/query_tests.py
. That's an unacceptable side-effect for a class that's intended as merely a metadata dumping ground.So, these commits move the creation of directories into a function within
classes.info
,setup_userdirs()
, whichlaunch.py
calls immediately prior to setting up theOpenShotApp
instance. All of the other scripts that import the class won't call it, so they don't trigger the creation of a bunch of unnecessary settings dirs as a side-effect.To make this work, I had to rearrange a bunch of things in
classes.settings
,classes.logger
,classes.project
, andclasses.app
so that they could handle the user preferences dir being entirely absent, since the unit tests need to be able to importclasses.app
and create anOpenShotApp
instance without ever callingclasses.info.setup_userdirs()
.I also removed the load of
classes.logger
fromclasses.sentry
— if that's going to be loaded at the very start of the launch script, it can't trigger the initialization of the logging class. It's too early. So it just does aprint()
of the info instead, same as howlaunch.py
handles its own output.And I removed all references to the
mode
from the GUI code, as the unit tests haven't started the GUI for some time now.window.mode
will never be"unittest"
under any circumstances, anymore. (app.mode
is still used by the unit tests to adjust certain startup functionality, so it's still there. Also it's now set as an instance variable, so if any of the code ever does need to check the mode, it can testif get_app().mode == "unittest"
.)With these changes, it's now possible to do all of these things:
...WITHOUT triggering the creation of
$HOME/.openshot_qt/
and its many, many subdirs.Unfortunately I wasn't able to arrange things so that OpenShot itself could run entirely without a user dir as a 0-footprint application. That's something I see value in (temporary files would just be written to system default tempdirs, is the idea) since it would allow use of OpenShot in all sorts of scenarios where writing to
$HOME/.openshot_qt
is not feasible, permitted, or desired. But, it's a bigger undertaking that shouldn't hold up these changes.Update
I added a few more commits:
classes.info
now captures all of the initial defaults for user paths. (Any variable with a name that ends with_PATH
, and a value that matchesinfo.USER_PATH
at the start is placed into theinfo._path_defaults
dict.)info.setup_userdirs()
(replacing the hardcoded list of variables representing paths to be created)info
paths, by callinginfo.reset_paths()
.info.get_default_path("NAME_OF_VAR")
.info
paths now does so by simply callinginfo.reset_paths()
.os.path.join(info.USER_PATH, "thumbnails")
to work around a modifiedinfo.THUMBNAIL_PATH
now instead just callsinfo.get_default_path("THUMBNAIL_PATH")
.I re-worked the autosave code a bit. The
project.save()
method, which used to have two parametersmake_paths_relative
andmove_temp_files
, now has only one:backup_only
. Settingbackup_only=True
implies both of the previous parametersFalse
, and also disables some additional logic that's undesirable when making a backup. (Like the storing ofcurrent_filepath
and the resetting ofhas_unsaved_changes
, both of which were previously being done inproject.save()
, then immediately un-done by the autosave code that called it. Now it's never done in the first place, becausebackup_only=True
is passed in with the call.)I renamed
MainWindow.clear_all_thumbnails()
toMainWindow.clear_temporary_files()
, because I just couldn't abide the previous name for a function that not only cleared three different types of working file, but also deleted the (previous) backup file! A name that bad was just asking for someone to make a wrong assumption, possibly with consequences.