PyDev for App Engine - re-import External Libs - python

I have a project which I created 2 years ago. I need to work on it again, and didn't have it in my Eclipse Workspace so I downloaded it from git and did an import existing projects into workspace. All worked well, except I notice the External Libraries do not contain all the new libraries added to the SDK since I created the project (and there's loads now compared to then). It would be useful if I could select the GAE root dir and let Eclipse automatically pull in all the libs for me, as it does when you create a new project. I don't see a way of doing this other than adding them 1 by 1. Does anyone have any tips?!

If you create a new project, you get all the new libs. Move your existing (imported) sources to this new project.

Related

Managing a Python Monorepo in PyCharm

I'm experimenting with monorepos & python. The idea is having multiple projects in the same repo, each project should have its own virtualenv.
I find it kinda cumbersome managing all of that in PyCharm.
PyCharm supports managing multiple projects in with different venvs: https://www.jetbrains.com/help/pycharm/opening-multiple-projects.html?_ga=2.5681206.409054178.1602169802-543218074.1500382704
But it's not very friendly if you have many projects, I will have to "open" and "attach" each and every one of them.
Let's see an example in this repo:
Under the project directory I have 2 projects:
The 2 projects directories are marked in bold (just like the root one), basically meaning they are "PyCharm projects".
Under the preferences window, you can see all the projects:
But there's no option of adding new projects there.
If I had a 3rd project, I would have to open it and attach it to the current window.
Am I missing something? Is there an easier way of marking a sub-directory as a project?
Imagine cloning a repository with 10 projects or more, configuring all the settings on PyCharm is going to be very frustrating.
You can share some of the files into the .idea folder via your repository. This folder and particularly the .idea/modules.xml file contains all the configuration details for your project(s).
Therefore, you only have to do the setup once (or as projects are added) then the configuration will be replicated.

Most efficient solution for sharing code between two django projects

I have to find a solution for sharing code between two big Django projects. The main things to share are models and serializers and template tags. I've came up with 3 different solutions and I need you to find pro and cons to be able to make a choice.
I'll list you the solutions I found:
git submodules
Create a repository where to store my *.py files and include them as a django app such as 'common_deps'
Even if this is the purpose of git submodules there are a bit hard to use and its easy to fall into traps.
python package
Create a python package to store my *.py files.
It seems to be the best option to me event if that means that I'll need to change my requirements.txt file on my projects on each new release.
Simple git repository
Create a new repository to store my *.py files and include them as a django app such as 'common_deps'. Then add it to my PYTHON_PATH
I need some advices, I haven't chosen yet. I'm just telling myself that git submodules seems to be a bas idea.
Tell me guys.
I will definitely go with the second option you listed - packaging your app. If you follow steps in the Packaging your app part of official Django tutorial, you'll get tar.gz file which will allow you to include your app in any project you want by simply installing (e.g. with pip) to the virtual env connected with the project or globally
I will go with python package, after all this is what it is for.

Basics of setting up a Spyder workspace and projects

I have searched for a basic tutorial regarding workspaces and projects in the Spyder IDE. What I want to understand is the basic concepts of how to use the workspace and projects to organize my code. It seems that this is perhaps basic programming skills and that is the reason why I have issues finding any kind of overview. This page seems to be related, but is actually about Eclipse and rather sparse. The Pythonxy tutorial and the documentation for Spyder does not go into any detail. Neither does the Anaconda documentation.
The questions I have are:
When should I set up a new workspace (if ever)?
When do I create a new project?
How does the PYTHONPATH depend on my workspace and project settings? Is it the same in all cases or can I customize it per workspace/project?
Are there other settings apart from the PYTHONPATH that I should configure?
How specific are the answers above to Spyder? Would it be the same for other IDEs, like Eclipse?
I am running Spyder on 64-bit Windows 7, as part of the Anaconda package.
Update Oct 2016: Spyder 3 now has project facilities similar to that of other IDEs (especially Rstudio).
Now you if you have a folder with scripts, you can go to
Projects > New Projects > Existing Directory
to import it. The selected directory will be set as the base directory for the project.
I use spyder for data analysis and I have just started using the project workspace. I believe that it allows you to write better code due to the organization. As a previous post stated that "This can be helpful in web development", which is true because web development requires good software engineering due to the complexity of the files and how they interact with each other. This organization/structure can be used in data analysis as well.
Often, data analysts that use Anaconda have an engineering or science background, not necessarily software engineering or computer science. This means that good software engineering principles may be missing (myself included). Setting up a workspace does one critical thing that I believe is missing from the discussion. It adds the workspace to the system path. Set up a project and then try
import sys
print sys.path
You will see your project's directory added to the PYTHONPATH . This means I can break up my project and import functions from different files within my project. This is highly beneficial when analysis becomes complex or you want to create some type of larger model that will be used on a regular basis. I can create all of my functions in one file, maybe functions for plots in another and then import them in a separate script file.
in myScript.py
from myFunctions import func1
from myFunctions import func2
from myPlots import histPlot
This is a much cleaner approach to data analysis and allows you to focus on one specific task at a time.
In python 3 there is the %autoreload capability so you can work on your functions and then go back to your script file and it will reload them each time if you find errors. I haven't tried this yet bc the majority of my work is in 2.7, but this would seem to add even greater flexibility when developing.
So when should you do this? I think it is always a good idea, I just started using this setup and I will never go back!
In my experience, setting up a workspace in Spyder is not always necessary.
A workspace is a space on your computer where you create and save all the files you work in. Workspaces usually help in managing your project files.
Once you create a workspace in Spyder, a pane called "Project Explorer" opens up inside Spyder. There you see in real-time the files of your project. For instance, if you generate a file with Python, it will show in that pane.
The pane let's you keep the files organized, filter them etc. This can be useful for web development for example because helps you keep your content organized.
I use Python to handle files (e.g. csv) and work with data (data analysis), and I find no use in the workspace feature.
Moreover, if you delete a file in the Project Explorer pane, the file cannot be found in the Windows recycle bin.
One critical piece of information that appears to be missing from the Spyder documentation is how to create a new workspace in the first place. When no workspace exists after installing Spyder, creating your first project automatically initiates the creation of a workspace (at least in the Anaconda 3 distribution). However, it is not as obvious how to create a new workspace when a workspace already exists.
This is the only method I have found for creating a new workspace:
(1) Select the Project explorer window in Spyder. If this window or tab doesn't appear anywhere in the Spyder application, use View > Panes > Project explorer to enable the window.
(2) Click on the folder icon in the upper-right corner of the Project explorer window. This icon brings up a dialog that can create a new workspace. The dialog allows selection of a directory for the .spyderworkspace file.

How to create an Xcode project for an existing GitHub repository

I am working with an existing GitHub repository and I want to create a new Xcode project from it. How can this be done?
I have previously used Xcode just as a python script editor and never created a project, but I would like to do so in this case so that I can have a special indentation style just for the files in this project (this is Python, so no interest in build targets etc, just want to edit and use git).
I am using Xcode 6.0.1 on Mavericks.
IanAuld's answer sent me in the right direction and I figured out what I was doing wrong. I had been assuming that the Xcode project should be inside the directory with the git project, but that was causing problems because then git tries to track the Xcode project.
Here's what I am now doing, which seems to work:
Create a new Xcode project somewhere that is not managed by git. Make sure that "Create Git repository on ..." is not checked.
Clone the github project to a directory that does not include the Xcode project.
In Xcode, File | Add Files to "ProjectName"..., and select the folder with the git project.
Now, if I edit any of those files in the context of the project, it uses the indentation style I set for the project (though if I edit the file on its own it uses my global indentation style), and I can control git through the Source Control menu.
Problem solved.

Referencing an external library in a Python appengine project, using Pydev/Eclipse

it's a couple of months I've started development in Python - having myself a C# and Java background.
I'm currently working on 2 different python/appengine applications, and as often happens in those cases, both application share common code - so I would like to refactor and move the common/generic code into a shared place.
In either Java or C# I'd just create a new library project, move the code into the new project and add a reference to the library from the main projects.
I tried the same in Python, but I am unable to make it work.
I am using Eclipse with Pydev plugin.
I've created a new Pydev project, moved the code, and attempted to:
reference the library project from the main projects (using Project Properties -> Project References)
add the library src folder folder into the main projects (in this case I have an error - I presume it's not possible to leave the project boundaries when adding an existing source folder)
add as external library (pretty much the same as google libraries are defined, using Properties -> External libraries)
Import as link (from Import -> File System and enabling "Create links in workspace")
In all cases I am able to reference the library code while developing, but when I start debugging, the appengine development server throws an exception because it can't find what I have moved into a separate library project.
Of course I've searched for a solution a lot, but it looks like nobody has experienced the same problem - or maybe nobody doesn't need to do the same :)
The closest solution I've been able to find is to add an ant script to zip the library sources and copy in the target project - but this way debugging is a pain, as I am unable to step into the library code.
Any suggestion?
Needless to say, the proposed solution must take into account that the library code has to be included in the upload process to appengine...
Thanks
The dev_appserver and the production environment don't have any concept of projects or libraries, so you need to structure your app so that all the necessary libraries are under the application's root. The easiest way to do this, usually, is to symlink them in as subdirectories, or worst-case, to copy them (or, using version control, make them sub-repositories).
How that maps to operations in your IDE depends on the IDE, but in general, it's probably easiest to get the app structured as you need it on disk, and work backwards from that to get your IDE set up how you like it.

Categories

Resources