python持续集成_与Python的持续集成:简介

python持续集成

When writing code on your own, the only priority is making it work. However, working in a team of professional software developers brings a plethora of challenges. One of those challenges is coordinating many people working on the same code.

自己编写代码时,唯一的优先事项就是使其正常工作。 但是,在专业软件开发人员团队中工作会带来很多挑战。 这些挑战之一是协调许多使用相同代码的人员。

How do professional teams make dozens of changes per day while making sure everyone is coordinated and nothing is broken? Enter continuous integration!

专业团队如何每天进行数十次更改,同时确保每个人都协调一致且没有任何问题? 输入持续集成!

In this tutorial you’ll:

在本教程中,您将:

  • Learn the core concepts behind continuous integration
  • Understand the benefits of continuous integration
  • Set up a basic continuous integration system
  • Create a simple Python example and connect it to the continuous integration system
  • 了解持续集成背后的核心概念
  • 了解持续集成的好处
  • 建立基本的持续集成系统
  • 创建一个简单的Python示例并将其连接到持续集成系统

Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.

免费奖金: 关于Python精通的5个想法 ,这是针对Python开发人员的免费课程,向您展示了将Python技能提升到新水平所需的路线图和心态。

什么是持续集成? (What Is Continuous Integration?)

Continuous integration (CI) is the practice of frequently building and testing each change done to your code automatically and as early as possible. Prolific developer and author Martin Fowler defines CI as follows:

持续集成(CI)是一种频繁地自动并尽早构建和测试对代码所做的每次更改的实践。 多产的开发人员和作家Martin Fowler对CI的定义如下:

“Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily – leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible.” (Source)

“持续集成是一种软件开发实践,团队成员经常集成他们的工作,通常每个人至少每天集成一次-导致每天多次集成。 每个集成都通过自动构建(包括测试)进行验证,以尽快检测到集成错误。” ( 来源

Let’s unpack this.

让我们打开包装。

Programming is iterative. The source code lives in a repository that is shared by all members of the team. If you want to work on that product, you must obtain a copy. You will make changes, test them, and integrate them back into the main repo. Rinse and repeat.

编程是迭代的。 源代码位于由团队所有成员共享的存储库中。 如果要使用该产品,则必须获得一份副本。 您将进行更改,对其进行测试,然后将其重新集成到主存储库中。 冲洗并重复。

Not so long ago, these integrations were big and weeks (or months) apart, causing headaches, wasting time, and losing money. Armed with experience, developers started making minor changes and integrating them more frequently. This reduces the chances of introducing conflicts that you need to resolve later.

不久之前,这些集成相隔数周(数月)之久,造成了头痛,浪费时间和亏损。 有了经验,开发人员开始进行较小的更改并更频繁地进行集成。 这减少了引入需要稍后解决的冲突的机会。

After every integration, you need to build the source code. Building means transforming your high-level code into a format your computer knows how to run. Finally, the result is systematically tested to ensure your changes did not introduce errors.

每次集成之后,您都需要构建源代码。 构建意味着将高级代码转换为计算机知道如何运行的格式。 最后,系统地测试结果,以确保您的更改不会引入错误。

我为什么要在乎? (Why Should I Care?)

On a personal level, continuous integration is really about how you and your colleagues spend your time.

在个人层面上,持续集成实际上就是您和您的同事如何度过的时间。

Using CI, you’ll spend less time:

使用CI,您将花费更少的时间:

  • Worrying about introducing a bug every time you make changes
  • Fixing the mess someone else made so you can integrate your code
  • Making sure the code works on every machine, operating system, and browser
  • 每次更改时都担心引入错误
  • 修复其他人造成的混乱,以便您可以集成代码
  • 确保代码在每台机器,操作系统和浏览器上均有效

Conversely, you’ll spend more time:

相反,您将花费更多时间:

  • Solving interesting problems
  • Writing awesome code with your team
  • Co-creating amazing products that provide value to users
  • 解决有趣的问题
  • 与您的团队一起编写出色的代码
  • 共同创造为用户提供价值的惊人产品

How does that sound?

听起来怎么样?

On a team level, it allows for a better engineering culture, where you deliver value early and often. Collaboration is encouraged, and bugs are caught much sooner. Continuous integration will:

从团队的角度来看,它允许更好的工程文化,您可以在其中早日,经常地交付价值。 鼓励协作,并且可以更快地发现错误。 持续集成将:

  • Make you and your team faster
  • Give you confidence that you’re building stable software with fewer bugs
  • Ensure that your product works on other machines, not just your laptop
  • Eliminate a lot of tedious overhead and let you focus on what matters
  • Reduce the time spent resolving conflicts (when different people modify the same code)
  • 使您和您的团队更快
  • 让您充满信心,以更少的错误构建稳定的软件
  • 确保您的产品可以在其他计算机上运行,​​而不仅仅是笔记本电脑上
  • 消除许多繁琐的开销,让您专注于重要的事情
  • 减少解决冲突所花费的时间(当不同的人修改相同的代码时)

核心概念 (Core Concepts)

There are several key ideas and practices that you need to understand to work effectively with continuous integration. Also, there might be some words and phrases you aren’t familiar with but are used often when you’re talking about CI. This chapter will introduce you to these concepts and the jargon that comes with them.

您需要了解一些关键思想和实践,才能通过持续集成有效地工作。 另外,可能有一些您不熟悉的单词和短语,但是在谈论CI时经常使用。 本章将向您介绍这些概念及其附带的术语。

单一来源存储库 (Single Source Repository)

If you are collaborating with others on a single code base, it’s typical to have a shared repository of source code. Every developer working on the project creates a local copy and makes changes. Once they are satisfied with the changes, they merge them back into the central repository.

如果您要在单个代码库上与其他人进行协作,通常会拥有一个共享的源代码存储库。 每个从事该项目的开发人员都会创建一个本地副本并进行更改。 一旦他们对更改感到满意,便将其合并回中央存储库。

It has become a standard to use version control systems (VCS) like Git to handle this workflow for you. Teams typically use an external service to host their source code and handle all the moving parts. The most popular are GitHub, BitBucket, and GitLab.

使用像Git这样的版本控制系统(VCS)为您处理此工作流已成为一种标准。 团队通常使用外部服务来托管其源代码并处理所有活动部分。 最受欢迎的是GitHub,BitBucket和GitLab。

Git allows you to create multiple branches of a repository. Each branch is an independent copy of the source code and can be modified without affecting other branches. This is an essential feature, and most teams have a mainline branch (often called a master branch) that represents the current state of the project.

Git允许您创建存储库的多个分支 。 每个分支都是源代码的独立副本,可以在不影响其他分支的情况下进行修改。 这是一项重要功能,大多数团队都有代表项目当前状态的主线分支(通常称为主分支)。

If you want to add or modify code, you should create a copy of the main branch and work in your new, development branch. Once you are done, merge those changes back into the master branch.

如果要添加或修改代码,则应创建main分支的副本并在新的development分支中工作。 完成后,将这些更改合并回master分支。

Git Branching
Git branching
Git分支

Version control holds more than just code. Documentation and test scripts are usually stored along with the source code. Some programs look for external files used to configure their parameters and initial settings. Other applications need a database schema. All these files should go into your repository.

版本控制不仅仅包含代码。 文档和测试脚本通常与源代码一起存储。 一些程序会寻找用于配置其参数和初始设置的外部文件。 其他应用程序需要数据库架构。 所有这些文件都应放入您的存储库中。

If you have never used Git or need a refresher, check out our Introduction to Git and GitHub for Python Developers.

如果您从未使用过Git或需要复习,请查看我们的Python开发人员Git和GitHub简介

自动化构建 (Automating the Build)

As previously mentioned, building your code means taking the raw source code, and everything necessary for its execution, and translating it into a format that computers can run directly. Python is an interpreted language, so its “build” mainly revolves around test execution rather than compilation.

如前所述,构建代码意味着获取原始源代码以及执行它所需的一切,并将其转换为计算机可以直接运行的格式。 Python是一种解释型语言 ,因此它的“构建”主要围绕测试执行而不是编译。

Running those steps manually after every small change is tedious and takes valuable time and attention from the actual problem-solving you’re trying to do. A big part of continuous integration is automating that process and moving it out of sight (and out of mind).

每次进行细微更改后,手动执行这些步骤都是很繁琐的工作,并且需要花费宝贵的时间和精力来解决您要解决的实际问题。 持续集成的很大一部分是使该过程自动化并将其移到视线之外(和头脑之外)。

What does that mean for Python? Think about a more complicated piece of code you have written. If you used a library, package, or framework that doesn’t come with the Python standard library (think anything you needed to install with pip or conda), Python needs to know about that, so the program knows where to look when it finds commands that it doesn’t recognize.

这对Python意味着什么? 考虑一下您编写的更复杂的代码。 如果您使用的是Python标准库所没有的库,包或框架(请考虑使用pipconda安装所需的任何东西),则Python需要知道这一点,因此程序在找到时会知道在哪里寻找无法识别的命令。

You store a list of those packages in requirements.txt or a Pipfile. These are the dependencies of your code and are necessary for a successful build.

您可以将这些软件包的列表存储在requirements.txt或Pipfile中。 这些是您代码的依赖项,对于成功构建是必需的。

You will often hear the phrase “breaking the build.” When you break the build, it means you introduced a change that rendered the final product unusable. Don’t worry. It happens to everyone, even battle-hardened senior developers. You want to avoid this primarily because it will block everyone else from working.

您经常会听到“破坏体系”的说法。 当您中断构建时,意味着您进行了更改,使最终产品无法使用。 不用担心 它发生在每个人身上,甚至是经过艰苦奋战的高级开发人员。 您主要想避免这种情况,因为它会阻止其他所有人工作。

The whole point of CI is to have everyone working on a known stable base. If they clone a repository that is breaking the build, they will work with a broken version of the code and won’t be able to introduce or test their changes. When you break the build, the top priority is fixing it so everyone can resume work.

CI的全部目的是让每个人都在一个已知的稳定基础上工作。 如果他们克隆了破坏构建的存储库,那么他们将使用代码的损坏版本,并且将无法引入或测试其更改。 当您中断构建时,最重要的是修复它,以便每个人都可以恢复工作。

Pushing Breaking Changes to Master
Introducing a breaking change to the master branch
向主分支引入重大更改

When the build is automated, you are encouraged to commit frequently, usually multiple times per day. It allows people to quickly find out

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值