简体   繁体   English

如何找出与我的代码兼容的所有以前的python版本

[英]How do I find out all previous versions of python with which my code is compatible

I have created a medium sized project in python 2.7.3 containing around 100 modules. 我在python 2.7.3中创建了一个中等大小的项目,其中包含大约100个模块。 I wish to find out with which previous versions of python (ex: 2.6.x, 2.7.x) is my code compatible (before releasing my project in public domain). 我希望找出与python的先前版本(例如:2.6.x,2.7.x)兼容的代码(在公共领域发布我的项目之前)。 What is the easiest way to find it out? 找出它的最简单方法是什么?

Solutions I know - 我知道的解决方案-

  1. Install multiple versions of python and check in every versions. 安装多个版本的python并签入每个版本。 But I don't have test cases defined yet, so need to define those first. 但是我还没有定义测试用例,因此需要先定义那些用例。
  2. Read and compare changelog of the various python versions I wish to check compatibility for, and accordingly find out. 阅读并比较我希望检查其兼容性的各种python版本的changelog,并据此查找。

Kindly provide better solutions. 请提供更好的解决方案。

I don't really know of a way to get around doing this without some test cases. 我真的不知道没有一些测试用例就能解决这个问题的方法。 Even if your code could run in an older version of python there is no guarantee that it works correctly without a suite of test cases that sufficiently test your code 即使您的代码可以在旧版本的python中运行,也不能保证没有一组足以测试您的代码的测试用例,它就可以正确运行

No, what you named is pretty much how it's done, though the What's New pages and the documentation proper may be more useful than the full changelog. 不,虽然“新增功能”页面和适当的文档可能比完整的变更日志更有用,但您所命名的几乎是完成工作的方式。 Compatibility to such a huge, moving target is infeasible to automate even partially. 与如此巨大的移动目标的兼容性甚至无法部分自动化。 It's just not as much work as it sounds like, because: 它的工作量并不像听起来那样多,因为:

  1. Some people do have test suites ;-) 有些人确实有测试套件;-)
  2. You don't (usually) need to consider bugfix releases (such as 2.7.x for various x). 您(通常)不需要考虑错误修正版本(例如针对各种x的2.7.x)。 It's possible that your code requires a bug fix, but generally the .0 releases are quite reliable and code compatible with xy0 can run on any xyz version. 您的代码可能需要修复错误,但通常.0版本非常可靠,并且与xy0兼容的代码可以在任何xyz版本上运行。
  3. Thanks to the backwards compatibility policy, it is enough to establish a minimum supported version, all later releases (of the same major version) will stay compatible. 由于具有向后兼容性策略,因此可以建立最低支持版本,所有以后的发行版(相同的主要版本)将保持兼容。 This doesn't help in your case as 2.7 is the last 2.x release ever, but if you target, say, 2.5 then you usually don't have to check for 2.6 or 2.7 compatibility. 这对于您的情况无济于事,因为2.7是有史以来最新的2.x版本,但是如果目标是2.5,则通常不必检查2.6或2.7兼容性。
  4. If you keep your eyes open while coding, and have a bit of experience as well as a good memory, you'll know you used some functionality that was introduced in a recent version. 如果您在编码时睁开眼睛,既有经验又有良好的记忆力,那么您会知道您使用了最新版本中引入的一些功能。 Even if you don't know what version specifically, you can look it up quickly in the documentation. 即使您不知道具体是哪个版本,也可以在文档中快速查找它。
  5. Some people embark with the intent to support a specific version, and always keep that in mind when developing. 有些人打算支持特定版本,因此在开发时始终牢记这一点。 Even if it happens to work on other versions, they'd consider it unsupported and don't claim compatibility. 即使它碰巧可以在其他版本上使用,他们也会认为它不受支持,并且不主张兼容性。

So, you could either limit yourself to 2.7 (it's been out for three years), or perform tests on older releases. 因此,您可以将自己限制为2.7(已经使用了三年),也可以在较旧的版本上进行测试。 If you just want to determine whether it's compatible, not which incompatibilities there are and how they can be fixed, you can: 如果您只想确定它是否兼容,而不是确定存在哪些不兼容以及如何解决这些不兼容,则可以:

  1. Search the What's New pages for new features, most importantly new syntax, which you used. 在“新增功能”页面上搜索所使用的新功能,最重要的是新语法。
  2. Check the version constraints of third party libraries you used. 检查您使用的第三方库的版本限制。
  3. Search the documentation of standard library modules you use for newly added functionality. 搜索用于新添加功能的标准库模块的文档。

1) If you're going to maintain compatibility with previous versions, testing is the way to go. 1)如果要保持与以前版本的兼容性,则必须进行测试。 Even if your code happens to be compatible now, it can stop being so at any moment in the future if you don't pay attention. 即使您的代码现在恰好兼容,但如果您不注意的话,将来任何时候都可能停止兼容。

2) If backwards compatibility is not an objective but just a "nice side-feature for those lucky enough", an easy way for OSS is to let users try it out, noting that "it was tested in <version> but may work in previous ones as well". 2)如果向后兼容性不是目标,而仅仅是“足够幸运的人的附属功能”,那么OSS的一种简单方法就是让用户尝试一下,并指出“它已经在<version>进行了测试,但可以在以前的”。 If there's anyone in your user base interested in running your code in an earlier version (and maintain compatibility with it), they'll probably give you feedback. 如果您的用户群中有任何人有兴趣在较早版本中运行您的代码(并保持与之的兼容性),他们可能会给您反馈。 If there isn't, why bother? 如果没有,何必呢?

A lot easier with some test cases but manual testing can give you a reasonably idea. 使用一些测试用例会容易得多,但是手动测试可以为您提供一个合理的想法。

Take the furthest back version that you would hope to support, (I would suggest 2.5.x but further back if you must - manually test with that version keeping notes of what you did and especially where it fails if any where - if it does fail then either address the issue or do a binary search to see which version the failure point(s) disappear at. This could work even better if you start from a version that you are quite sure you will fail at, 2.0 maybe. 取得您希望支持的最新版本((我建议使用2.5.x,但如果需要则建议更进一步)-手动测试该版本,并记下您所做的操作,尤其是在出现故障的地方-如果出现故障-如果发生故障然后解决该问题或进行二进制搜索以查看故障点消失在哪个版本上。如果您从肯定会失败的版本开始,则可能会更好,例如2.0。

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

相关问题 如何确保我的Python 3.6代码与其他次要版本兼容? - How do I make sure my Python 3.6 code is compatible with other minor versions? 如何找到我的Python安装中的VM? - How to find out which VM i have in my Python installation? 我如何找出我的代码的哪些部分在Python中效率低下 - How do I find out what parts of my code are inefficient in Python 如何找到运行Django站点的Python,Django版本和路径? - How do I find out the Python, Django versions and path that a Django site is running? 如何使用 Python 找出我的 PYTHONPATH? - How do I find out my PYTHONPATH using Python? 如何更改我的代码以与此单元测试兼容? - How do I change my code to be compatible with this unittest? 我如何知道我的应用程序支持哪些版本的依赖项? - How do I know which versions of dependencies my application supports? 如何确定哪个 MS Edge 驱动程序与我的操作系统版本兼容,以启用 web 自动化和 Python 的 Selenium? - How do I determine which MS Edge Driver is compatible with my OS Version to enable web automation with Selenium for Python? 删除所有以前版本的python - Remove all previous versions of python 如何找到我的函数调用的文件或模块? - How do I find out in which file or module is my function called?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM