Search code examples
pythonpycharm

What is the best way to work privately on pypi released package within Pycharm?


I have a Python package that is released in pypi and can be installed via pip install.

I want to do some minor changes in that package that are only of use for me in my Pycharm project A. I expect that these changes will be quite frequent, so I want to be able to do these changes on the fly.

I know that I can work with a local copy of that project / package by doing the following steps:

  1. perform a git clone

  2. use that code as a separate Pycharm project B

  3. in my own project A, I write:

     import sys
     sys.path.insert(0, '/path/to/second_pycharm_project')
    
     import project_name
    

Now I can do code changes in the Pycharm project B and executing project A just reflects that correctly.

Nevertheless, I have some constraints:

  1. Variable / code lookup within Pycharm is not possible this way.
  2. Setting a breakpoint in project B has to be done within project A and seems to work only while entering the code of B during debugging.

My question is:

Is there any other (better) way to use another project within Pycharm?

(I thought of changing the code that gets copied by pip install in my virtual environment directly, but this seems very unclean and dangerous to me, in case my changes get accidentally overwritten by pip install)


Solution

  • Clone then pip install -e . of B on A’s virtualenv (do it in the directory with B’s setup.py). That’s a local editable install and puts B in A sys.path.

    Git Branch B so you can do your local B edits wo impact to its git origin (but could still merge it later if you wish to).

    Use Settings | (current) Project | Project Structure | Add Content Root in Pycharm to add the other project B to your main project A.

    (Make sure you keep track of local B changes because nothing here does that if you were to duplicate your work on a different machine and git clone B again).

    Remark: it must be a small -e and not a big -E.