简体   繁体   English

使用Git / PyCharm维护Lite项目的精简版和专业版

[英]Maintaining a Lite and Pro Version of Python Project with Git/PyCharm

Background 背景

I am wrapping up a python project, and I am considering releasing a it with pro/lite versions. 我正在结束一个python项目,我正在考虑用pro / lite版本发布它。 I don't want duplicate code laying around, of course, but I can't release a free version with many of the capabilities of the pro version only disabled with a few if checks: the code is for a Blender add-on and therefore will be easily edited and turned into a pro version if the features are still there. 当然,我不希望重复的代码存在,但我不能发布一个免费版本,其中许多专业版的功能仅在几个if检查时被禁用:代码用于Blender附加组件,因此如果功能仍然存在,将很容易编辑并转换为专业版。

Question

What is the best way to maintain a project like this using Git/Pycharm (or am I better off to just not worry about a lite version) without duplicate code ? 使用Git / Pycharm维护这样的项目的最佳方法是什么(或者我最好不要担心精简版) 没有重复的代码 I have read that using multiple Git branches is not the way to go. 我已经读过使用多个Git分支不是要走的路。

Disclaimer 放弃

I do realize that there have been many similar questions about this topic. 我确实意识到关于这个话题有很多类似的问题。 However, many of these deal with using Xcode, and many more do not have clear answers. 然而,其中许多涉及使用Xcode,而且还有更多没有明确的答案。 Don't get me wrong, I know I could do this a number of ways - but I am looking for the best way, the cleanest way. 不要误会我的意思,我知道我可以通过多种方式做到这一点 - 但我正在寻找最好的方式, 最干净的方式。

Here's basic idea, based on you segregating out code into different modules. 这是基本的想法,基于您将代码分离到不同的模块。 Right now, the concept is having 2 different download points. 目前,该概念有2个不同的下载点。 But it doesn't have to be, that's your call. 但它不一定是,这是你的电话。

Regardless of which packaging/distribution approach you take, you'll have to separate out codelines into different code modules. 无论采用哪种打包/分发方法,您都必须将代码行分离到不同的代码模块中。 Even if it's just one download. 即使它只是一个下载。

lite/common_core.py - installed from github.lite lite / common_core.py - 从github.lite安装

#things you want in common between pro and lite
#i.e. what would be your "duplicate code"
def common_func1():
    pass

Note: I would not put stuff common to both pro and lite directly into lite/main.py, because you want to present a unified API by exposing pro in lite, but you don't want to also have pro import lite, because that would risk circular import dependencies. 注意:我不会将pro和lite中常见的东西直接放到lite / main.py中,因为你想通过公开pro中的pro来呈现统一的API,但你不想也有pro import lite,因为那样会冒循环导入依赖性的风险。

lite/main.py - installed from github.lite lite / main.py - 从github.lite安装

#things you want in common between pro and lite
import lite.common_core
#or import lite.common_core as common

def lite_function1():
    pass

def lite_function2():
    pass

try:
    #you need to determine an appropriate path strategy
    #a pypi-installed pro package should be available on the sys.path
    from pro.main import *
    # or import pro.main as pro
except ImportError:
    pass

#client code can now call functions from the lite and pro

pro/main.py - installed from github.pro pro / main.py - 从github.pro安装

import lite.common_core

def pro_function1():
    pass

You could have lite be a requirement of the pro pypi package, so that the user would still have only one download if they started that way. 你可以将lite作为pro pypi包的一个要求,这样如果用户以这种方式启动,用户仍然只能进行一次下载。

Also, wrt to the answer you pointed to re git branches, another way to think of it is that you might be trying to fix/enhance say pro . 另外,对于你指向re git branches的答案,另一种想到它的方法是你可能正在尝试修复/增强说赞成 So, from pro's master , you'd want the freedom to create a new branch and still be aware of lite's master (because you depend on it). 所以,从专业大师那里,你需要自由创建一个新的分支,并且仍然知道精简版的主人 (因为你依赖它)。 That kinda bookkeeping is going to be difficult if you are juggling pro and lite on the same repo, with branches used to separate out pro/lite. 如果你在同一个回购杂志上玩专业版和精简版,用分支用来分离专业/精简版,这种记账将会很困难。

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

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