Skip to content

3537: End plugin model necromancy#3538

Merged
krzywon merged 3 commits into
3522-example-data-branchfrom
3537-plugin-model-moves
Jul 30, 2025
Merged

3537: End plugin model necromancy#3538
krzywon merged 3 commits into
3522-example-data-branchfrom
3537-plugin-model-moves

Conversation

@krzywon
Copy link
Copy Markdown
Contributor

@krzywon krzywon commented Jul 24, 2025

Description

This ensures, once files are copied from ~/.sasview/ to the new locations, the original file is removed from the system. The most important aspect of this is to ensure plugin models deleted through the plugin model manager do not reappear later.

This branch was based off 3522-example-data-branch, so I currently have this as a chained PR.

Fixes #3537

How Has This Been Tested?

Locally, all plugin models were wiped away in my ~/.sasview/plugin_models/ directory.

Review Checklist:

Documentation (check at least one)

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation (link?)

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing (untick if necessary)

  • The introduced changes comply with SasView license (BSD 3-Clause)

Comment thread src/sas/system/user.py Outdated
# Once the file is copied, the old file should be removed from the system to ensure.
# I did not change the shutil to a move, to ensure files that exist in both locations aren't overlooked.
if old_path.exists():
os.remove(old_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are some assumptions here:
The old file is correctly copied, and it is just a single file (keep in mind that os.remove() won't remove directories or links)
The os.remove doesn't throw - a dangerous assumption, as the exception will then percolate with unexpected results

Maybe be a bit more defensive?

for old_path, new_path in location_map.items():
    if old_path.exists() and not new_path.exists():
        shutil.copy2(old_path, new_path)
        # Ensure the file was copied successfully before removing the original
        if old_path.exists():
            try:
                os.remove(old_path)
            except Exception as e:
                logging.error(f"Failed to remove {old_path}: {e}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I purposely left the second if statement outside the first. If a user had a model from v5 that got copied to the new location in v6, it now exists in both locations, but should only be in the new locale. The check inside misses the case I am trying to correct for. My new proposed scheme to cover the use cases this is meant to capture:

for old_path, new_path in location_map.items():
         # Move the file to the new location instead of copying (fixes future issues)
        if old_path.exists() and not new_path.exists():
            shutil.move(old_path, new_path)
        # Files copied to the new location in previous versions may still be hanging around. Delete them.
        if old_path.exists() and new_path.exists():
             try:
                os.remove(old_path)
            except Exception as e:
                logging.error(f"Failed to remove {old_path}: {e}")

Copy link
Copy Markdown
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

I'm approving this, but please consider the comments, especially error handling.

…case where both files exist is handles properly
@krzywon
Copy link
Copy Markdown
Contributor Author

krzywon commented Jul 30, 2025

@rozyczko, let me know if the changes I made address your concerns, or merge if you think this is ready

@rozyczko
Copy link
Copy Markdown
Member

looks good!

@krzywon krzywon merged commit a4afc39 into 3522-example-data-branch Jul 30, 2025
32 checks passed
@krzywon krzywon deleted the 3537-plugin-model-moves branch July 30, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants