Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-flask-python : Is it safe to remove pycache and flask session folders

I had implemented my project along with daily commits to Github, which is a website implemented using Flask and Python, while daily commits I used to git add --a, thus it has added all folders like __pycache__ and flask_session. I think it is safe to delete those from my Github, Is it so? If not why?

like image 451
R. Gurung Avatar asked Jun 30 '18 06:06

R. Gurung


People also ask

Can I delete __ Pycache __ folder?

Explains: First finds all __pycache__ folders in current directory. Execute rm -r {} + to delete each folder at step above ( {} signify for placeholder and + to end the command)

How do you destroy a session in flask?

There is no way to clear session or anything. One must simply change the app. config["SECRET_KEY"] and the contents in session dictionary will get erased.


Video Answer


2 Answers

If you look at gitignore.io/python, you will find in the generated .gitignore file

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/

However, you won't find flask_session, not even in flask-common/.gitignore.

The Flask documentation mentions:

SESSION_FILE_DIR The directory where session files are stored.
Default to use flask_session directory under current working directory.

If that is something private to the user and the flask execution, then add to your .gitignore:

/*_session/

But considering a Flask session stores secrets, the best practice would be to configure Flask to store its session outside the Git repository: that way, no risk to add by mistake anything, .gitignore or not.

like image 115
VonC Avatar answered Oct 13 '22 05:10

VonC


Both these folders contain temporary objects that are created in runtime, and there's no point in committing them to git. I'd remove those folders from your repository and then add them to .gitignore to prevent them from being re-added there by mistake.

like image 3
Mureinik Avatar answered Oct 13 '22 04:10

Mureinik