Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Avoid overwrite when regenerating project#22

Merged
varun646 merged 17 commits intomainfrom
avoid_overwrite_with_manifest
Apr 26, 2024
Merged

Avoid overwrite when regenerating project#22
varun646 merged 17 commits intomainfrom
avoid_overwrite_with_manifest

Conversation

@varun646
Copy link
Copy Markdown
Contributor

Changes

Currently, any changes made locally are overwritten when regenerating a project to that directory. This is addressed by creating a temporary directory, generating to that directory, copying over content if the user has made no changes to the files which we will overwrite, and finally removing the temporary dir.

To keep track of whether a user has made changes, we store a file hash for each file at the point that the file is originally generated (or if it is removed from the output directory then generated again, the stored hash will correspond to the status of the file at regeneration). These values are stored in <output_dir>/.manifest.yml so they can be checked into GitHub and can be accessed if a user changes devices.

varun646 added 6 commits April 9, 2024 14:06
Restructured code so post-gen hook writes values for placeholders to yaml file. This allows for values such as "current_dir" to be replaced by final output directory instead of tmp directory.
This version adequately deals with changes in template files between cookiecutter generations

TODO: need to find better way to identify path to store any prompt population yaml files and manifest file. Current implementation makes assumptions about the CWD which may be unsafe

Potential bug if the original generation is done to a directory which is non-empty and contains files with the same name as those being generated
- Manifest files now saved in base of output directory

- Prompt population yaml saved in temporary directory so it can be accessed and removed after displaying final messages

- Fixed type annotations/removed debug comments
address issue stemming from files existing in output directory before generation
Address workflow failures stemming from not being able to locate coverage info

See here: https://github.com/varun646/PythonProjectBootstrapperTest/actions/runs/8691233105/job/23833091301
- Clearer function name
- Ensure some dirs exist
@varun646 varun646 requested a review from davidbrownell April 15, 2024 16:29
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/EntryPoint.py Outdated
Comment thread src/PythonProjectBootstrapper/package/hooks/post_gen_project.py Outdated
###Changes

- Moved functions to separate file
- Added tests
- Removed old tests that were failing (likely) due to changes in working directory
- Fixed pylint issues

TODO: check that the prompt file is being created at the ideal place

TODO: look into whether another test needs to be added for generating to a directory where a file name already exists but not in the manifest
@varun646 varun646 marked this pull request as draft April 18, 2024 20:54
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread tests/ProjectGenerationUtils_UnitTest.py Outdated
Comment thread tests/ProjectGenerationUtils_UnitTest.py Outdated
Comment thread tests/ProjectGenerationUtils_UnitTest.py Outdated
Comment thread tests/ProjectGenerationUtils_UnitTest.py
Comment thread tests/EntryPoint_UnitTest.py Outdated
varun646 and others added 8 commits April 19, 2024 15:33
- Remove `hashlib.file_digest()` function which is no longer used

Should address workflow failures on mac
change copy function so it no longer copies metadata. It seems like errors were coming up from trying to get file data so this could be the cause
- Manifest keys are now posix strings (path sep == '/') for support on Windows (where path sep == '\')
- No longer running cross-os tests (e.g. no longer running "MacOS" on "Linux" machines). We exercise those tests in the CI process.
- Make functions public
- Nit comments
- Remove unnecessary casting
@varun646 varun646 marked this pull request as ready for review April 24, 2024 19:26
Comment thread pyproject.toml Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread src/PythonProjectBootstrapper/ProjectGenerationUtils.py Outdated
Comment thread tests/ProjectGenerationUtils_UnitTest.py Outdated
@varun646 varun646 force-pushed the avoid_overwrite_with_manifest branch from 0d8b69c to 99f7b39 Compare April 25, 2024 11:30
Address comments from commit

99f7b39
@varun646 varun646 requested a review from davidbrownell April 26, 2024 18:50
Copy link
Copy Markdown
Contributor

@davidbrownell davidbrownell left a comment

Choose a reason for hiding this comment

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

Looks good - congrats!

@varun646 varun646 merged commit 489dc2e into main Apr 26, 2024
@varun646 varun646 deleted the avoid_overwrite_with_manifest branch April 26, 2024 18:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants