简体   繁体   English

从虚拟环境中在PyCharm中注册VCS根目录?

[英]Registering VCS root in PyCharm from within virtual environment?

I have checked out my modules in my django project with the -e, --editable path/url option in pip, and the .git roots have been installed in my .env/src/{EGG} folder. 我在与-e,--editable路径/ url选项在PIP Django项目检查了我的模块和git的根已经安装在我的.ENV / src目录/ {} EGG文件夹。

But unfortunately PyCharm doesn't detect them as a separate VCS root, and my code changes cannot be committed to the repository checked out inside my modules. 但是不幸的是,PyCharm并未将它们检测为单独的VCS根目录,并且我的代码更改无法提交到模块内部检出的存储库。

How do I register the VCS roots, preferably automatically because there are a lot of components our project depends on. 我如何注册VCS根目录,最好自动注册,因为我们的项目依赖很多组件。

I have found out that if I open up one by one in pycharm by selecting show hidden files and folders, I can manually add them. 我发现,如果我通过选择显示隐藏的文件和文件夹在pycharm中一个一个地打开,则可以手动添加它们。 But I would prefer it to be done automatically. 但我希望它可以自动完成。

Ok since no one has answered my question, I wrote this simple script that I added in my path folder in utils. 好的,因为没有人回答我的问题,所以我写了这个简单的脚本,将其添加到utils的path文件夹中。

So when I execute this in my project root folder, the VCS roots get added in pycharm upon restart. 因此,当我在项目根文件夹中执行此操作时,VCS根将在重新启动后添加到pycharm中。

https://github.com/virogenesis/pycharm_vcsrootgenerator https://github.com/virogenesis/pycharm_vcsrootgenerator

If these modules are supposed to be part of your project (PyCharm then detects VCS roots automatically) then you should check them out into your project directory and not into .env/src . 如果这些模块应该属于您的项目(PyCharm然后会自动检测VCS根目录),则应将它们检出到项目目录中,而不要.env/src.env/src
You can do it in the following ways: 您可以通过以下方式进行操作:

  • Use --src <dir> option of pip install command, when <dir> according to pip's documentation is 如果根据pip文档的<dir>是,请使用pip install命令的--src <dir> 选项

Directory to check out editable projects into. 检出可编辑项目的目录。 The default in a virtualenv is <venv path>/src . virtualenv中的默认值为<venv path>/src The default for global installs is <current dir>/src . 全局安装的默认值为<current dir>/src

  • Check them out with git and then install into virtualenv with pip install --editable /path/to/modules (it might be best to invoke pip from within the directory with setup.py file as often setup.py files are not prepared to be run from different directory) 使用git检出它们,然后使用pip install --editable /path/to/modules安装到virtualenv中(最好是使用setup.py文件从目录中调用pip ,因为通常不准备将setup.py文件从其他目录运行)

If you have some external (third party) Python packages used in the project which you would like to have easy way to modify and provide patches upstream, it might be good idea to check them out in the same way to some specific ( external , deps , thirdparty are likely names) directory of your project in the same way. 如果你有一些外部(第三方)的Python项目中使用的包,你希望有简单的方法来修改和上游提供的补丁,它可能是好主意,检查他们以同样的方式向某些特定的( externaldepsthirdparty可能是您项目的目录)。 Remember to ignore this specific directory in the configuration of yours project's VCS. 切记在项目的VCS的配置中忽略此特定目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM