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

sasview.exe cannot create the custom_config.py file #1911

Closed
butlerpd opened this issue Sep 6, 2021 · 18 comments
Closed

sasview.exe cannot create the custom_config.py file #1911

butlerpd opened this issue Sep 6, 2021 · 18 comments
Labels
Blocker Prevents a different issue from being resolved Defect Bug or undesirable behaviour Testing Testing and quality
Milestone

Comments

@butlerpd
Copy link
Member

butlerpd commented Sep 6, 2021

As mentioned in @1672 and other places, if the sasview.exe program tries to copy the default_config.py to custom_config.py in the users .sasview\config folder it fails. Fortunately this bit of code should in principle never be needed as the custom_config.py file is normally installed by the installer on a clean install (barring some unusual and as yet undocumented situation) and from there on it should always be there with whatever user modifications get made. However, in the case that it accidentally gets deleted or moved, the following function src/sas/_config.py is activated:

def setup_custom_config(app_dir, user_dir):
    path = make_custom_config_path(user_dir)
    if not os.path.isfile(path):
        try:
            # if the custom config file does not exist, copy the default from
            # the app dir
            shutil.copyfile(os.path.join(app_dir, "custom_config.py"), path)
        except Exception:
            logger.error("Could not copy default custom config.")

I have not yet seen any case where this ever works. In all cases I have been able to ascertain this function fails producing the error in logger.error and the program then stops with a message Failed to execute script sasview. Since it is so rare that this would actually be called, the easiest way to test it is to manually delete the .sasview\config\custom_config.py file and then try running the program again.

It is unlikely to be a permission problem since the program can write the the .sasview directory (for example when saving a custom model). Further, even when changing the HOME directory variable so that the program tries to write to a different directory (e.g. c:\temp), it will still fail.

In order to keep tickets from getting convoluted with many issues, I recommend we only add comments here related to this copying and not to any other failure to run sasview issues. Those more general issues can be added to #1672 which remains open and now contains quite a few reports.

@butlerpd butlerpd added this to the SasView 5.1.0 milestone Sep 11, 2021
@butlerpd butlerpd added Defect Bug or undesirable behaviour Minor Small job SasView Bug Fixing Testing Testing and quality labels Sep 11, 2021
@butlerpd
Copy link
Member Author

butlerpd commented Feb 1, 2022

Verified using 5.0.5RC2. Removing the custom_config.py causes the SasView program to fail to start with the usual entry in the log file: Could not copy default custom config. However, the error that pops on my windows 10 screen is not the Failed to execute a script sasview error. Instead A big box with a white x on a red background label: Unhandled exception in script pops up. It gives a full error and then a traceback in a scrollable window. Unfortunately ip points to the line after the actual copy failure.

@butlerpd
Copy link
Member Author

butlerpd commented Feb 1, 2022

Looking at comments in #1672 by @smk78 regarding some stackoverflow comments and looking again at the code I strongly suspect that the problem is that the built-in custom_config.py which needs to be copied is not in the directory that the code aboves is looking for. there is a find appdir function which expects 4 different places depending on OS or "in-place" vs "frozen." I suspect at some point a reorg of files was done without realizing that the custom_config setup would get lost?

@wpotrzebowski
Copy link
Contributor

User reported issues with custom_config on Mac OSX. The workarround was to copy https://github.com/SasView/sasview/blob/main/src/sas/sasview/custom_config.py to ~/.sasview folder.

@smk78
Copy link
Contributor

smk78 commented Mar 15, 2022

User SarahR installed 5.0.4 on a clean W10 laptop. Trying to run the program resulted in the dreaded 'cannot execute script sasview'.

On my advice, uninstalled 5.0.4 and deleted %USERPROFILE%\.sasview, then installed 5.0.5rc2. Running this threw:
PHOTO-2022-03-15-15-51-51

Got Sarah to copy custom_config.py from the installation folder to %USERPROFILE%\.sasview\config and 5.0.5rc2 then ran happily.

@butlerpd
Copy link
Member Author

Was that a permission problem as well?

@smk78
Copy link
Contributor

smk78 commented Mar 16, 2022

5.0.5rc2 was installed as 'All Users' from the Users normal account (not a local admin account).

What is odd is that we had deleted the \config folder and the installer had recreated it, but having done so it was then unable to copy custom_config.py into the folder it had created!

@rozyczko
Copy link
Member

Similar situation reported by @celinedurniak on MacOS, with installed 5.0.4 (not developer build).
Maybe this isn't OS specific then?

@butlerpd
Copy link
Member Author

agreed @rozyczko . This particular issue, failing on the line of code at the top, should almost never be invoked unless one physically removes the custom_config.py file. It is clear that it can also happen on Windows in other ways (likely it gets deleted in a strange way we have not yet found?) otherwise we should never see the error since the installer copies the file there (using a different path in the code I think). It is thus completely plausible that whatever weird path removes the file happens less frequently on the mac?

Can we test on the mac like I've done on the PC that removing the custom_config.py file (I usually remove the directory) reproducibly fails on the macs? As stated above, from @smk78 snooping I am now suspecting a path problem? What do you think?

@krzywon
Copy link
Contributor

krzywon commented Jul 13, 2022

I ran into this issue last week while running v5.0.5 on Windows. The custom_config.py file was gone, but the compiled file (.pyc) was still available. I was able to get everything back up and running using the guide on the sasview FAQ site. I installed SasView for only myself.

I did some debugging this morning and was able to reproduce the deletion of the custom config file by running python setup.py build. A similar process is likely happening during the installation of new versions of sasview. Running the SasView v5.0.5 executable with no custom config file, I get the same error as others. run.py was able to generate a new config file and I can again start the stand-alone app.

I'm going to add more debugging messages to the exception handling in _config.py and generate an installer. Hopefully, this will give us more info than 'Could not copy default custom config.'

@krzywon
Copy link
Contributor

krzywon commented Jul 13, 2022

Using the installer found in https://github.com/SasView/sasview/releases/tag/untagged-aea52815bcc6a9c594ab, I was able to reproduce the issue and the traceback suggests the SasView app is looking for the custom_config.py file in the base C: directory, not the directory SasView is stored in. This looks like a path issue related to finding the app directory within _config.py lines 38-50. The find_app_dir() method assumes the installed code is held within library.zip, but that file no longer exists within the installed file structure. I'll try a few things with the path finding and see what I can figure out.

ERROR : sas._config (_config.py:95) :: Traceback (most recent call last):
File "sas_config.py", line 93, in setup_custom_config
File "shutil.py", line 264, in copyfile
FileNotFoundError: [Errno 2] No such file or directory: 'C:\custom_config.py'

@krzywon
Copy link
Contributor

krzywon commented Jul 13, 2022

The Windows installer at https://github.com/SasView/sasview/releases/tag/untagged-df5a9ed83c435b1c5119, built from the 1911-cannot-create-custom-config branch is now able to copy the custom_config file into the ~/.sasview/config/ directory on start-up and on install. Someone should check the MacOS installer to be sure that works as well.

The crux of the issue - The SasView dependencies are no longer housed in a library.zip file on the same path as the executable, so the config file is one directory level different than it used to be. find_app_dir() can't find the file to copy it into the user directory.

I did not submit this as a PR because we should find a better way to future-proof this for when our deployed file structure changes again in the future. We need some way to find the path of the executable, rather than the script currently running.

@celinedurniak
Copy link
Contributor

@krzywon I tested the dmg package on Mac v 10.15.7. And I still have the issue that custom_config.py is not in the config folder.

@krzywon
Copy link
Contributor

krzywon commented Jul 14, 2022

@celinedurniak Thanks for testing. Can you check your sasview.log file for an error traceback? This will help with debugging.

@celinedurniak
Copy link
Contributor

14:12:39 - ERROR: Traceback (most recent call last):
File "sas/_config.py", line 93, in setup_custom_config
File "shutil.py", line 264, in copyfile
FileNotFoundError: [Errno 2] No such file or directory: '/Applications/SasView5.app/custom_config.py'

14:12:39 - ERROR: Could not copy default custom config.
Traceback (most recent call last):
File "sasview.py", line 15, in
File "sas/qtgui/MainWindow/MainWindow.py", line 74, in run_sasview
File "sas/logger_config.py", line 43, in config_development
self._disable_debug_from_config()
File "sas/logger_config.py", line 50, in _disable_debug_from_config
custom_config = get_custom_config()
File "sas/init.py", line 44, in get_custom_config
raise
File "sas/_config.py", line 100, in setup_custom_config
FileNotFoundError: [Errno 2] No such file or directory: '/Users/celinedurniak/.sasview/config/custom_config.py'
[1771] Failed to execute script 'sasview' due to unhandled exception: [Errno 2] No such file or directory: '/Users/celinedurniak/.sasview/config/custom_config.py'
[1771] Traceback:
Traceback (most recent call last):
File "sasview.py", line 15, in
File "sas/qtgui/MainWindow/MainWindow.py", line 74, in run_sasview
File "sas/logger_config.py", line 43, in config_development
File "sas/logger_config.py", line 50, in _disable_debug_from_config
File "sas/init.py", line 44, in get_custom_config
File "sas/_config.py", line 100, in setup_custom_config
FileNotFoundError: [Errno 2] No such file or directory: '/Users/celinedurniak/.sasview/config/custom_config.py'

@lucas-wilkins
Copy link
Contributor

This should be fixed by #2168

@butlerpd
Copy link
Member Author

Hopefully this is indeed fixed by #2168. This is starting to bite us a lot a lot recently so to make sure we don't forget before the next release, I'm raising this to blocker for now. Note the increased incidence of this issue may be related to #2056 where the install can delete the existing custom_config (thereby generating this error on startup). That too is supposedly fixed by #2168 but needs to be checked.

@butlerpd butlerpd added Blocker Prevents a different issue from being resolved and removed Minor Small job labels Oct 10, 2022
@lucas-wilkins
Copy link
Contributor

That too is supposedly fixed by #2168 but needs to be checked.

There won't be a custom_config.py file, so it will definitely not be a problem in that sense. There shouldn't be any issue with collisions between versions either.

@lucas-wilkins
Copy link
Contributor

bye bye custom_config.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Prevents a different issue from being resolved Defect Bug or undesirable behaviour Testing Testing and quality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants