Adding files to gitignore in Visual Studio Code - python

In Visual Studio Code, with git extensions installed, how do you add files or complete folders to the .gitignore file so the files do not show up in untracked changes. Specifically, using Python projects, how do you add the pycache folder and its contents to the .gitignore. I have tried right-clicking in the folder in explorer panel but the pop-menu has no git ignore menu option. Thanks in advance.
Edit: I know how to do it from the command line. Yes, just edit the .gitignore file. I was just asking how it can be done from within VS Code IDE using the git extension for VS Code.

So after further investigation, it is possible to add files from the pycache folder to the .gitignore file from within VS Code by using the list of untracked changed files in the 'source control' panel. You right-click a file and select add to .gitignore from the pop-up menu. You can't add folders but just the individual files.

This extension lets you add folders to .gitignore.

Related

Is there a way in VSCode to automatically switch Python interpreter depending on the directory?

I'm using a monorepo with multiple packages in separate directories. Poetry is in charge of package management including creating the virtual environment.
I wish VSCode would use the right Python interpreter for each package individually. Is that possible? My workaround is to open a separate window with the directory containing a package, so all of its files would use the right interpreter.
You can open multiple folders in vscode and select the interpreter for each folder individually.
Select Add Folder to Workspace in the menu. As a simple example I have added three folders
Then click on the python interpreter version in the lower right corner (or Ctrl+Shift+P --> Python:Select Interpreter)
Choose a folder, here I choose folder1
Now select interpreter for folder1 folder
The same operation continues to select interpreters for folder2 and folder3.
Of course this is just the basics, you can also create virtual environments for each folder and then choose the interpreter for the virtual environment for each folder.
For example, I created a virtual environment .venv2 under the folder2, the same step 2 and 3, and then I selected the interpreter under the virtual environment .venv2.
There is also a way to specify the default interpreter path in the settings.json, but after setting it also requires step 2 and 3 and then select it in the selection panel.
When you modify the folder settings, the .vscode folder and the settings.json file will be automatically generated under the folder. The contents of the settings.json file are the settings you just modified
And this step is reversible. You can manually create the .vscode folder and add the settings.json file in it. And enter the corresponding settings in the settings.json file.

After Windows reset lost my user folder where my Pycharm Projects folder was and can't recover files

I just did a reset on Windows and deleted all the files, but did not wipe my drive clean. When i realized that I didn't put my Pycharm Projects folder into onedrive I started try to recover this folder with all my code in it. I found the user folder that held my Pycharm projects folder in windows.old and when i went into the project folder it had all the logs from messing around with the code and the project foler .iml file, but did not have any of the actual .py files from my coding projects. Is there anyway to recover these files. I tried to look everywhere and have done everything I can to recover these files but nothing is doing the trick
It looks like your Windows just updated to a new verion or build, that's why moved your project to a folder called windows.old, you need to copy the files that you need outside, then reinstall pycharm. It's recommended to reinstall programs.
For new projects, remember to use git repositories, www.github.com or www.gitlab.com can host private projects to avoid those problems

Where should I put the python files called by my application? [duplicate]

I am working on a C# application. Inside this program it looks through a directory and uses files in the same directory containing the exe files in the debug folder. I added a setup project, for deployment, to the solution for the application. I tend to be naive and figured I could just drop the files and folders into the installation folder after I install it on another computer. I know there is a way to add these files and folders to the projects and set it up to have the installer install these files at the time of installation.
I assume you are working with Visual Studio 2010, and using Visual Studio Installer Setup Project to create an MSI output file.
Right click on the Setup project, select View menu, and select File System.
In there you are able to define files and folders to be installed.

How to upload only source files to github?

I have project written in python which i would like to upload to my github repo. In my source directory in laptop, there are other compiled python scripts (.pyc) residing as well which i would like to avoid uploading to github. The documentation avaiable on the internet shows uploading entire source directory to github repo.
Is there a way to avoid uploading certain file type, specifically *.pyc, to github repo?
Make a .gitignore file and add *.pyc to it
I recommend you put this standard .gitignore for python by github It has *.py[cod] to get rid of .pyc,.pyo and .pyd files
This is the intent of the .gitignore file
For your specific problem, you should add *.pyc to this file.
When you upload you files to github only what is in your git repo gets uploaded. pyc files should not have been added to your git repo anyways. If you did, remove them before pushing your repository.
You can use the .gitignore files to not let pyc files show up in your git status view.

Pydev in Eclipse default working directory

What is the default working directory for my project? I have several projects under my workspace, and a couple of run configurations. I use os.getcwd() and the directory goes to other project's folder, after deleting all run configurations, the directory goes to eclipse's install folder. How to make the default working directory goes to my project folder or the \src folder?
EDIT:
In my PYTHONPATH that will be used in the run:
C:\Program Files\eclipse\dropins\plugins\org.python.pydev_1.5.4.2010011921\PySrc\pydev_sitecustomize;
C:\(MyProjectDirecotry)\\src;
C:\Python26;
C:\Python26\DLLs;
C:\Python26\lib;
C:\Python26\lib\lib-tk;
C:\Python26\lib\plat-win;
C:\Python26\lib\site-packages
maybe there's C:\Program Files\eclipse\dropins\plugins\org.python.pydev_1.5.4.2010011921\PySrc\pydev_sitecustomize; in the first line causing the issue. Why is this happened? How to revert it back to default? Thanks.
Open Run Dialog...-> Select your run configuration->Arguments Tab->Working directory:
mine is set to ${workspace_loc}:test/src/ for a project name test i created in my workspace

Categories