Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended workflow for cloning git into a virtual Python environment

What is the recommended workflow if I want to pull a git repo into a virtual Python environment? I think it's easiest to:

  1. Create an empty directory
  2. cd into it and git clone <repo>, as this will work only in empty directories
  3. create the virtual environment in a subdir in the same directory
  4. Start the VE and install requirements.txt from the <repo>.
  5. Add the subdir (and other stuff for my eyes only) to .gitignore
  6. work on project as intended
  7. perhaps ask to push valuable/shareable results to the original repo.

Or is there a better way?

Disclaimer: I'm quite a n00b with git, please bear with me. I'm well aware there are multiple similar answers already, however I couldn't find a convincing TL;DR. Perhaps I missed it.

like image 686
RolfBly Avatar asked Mar 10 '19 12:03

RolfBly


People also ask

How do I run a Git clone in python?

We can use git module in python to clone the repository from git. Clone the repository you want to work with in local system. So in clone_from methods pass the two arguments in which first argument is url of your repository and second argument is the location of your directory where you want to cloned the repo.

How do I clone a python project from GitHub?

In the Directory field, enter the path to the folder where your local Git repository will be created. Click Clone. If you want to create a project based on these sources, click Yes in the confirmation dialog. PyCharm will automatically set Git root mapping to the project root directory.


1 Answers

If there's already an existing virtualenv for a project that you want to clone a library into to work with, the following steps will help you:

  1. Activate the project's virtualenv
    source .venv/bin/activate.fish
  2. Uninstall the package you want to have replaced with a git clone:
    pip uninstall <package>
  3. Re-install the package via git:
    pip install -e git+ssh://[email protected]/<org>/<package>.git#egg=<package>
  4. Change to package directory to work on the repository
    cd .venv/src/<package>
like image 96
jnns Avatar answered Oct 20 '22 19:10

jnns