I am making the base skeleton of some Django project files so that I can put them on git and whenever I need to make a new Django site I can grab the files from git and start a blank project.
In my fabfile, I'm generating a virtualenv named virutalenv.
I just want to know that if I need to make many sites on single computer then all will have same not but they will be in the project directory.
Is that ok?
It is possible to create multiple virtualenvs with the same name; they must be in different parent directories, however.
Alternately, you could create multiple virtualenvs in the same parent directory, but with different names.
Related
Pycharm generates a .idea directory at the root of a Pycharm project. What files/directories within .idea should be ignored by git in this directory? Is this properly handled by the .gitignore file automatically generated within .idea:
cat .idea/.gitignore
# Default ignored files
/shelf/
/workspace.xml
or do I need to add something to the project root's .gitignore file?
In general, you should not check in any files to the repository which are specific to your editor or IDE unless they are also absolutely required to build the project. So if you're using PyCharm for development, all of the files it generates should be ignored.
The reason is that on most projects with multiple developers, different people will use different editors. So while you use PyCharm, I might use Vim. We don't want our .gitignore to have to learn about every user's preferred editor files, and we don't want to have to maintain multiple sets of editor files, especially since we may work on multiple projects together. If we need to configure settings, it's better to use an .editorconfig file, which works across editors, or prefer a standardized set of tools, such as a code formatter (and check in any configuration we need for that).
Instead, you should configure core.excludesfile (or use the default, $HOME/.config/git/ignore) so that it excludes your editor files. This works for all repositories that you use so each project doesn't have to learn about those settings and lets you change one place if you change editors. So in this case, that means adding the /.idea line to that file.
I have several projects open in one window, some of which are different branches of the same project. I decided to rename the directory and project for one of these branches in PyCharm using the Refactor option on the project. After doing so, the Django Unit Tests Run Configuration I had working no longer works. It is still trying to run the tests from the old directory name.
I have not found anywhere in the Run Configuration to specify the directory. The working directory, yes, but that doesn't fix it. I tried changing all instances of the old path to the new path in the workflow.xml file in the root project (which is where the Run Configuration was stored), but that didn't help, and may have messed up other configurations.
Does anyone know where to change the directory for Django tests in PyCharm?
The Django project root setting does not get updated when you use the Refactor / Rename option, so you'll have to update it yourself. Go to Preferences -> Languages & Frameworks -> Django. Select the project of interest. Just below the Enable Django Support checkbox is the Django project root: setting. Click the folder, navigate to your project root, and click Apply or OK.
(Note that while there are other questions with the same or similar answers, the questions being asked are different enough that neither Google searches nor SO searches found them, thus I chose to document the answer in a way that someone else can find the answer.)
I'm reading headfirst python and have just completed the section where I created a module for printing nested list items, I've created the code and the setup file and placed them in a file labeled "Nester" that is sitting on my desktop. The book is now asking for me to install this module onto my local copy of Python. The thing is, in the example he is using the mac terminal, and I'm on windows. I tried to google it but I'm still a novice and a lot of the explanations just go over my head. Can someone give me clear thorough guide?.
On Windows systems, third-party modules (single files containing one or more functions or classes) and third-party packages (a folder [a.k.a. directory] that contains more than one module (and sometimes other folders/directories) are usually kept in one of two places: c:\\Program Files\\Python\\Lib\\site-packages\\ and c:\\Users\\[you]\\AppData\\Roaming\\Python\\.
The location in Program Files is usually not accessible to normal users, so when PIP installs new modules/packages on Windows it places them in the user-accessible folder in the Users location indicated above. You have direct access to that, though by default the AppData folder is "hidden"--not displayed in the File Explorer list unless you set FE to show hidden items (which is a good thing to do anyway, IMHO). You can put the module you're working on in the AppData\\Roaming\\Python\\ folder.
You still need to make sure the folder you put it in is in the PATH environment variable. PATH is a string that tells Windows (and Python) where to look for needed files, in this case the module you're working on. Google "set windows path" to find how to check and set your path variable, then just go ahead and put your module in a folder that's listed in your path.
Of course, since you can add any folder/directory you want to PATH, you could put your module anywhere you wanted--including leaving it on the Desktop--as long as the location is included in PATH. You could, for instance, have a folder such as Documents\\Programming\\Python\\Lib to put your personal modules in, and use Documents\\Programming\\Python\\Source for your Python programs. You'd just need to include those in the PATH variable.
FYI: Personally, I don't like the way python is (by default) installed on Windows (because I don't have easy access to c:\\Program Files), so I installed Python in a folder off the drive root: c:\Python36. In this way, I have direct access to the \\Lib\\site-packages\\ folder.
Here is my problem, I am trying to make an application which copies data files during its setup. When i am doing pip install the setup copies a few files to a directory.
Now my question is, When inside a virtual environment, what is the behaviour that the customer expects- does he want all the created data files inside the virtual environment directory for each virtualenv or copy all the files into a common directory outside the virtual environment directory.
While running the application there will be new files that will be created and stored along these copied files. What is the ideal behaviour that is expected form a python virtualenv. common or isolated?
virtualenv is more for development, not for deployment. There are many scenarios to deploy Python app. but if you prefer virtualenv usage and you have common files, they can be anywhere IMHO, because virtualenv is not real isolation, it's only Python paths mangling/modification mechanism (not like "chroot"), so you decide where to place your common files, even /usr/share/my-app-1.0/datafiles/. Also, virtualenv is used to isolate binaries/scripts, but if data files are static, you can place them when you prefer.
In my opinion, that depends on application, which you create. Virtualenv is just way of running on same machine multiple applications with different dependencies. Data from applications is another thing.
When I would write web application, that will be single app on server, then I would use one directory.
On the other hand, when I would write GUI app, then things get different. If data is something that must be changed with every version, but end user does not touch it directly (e.g. some dictionaries, translation, etc) I would put it in dist-packages along the application package (see package data in setup.py).
On the other hand, if user can "touch" and use those files, then I would put them in users home directory. See How to find the real user home directory using python?
I was going to change the home directory name on my MacBook, but I was wondering if that will mess up any virtual environments or any other files I'm not thinking of right now in my already created Python/Django projects?
The best way to find out is to set up a test, duplicate account with all the same setup (.login, .bashrc, .bash_profile, .tcshrc, etc.) and see what happens when you try.
You may be perfectly fine, or you might have your home directory name hard coded into one of those files, in which case testing this out first might show the problem really quickly (before you mess up your real home directory).
Rename the home directory, then create a link pointing the old directory name to the new directory name.
This way, anything that points to the old name will still work.