简体   繁体   English

我应该更新Python模块吗?

[英]Should I update Python modules?

I'm developing a personal program and sometimes I think it would be a good idea to update the Python modules used in the program but I don't want the program to stop working because of updated functions on the updated modules or something like that. 我正在开发一个个人程序,有时我认为更新程序中使用的Python模块是一个好主意,但是我不希望该程序因更新后的模块上的更新功能或类似功能而停止工作。 So, since when I started making the program (1 year ago), I've never updated the modules and keep all the installers inside one of the folders of the program to be able to install the correct version of each one (with an automatic installer I made to be faster when installing them). 因此,自从我开始制作该程序(一年前)以来,我从未更新过模块,也没有将所有安装程序都保留在该程序的一个文件夹中,以便能够安装每个版本的正确版本(自动安装我将安装程序设置为更快的安装程序)。 Am I doing right or is this a bad idea? 我做对了还是个坏主意? I just don't want to have to reprogram many things in my program if the functions, classes,... of the modules are updated. 如果模块的功能,类等已更新,我只是不想在程序中重新编程很多东西。 Does this happen or they will always work? 会发生这种情况还是它们将始终有效? Btw, I'm a Python beginner. 顺便说一句,我是Python初学者。

You should definitely look into updating your modules if they have known vulnerabilities. 如果模块已知漏洞,则绝对应该考虑更新它们。 A quick Google of tools that might help you with this turned out a couple of interesting hits: 一个快速的Google工具可以帮助您解决这个问题,结果带来了一些有趣的结果:

Typically open source software use semantic versioning (or semver) to provide some idea on how upgrading to a specific version will affect you. 通常,开源软件使用语义版本控制 (或semver)来提供一些有关如何升级到特定版本会影响您的想法。 Specifically the guidelines for what "part" of the version to change depends on how backwards-compatible the change is going to be: 具体来说,要更改版本的“部分”的准则取决于更改的向后兼容性

Given a version number MAJOR.MINOR.PATCH, increment the: 给定版本号MAJOR.MINOR.PATCH,增加:

  • MAJOR version when you make incompatible API changes, 当您进行不兼容的API更改时的主要版本,
  • MINOR version when you add functionality in a backwards-compatible manner, and 以向后兼容的方式添加功能时的MINOR版本,并且
  • PATCH version when you make backwards-compatible bug fixes. 进行向后兼容的错误修复时的PATCH版本。

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. 可以使用预发布和构建元数据的其他标签作为MAJOR.MINOR.PATCH格式的扩展名。

But then again, this will always be left to the discretion of the author of the module so I suggest that you start taking time to write unit tests for your code. 但是话又说回来,这将始终由模块作者决定,因此,我建议您开始花一些时间为代码编写单元测试。 This way, you'll quickly be able to see if an upgrade to one of the modules will break your code. 这样,您将能够快速查看是否升级其中一个模块会破坏您的代码。 This should be a good starting point for a list of tools that may help you with writing your tests. 应该是可以帮助您编写测试的一系列工具的良好起点。

If you do decide to upgrade, make sure that you are following good practices in making sure that you specify the correct versions of your dependencies properly and colidyre's answer should help you with that. 如果您决定升级,请确保遵循正确的做法,以确保正确指定依赖项的正确版本,而大肠菌病的答案应该可以帮助您。

Updating the modules can of course lead to corrupt code in your project. 当然,更新模块可能会导致项目中的代码损坏。 The module may of course have rewritten functions or classes, removed deprecated code, etc. in another version. 当然,该模块在另一个版本中可能具有重写的函数或类,已删除的不赞成使用的代码等。

One possible approach would be to create a virtual environment for the project, as already proposed by roganjosh. 如roganjosh所建议的,一种可能的方法是为项目创建虚拟环境。 Here is a helpful link: http://docs.python-guide.org/en/latest/dev/virtualenvs/ . 这是一个有用的链接: http : //docs.python-guide.org/en/latest/dev/virtualenvs/

In this virtual environment you can record your modules in the current versions in a requirements file. 在此虚拟环境中,您可以将当前版本的模块记录在需求文件中。 This is often done and I think it is also a good practice. 经常这样做,我认为这也是一个好习惯。 An additional advantage of this is that by simply changing the version number in the requirements file you can try out whether a newer version crashes your program or not (of course you can certainly also read the module's documentation, "breaking changes" or similar). 这样做的另一个好处是,只需更改需求文件中的版本号,您就可以尝试确定较新的版本是否会使您的程序崩溃(当然,您当然也可以阅读该模块的文档,“重大更改”或类似内容)。 Another disadvantage is that the project can only be updated at great expense at some point (too many changes at once). 另一个缺点是只能在某个时间点花费大量费用来更新项目(一次更改太多)。 You could then successively update one module after the other and see whether project code needs to be changed here and there. 然后,您可以依次更新一个模块,然后查看是否需要在此处和此处更改项目代码。

If you just want to run your project and there are no security concerns, then it's probably enough to fix the versions and that's it. 如果您只想运行您的项目而没有安全问题,那么修复版本就足够了。

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

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