Commit/Push from Pycharm to GitHub contains packages - python

I'm working on a Python app using the Pycharm IDE. I've just finished the first version of my app and am planning to commit and push to an empty repository on GitHub.
During set up to avoid the constant popup questions about adding files to Git, I choose an option to add all files. This may have been a mistake as it seems I've added 21,750 files to the repository. I was expected less than 10.
Looking at the list of tiles I'm seeing nearly all of them are located in the
\Lib\site-packages\...
with the ... being the various packages that I've imported for the scripts to run.
Should I be excluding everything from this folder?

Yes. You should remove the libraries from version control.
I suggest using a gitignore file to ignore the venv folder, .idea, etc.

Related

How to keep .py files in directory, but exclude in build distribution?

I'm currently working on publishing a python package (I've already ran installation tests on test pypi and am able to pip install and run my code cleanly in a clean environment).
Context
I currently have a working directory that contains 1) source distribution 2) build distribution 3) src folder containing my package which contains all my code for my library 4) README, LICENSE, pyproject.toml file utilizing setuptools. This working directory has a local git repository which is hooked up to a remote repository (on github).
Problem and My Attempt to Fix It
However, I'm confused about one thing that I couldn't find a clear answer on, even after looking through documentation. I have .py files, in my git repository and working directory, that I DO NOT want to include in my ACTUAL release to pypi. I attempted to use a MANIFEST.in file and used the exclude command to take these files out, but I found out that MANIFEST.in doesn't exclude python modules (.py files) in the build distributions (wheels), so when I pip install my package, the modules that I wanted gone are still included in the package on the user end. So tldr; How can I keep all my files in the working directory, but exclude certain .py files in the build distribution (before I publish to pypi)?
If I have any mistakes in my terminology/understanding of this, please correct me as I am new to this workflow of publishing packages.
Edit: I figured out a workaround, but still haven't solved this issue.
I originally wanted to exclude a single python module (a .py file) from the bdist because I didn't want the module to be accessible on the user end (i.e. if someone writes from library_name import *, I didn't want my file to be imported for them to use), however, I still wanted this file to be tracked on my git repository so that it would show up on my github repo for this project.
Instead of excluding the file from my bdist, I just included it in the bdist, but I made sure to not import it in the __init__.py so that the user couldn't access it by importing. Not the most elegant solution but it is sufficient for my situation. I will leave this question open because I am open to suggestions on how to address this.

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.

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.

Version control my python projects resource files

I'm currently moving a project between home and work using svn. The IDE I'm using is PyCharm which I find awsome. I get everything integrated into one tool.
PyCharm has the ability to create a setup.py from the virtualenv for me that I also commit to svn.
By default PyCharm is adding files to my svn repo with full recursion.
Should I also let PyCharm add the Include and Lib folders of my project and the Scripts folder? I run version 2.6 at work and 2.7 at home but I don't really want that to matter either since code wise it doesn't.
To me it seems better if that is updated on the other machine running python setup.py.
Include, Lib and Scripts folders being part of virtualenv are not part of your project thus they should not be under vcs control. You might find PyCharm: versioning .idea folder while keeping different interpreters across developers interesting as well. In addition you might want to take a look at pip requirements file as a mean to recreate the same environment for your project on different computers.

Categories

Resources