mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
0dabbf1bd9
@ -0,0 +1,69 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (messon007)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12141-1.html)
|
||||
[#]: subject: (What is the internet backbone and how it works)
|
||||
[#]: via: (https://www.networkworld.com/article/3532318/what-is-the-internet-backbone-and-how-it-works.html)
|
||||
[#]: author: (Tim Greene https://www.networkworld.com/author/Tim-Greene/)
|
||||
|
||||
什么是互联网骨干网,它是怎样工作的
|
||||
======
|
||||
|
||||
> 一级互联网服务提供商(ISP)将其高速光纤网络连接在一起,形成互联网的骨干网,实现在不同地理区域之间高效地传输流量。
|
||||
|
||||

|
||||
|
||||
互联网会产生大量的计算机到计算机的流量,要确保所有流量都可以在世界上任何地方之间传输,就需要大量汇聚的高速网络,这些网络统称为互联网骨干网,但是它是如何工作的呢?
|
||||
|
||||
### 互联网的骨干网是什么?
|
||||
|
||||
像任何其他网络一样,互联网由接入链路组成,这些接入链路将流量传输到高带宽路由器,路由器又将流量从源地址通过最佳可用路径传输到目的地址。其核心是由相互连接的、彼此对等的各个高速光纤网络而构成的互联网骨干网。
|
||||
|
||||
单个独立的核心网络由一级互联网服务提供商(ISP)所拥有。他们的网络连接在一起。这些提供商包括 AT&T、CenturyLink、Cogent Communications,、Deutsche Telekom、Global Telecom and Technology (GTT)、NTT Communications、Sprint、Tata Communications,、Telecom Italia Sparkle、Telia Carrier和 Verizon。
|
||||
|
||||
通过将这些长途网连接在一起,一级 ISP 们创建了一个他们可以访问整个路由表的单一的全球性网络,因此他们可以通过逐步层次化地增加本地 ISP 网络来有效地将流量传输到其目的地。
|
||||
|
||||
除了物理连接之外,这些骨干网提供商还通过一致的网络协议 TCP/IP 融合在一起,这实际上是两个协议,<ruby>传输控制协议<rt>transport control protocol</rt></ruby>和<ruby>互联网协议<rt>internet protocol</rt></ruby>,它们在计算机之间建立连接,以确保连接可靠,并将消息格式化为数据包。
|
||||
|
||||
### 互联网交接点(IXP)将骨干网连接在一起
|
||||
|
||||
骨干网 ISP 在中立位置的对等点通过高速交换机和路由器连接其网络。这些通常由第三方(有时是非营利组织)提供,以促进骨干网的统一。
|
||||
|
||||
参与的一级 ISP 会帮助资助 IXP,但不向其他一级 ISP 收取流量传输费用,这种关系称为无结算对等。这种协议消除了可能导致互联网性能下降的潜在财务纠纷。
|
||||
|
||||
### 骨干网有多快?
|
||||
|
||||
互联网骨干网由最快的路由器组成,可以提供 100Gbps 的线路速度。这些路由器由包括 Cisco、Extreme、华为、Juniper 和 Nokia 在内的供应商制造,使用边界网关协议(BGP)在彼此之间路由流量。
|
||||
|
||||
### 流量是如何进入骨干网的
|
||||
|
||||
在 1 级 ISP 之下是规模较小的 2 级和 3 级 ISP。
|
||||
|
||||
3 级 ISP 为企业和消费者提供了互联网接入服务。这些提供商自己没有接入互联网骨干网,因此,他们自己无法将其客户连接到数十亿台互联网上的计算机。
|
||||
|
||||
购买一级 ISP 提供商的接入非常昂贵。通常 3 级 ISP 与拥有自己网络的 2 级(区域)ISP 签订合同,利用 2 级 ISP 的网络将流量传输到有限的地理区域,但不能传输到所有互联网上的设备。
|
||||
|
||||
为此,2 级 ISP 与 1 级 ISP 签约以访问全球骨干网,并以这种方式使客户可以访问整个互联网。
|
||||
|
||||
这种方式使得来自世界一侧的计算机的流量能够连接到另一侧的计算机。流量从源计算机流向 3 级 ISP,再路由到 2 级 ISP,再路由到 1 级骨干网提供商,再路由到正确的 2 级 ISP,最后路由到提供该数据的 3 级接入提供商连接的目标计算机。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3532318/what-is-the-internet-backbone-and-how-it-works.html
|
||||
|
||||
作者:[Tim Greene][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[messon007](https://github.com/messon007)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Tim-Greene/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://pixabay.com/en/social-media-digitization-faces-3271592/
|
||||
[2]: https://creativecommons.org/publicdomain/zero/1.0/
|
||||
[3]: https://www.networkworld.com/newsletters/signup.html
|
||||
[4]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE21620&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||
[5]: https://www.facebook.com/NetworkWorld/
|
||||
[6]: https://www.linkedin.com/company/network-world
|
@ -0,0 +1,169 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12143-1.html)
|
||||
[#]: subject: (How to package Python applications for Linux)
|
||||
[#]: via: (https://opensource.com/article/20/4/package-python-applications-linux)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
如何为 Linux 打包 Python 应用
|
||||
======
|
||||
|
||||
> 了解如何使用 dh_virtualenv 来让你的 Python 应用可作为 .deb 包安装。
|
||||
|
||||

|
||||
|
||||
在基于 Debian 的操作系统(例如 Debian 或 [Elementary OS][2])上安装 Python 应用的一种方法是使用 [dh_virtualenv][3] 工具。它可以构建一个 `.deb` 包,在应用之外封装了一个 Python 虚拟环境,并在安装时进行部署。
|
||||
|
||||
在本文中,我将以构建一个包含 [HTTPie][4] 工具的包为例来解释如何使用它,以便在无需激活虚拟环境的情况下从命令行测试 HTTP API。
|
||||
|
||||
### 使用 dh_virtualenv 打包
|
||||
|
||||
首先,你需要安装 `dh_virtualenv` 所需的工具。`dh_virtualenv` 的[文档][5]提供了所有安装选项。在基于 Debian 的系统上,我输入:
|
||||
|
||||
```
|
||||
apt-get install dh-virtualenv devscripts
|
||||
```
|
||||
|
||||
尽管不需要 [devscripts][6] 包,但它可以简化后续操作。
|
||||
|
||||
现在,创建一个目录来保存源码。由于这是一个本地的、非官方的 HTTPie 打包,因此我将其称为 `myhttp`。接下来,让我们在 `myhttp` 内创建一些文件,向 Debian 构建系统提供元数据。
|
||||
|
||||
首先,创建 `debian/control` 文件:
|
||||
|
||||
```
|
||||
Source: myhttp
|
||||
Section: python
|
||||
Priority: extra
|
||||
Maintainer: Jan Doe <jandoe@example.org>
|
||||
Build-Depends: debhelper (>= 9), python3.7, dh-virtualenv (>= 0.8)
|
||||
Standards-Version: 3.9.5
|
||||
|
||||
Package: myhttp
|
||||
Architecture: any
|
||||
Pre-Depends: dpkg (>= 1.16.1), python3.7, ${misc:Pre-Depends}
|
||||
Depends: ${misc:Depends}
|
||||
Description: http client
|
||||
Useful for doing stuff
|
||||
```
|
||||
|
||||
那么这些是什么信息呢?正如 [Debian 文档][8]指出的:
|
||||
|
||||
>“第 1–7 行是源码包的控制信息。第 9–13 行是二进制包的控制信息。”
|
||||
|
||||
以下是我使用的:
|
||||
|
||||
* `Section` 的值对于我们来说大多没有意义,但需要存在。它对给引导式 UI 安装程序提供信息是有意义的,但对于这个包来说,没有意义。
|
||||
* `Priority` 对像这样的第三方包的正确值是 `extra`。
|
||||
* 强烈建议在 `Maintainer` 字段中填写正确的联系人信息。但不一定非得是你的个人电子邮件,如果包由团队维护,并且你希望将问题发送到团队的邮件别名,例如 `Infrastructure Team <infra-team-list@company.example.com>`。
|
||||
* `Build-Depends` 字段标识你需要 `debhelper`、`python` 和 `dh-virtualenv` 来构建包:包构建过程中将确保这些依赖项在包构建时已安装。
|
||||
* `Standards-Version` 字段主要给人看。它表明你遵循的指南。本指南基于 `dh-virtualenv` 的官方文档,它是基于 Debian 的 3.9.5 指南。最好一直将源码包和二进制包命名相同。
|
||||
* `Architecture` 字段应为 `Any`,因为除非虚拟环境可能包含一些特定于体系结构的文件。否则,最好选择该字段为 `any`。
|
||||
* 保持 `Pre-Depends` 列表不变:它是一种非常严格的依赖关系形式,你很少会需要比这里建议的最小依赖更多的依赖项。依赖项通常由构建系统准确计算,因此没有理由手动指定它们。
|
||||
* 如果你的包主要用于内部,那么 `Description` 字段可能只需要最少的信息或者指向公司 wiki 的链接,不然更多的信息会更有用。
|
||||
|
||||
然后创建 `debian/compat` 文件,它[主要出于历史目的而存在][10]:
|
||||
|
||||
```
|
||||
$ echo "9" > debian/compat
|
||||
```
|
||||
|
||||
接下来,创建更新日志以告知包用户自上次发布以来发生了什么变化。最简单的方法是使用 `dch --create` 创建模板,然后填写值。
|
||||
|
||||
填写后,它看起来像:
|
||||
|
||||
```
|
||||
myhttp (2.0.0-1) stable; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- Jan Doe <jandoe@example.org> Fri, 27 Mar 2020 01:09:22 +0000
|
||||
```
|
||||
|
||||
现在你需要告诉工具安装 HTTPie,但是哪个版本?
|
||||
|
||||
创建一个宽松版本的 `requirements.in` 文件:
|
||||
|
||||
```
|
||||
httpie
|
||||
```
|
||||
|
||||
通常,宽松的需求文件将仅包含项目的直接依赖项,并在需要时指定最低版本。不一定总是需要指定最低版本:这些工具通常偏向于将依赖关系转化为“可能的最新版本”。如果你的 Debian 包与一个内部 Python 包相对应,这是内部应用中的一种常见情况,那么宽松的需求文件看起来将很相似:仅包含包名的一行。
|
||||
|
||||
然后使用 `pip-compile`(可通过安装 PyPI 包 `pip-tools` 获得):
|
||||
|
||||
```
|
||||
$ pip-compile requirements.in > requirements.txt
|
||||
```
|
||||
|
||||
这会生成一个严格的依赖文件,名为 `requirements.txt`:
|
||||
|
||||
```
|
||||
#
|
||||
# This file is autogenerated by pip-compile
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile requirements.in
|
||||
#
|
||||
certifi==2019.11.28 # via requests
|
||||
chardet==3.0.4 # via requests
|
||||
httpie==2.0.0 # via -r requirements.in
|
||||
idna==2.9 # via requests
|
||||
pygments==2.6.1 # via httpie
|
||||
requests==2.23.0 # via httpie
|
||||
urllib3==1.25.8 # via requests
|
||||
```
|
||||
|
||||
最后,写一个 `debian/rules` 文件来创建包。因为 `dh_virtualenv` 会处理所有困难的事,因此规则文件很简单:
|
||||
|
||||
```
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@ --with python-virtualenv --python /usr/bin/python3.7
|
||||
```
|
||||
|
||||
确保指定 Python 解释器。默认它会使用 `/usr/bin/python`,这是 Python2,但是你应该使用一个[受支持的 Python 版本][11]。
|
||||
|
||||
完成了,接下来就是构建包:
|
||||
|
||||
```
|
||||
$ debuild -b -us -uc
|
||||
```
|
||||
|
||||
这会在父目录生成一个类似 `myhttp_2.0.0-1_amd64.deb` 的文件。该文件可在任何兼容的系统上安装。
|
||||
|
||||
通常,最好在同一平台上构建用于特定平台(例如 Debian 10.0)的 Debian 包。
|
||||
|
||||
你可以将此 Debian 包保存在软件仓库中,并使用例如 [Ansible][12] 的工具将其安装在所有相关系统上。
|
||||
|
||||
### 总结
|
||||
|
||||
给基于 Debian 的系统的打包应用是一个有着多个步骤的过程。使用 `dh_virtualenv` 将使过程变得简单明了。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/package-python-applications-linux
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life-python.jpg?itok=F2PYP2wT (Python in a tree)
|
||||
[2]: https://opensource.com/article/19/12/pantheon-linux-desktop
|
||||
[3]: https://dh-virtualenv.readthedocs.io/en/latest/
|
||||
[4]: https://opensource.com/article/19/8/getting-started-httpie
|
||||
[5]: https://dh-virtualenv.readthedocs.io/en/1.1/tutorial.html
|
||||
[6]: http://man.he.net/man1/devscripts
|
||||
[7]: mailto:jandoe@example.org
|
||||
[8]: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#control
|
||||
[9]: mailto:infra-team-list@company.example.com
|
||||
[10]: https://www.debian.org/doc/manuals/maint-guide/dother.en.html#compat
|
||||
[11]: https://opensource.com/article/19/11/end-of-life-python-2
|
||||
[12]: https://opensource.com/resources/what-ansible
|
@ -1,69 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (messon007)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (What is the internet backbone and how it works)
|
||||
[#]: via: (https://www.networkworld.com/article/3532318/what-is-the-internet-backbone-and-how-it-works.html)
|
||||
[#]: author: (Tim Greene https://www.networkworld.com/author/Tim-Greene/)
|
||||
|
||||
互联网的骨干网是什么以及它是怎样工作的
|
||||
======
|
||||
一级互联网服务提供商(ISP)将其高速光纤网络连接在一起,形成互联网的骨干网,实现在不同地理区域之间高效地传输流量。[Gerd Altmann][1] [(CC0)][2]
|
||||
|
||||
互联网会产生大量的计算机到计算机的流量,要确保所有流量都可以在世界上任何地方之间传输,就需要大量汇聚的高速网络,这些网络统称为互联网骨干网,但是它是如何工作的呢?
|
||||
|
||||
### 互联网的骨干网是什么?
|
||||
像任何其他网络一样,Internet由接入链路组成,这些接入链路将流量传输到高带宽路由器,路由器又将流量从源地址通过最佳可用路径传输到目的地址。其核心是由相互连接的各个高速光纤网络而构成的Internet骨干网。
|
||||
|
||||
各个独立的核心网络由一级互联网服务提供商(ISP),大型运营商所拥有。他们的网络连接在一起。这些提供商包括AT&T,CenturyLink,Cogent Communications,德国电信,全球电信和技术(GTT),NTT Communications,Sprint,Tata Communications,意大利Sparkle电信,Telia Carrier和Verizon。
|
||||
|
||||
[[Get regularly scheduled insights by signing up for Network World newsletters.]][3]
|
||||
|
||||
通过将这些长途网连接在一起,一级ISP们创建了一个他们可以访问整个路由表的单一的全球性网络,因此他们可以通过逐步层次化地增加本地ISP网络来有效地将流量传输到其目的地。
|
||||
|
||||
除了物理连接之外,这些骨干提供商还通过一致的网络协议TCP/IP融合在一起。它们实际上是两个协议,传输控制协议和IP协议,它们在计算机之间建立连接,以确保连接可靠并将消息格式化为数据包。
|
||||
|
||||
### 互联网交接点(IXP)将骨干连接在一起
|
||||
|
||||
骨干ISP在对等点,中立位置通过高速交换机和路由器连接其网络。这些通常由第三方(有时是非营利组织)提供,以促进骨干网的统一。
|
||||
|
||||
有1级ISP的参与有助于为IXP提供资金,但是在称为无结算的对等关系中,彼此之间不收取从其他1级ISP传输流量的费用。此类协议消除了可能导致互联网性能下降的潜在财务纠纷。
|
||||
|
||||
[][4]
|
||||
|
||||
### 骨干网有多快?
|
||||
互联网骨干网由最快的路由器组成,可以提供100Gbps的线路速度。这些路由器由包括Cisco,Extreme,Huawei,Juniper和Nokia在内的供应商制造,使用边界网关协议(BGP)在彼此之间路由流量。
|
||||
|
||||
### 流量是如何进入骨干网的
|
||||
|
||||
1级ISP之下是小的2级和3级ISP。
|
||||
|
||||
3级(ISP)提供商为企业和消费者提供了Internet接入服务。这些提供商自己没有接入互联网骨干网,因此,他们自己无法将其客户连接到数十亿台互联网上的计算机。
|
||||
|
||||
购买一级(ISP)提供商的接入权非常昂贵。通常3级ISP与具有自己网络的2级(区域)ISP签订合同,利用2级ISP的网络将流量传输到有限的地理区域,但不能传输到所有Internet上的设备。
|
||||
|
||||
为此,2级ISP与1级ISP签约以访问全球骨干网,并以这种方式使客户可以访问整个Internet。
|
||||
|
||||
这种方式使得来自世界一侧的计算机的流量能够连接到另一侧的计算机。流量从源计算机流向3级ISP,再路由到2级ISP,再路由到1级骨干网提供商,再路由到正确的2级ISP,最后路由到提供该数据的3级接入提供商连接的目标计算机。
|
||||
|
||||
加入[Facebook][5]和[LinkedIn][6]上的Network World社区,就可以评论最前沿的话题。
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.networkworld.com/article/3532318/what-is-the-internet-backbone-and-how-it-works.html
|
||||
|
||||
作者:[Tim Greene][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[messon007](https://github.com/messon007)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.networkworld.com/author/Tim-Greene/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://pixabay.com/en/social-media-digitization-faces-3271592/
|
||||
[2]: https://creativecommons.org/publicdomain/zero/1.0/
|
||||
[3]: https://www.networkworld.com/newsletters/signup.html
|
||||
[4]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE21620&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||
[5]: https://www.facebook.com/NetworkWorld/
|
||||
[6]: https://www.linkedin.com/company/network-world
|
@ -1,177 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to package Python applications for Linux)
|
||||
[#]: via: (https://opensource.com/article/20/4/package-python-applications-linux)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
|
||||
如何为 Linux 打包 Python 应用
|
||||
======
|
||||
了解如何使用 dh_virtualenv 来让你的 Python 应用可作为 .deb 包安装。
|
||||
![Python in a tree][1]
|
||||
|
||||
一种让 Python 应用可在基于 Debian 的操作系统(例如 Debian 或 [Elementary OS][2])上安装的方法是使用 [dh_virtualenv][3] 工具。它会构建一个封装了 Python 虚拟环境的 **.deb** 包,并在安装时进行部署。
|
||||
|
||||
在本文中,我将以构建包含 [HTTPie][4] 工具的包为例,说明如何无需激活虚拟环境即可从命令行测试 HTTP API。
|
||||
|
||||
### 使用 dh_virtualenv 打包
|
||||
|
||||
首先,你需要安装 dh_virtualenv 所需的工具。dh_virtualenv 的[文档][5]提供了所有安装选项。在基于 Debian 的系统上,我输入:
|
||||
|
||||
```
|
||||
`apt-get install dh-virtualenv devscripts`
|
||||
```
|
||||
|
||||
尽管不需要 [devscripts][6] 包,但它将简化后续操作。
|
||||
|
||||
现在,创建一个目录来保存源码。由于这是 HTTPie 的本地非官方打包,因此我将其称为 **myhttp**。 接下来,让我们在 **myhttp** 内创建一些文件以向 Debian 构建系统提供元数据。
|
||||
|
||||
首先,创建 **debian/control** 文件:
|
||||
|
||||
|
||||
```
|
||||
Source: myhttp
|
||||
Section: python
|
||||
Priority: extra
|
||||
Maintainer: Jan Doe <[jandoe@example.org][7]>
|
||||
Build-Depends: debhelper (>= 9), python3.7, dh-virtualenv (>= 0.8)
|
||||
Standards-Version: 3.9.5
|
||||
|
||||
Package: myhttp
|
||||
Architecture: any
|
||||
Pre-Depends: dpkg (>= 1.16.1), python3.7, ${misc:Pre-Depends}
|
||||
Depends: ${misc:Depends}
|
||||
Description: http client
|
||||
Useful for doing stuff
|
||||
```
|
||||
|
||||
那么这些是什么信息呢? [Debian 文档][8]指出:
|
||||
|
||||
>“第 1–7 行是源码包的控制信息。第 9–13 行是二进制包的控制信息。”
|
||||
|
||||
以下是我使用的:
|
||||
|
||||
* **section** 的值对于我们来说大多没有意义,但需要存在。它对提供 UI 安装程序信息是有意义的,这与此包无关。
|
||||
* 额外的 **Priority** 值是像这样的第三方包的正确优先级。
|
||||
* 强烈建议在 **Maintainer** 字段中填写正确的联系人信息。但是,如果包由团队维护,并且你希望将问题发送到团队的邮件别名,例如 “Infrastructure Team <[infra-team-list@company.example.com][9]>”,那这不一定是你的个人邮箱。
|
||||
* **build-depends** 字段标识你需要 debhelper、python 和 dh-virtualenv 来构建包:包生成过程将确保这些依赖项在包构建时安装。
|
||||
* **standards version** 字段主要给人看。它表明你遵循的指南。本指南基于 dh-virtualenv 的官方文档,它是基于 Debian 的 3.9.5 指南。最好一直将源码包和二进制包命名相同。
|
||||
* **Architecture** 字段应为 **Any**,因为除非虚拟环境可能包含一些特定于体系结构的文件。否则,最好选择该字段为 **any**。
|
||||
* 保持 Pre-Depends 列表为当前的样式:预依赖是一种非常严格的依赖关系形式,你很少会需要比建议的最小依赖更多的依赖项。依赖项通常由构建系统准确计算,因此没有理由手动指定它们。
|
||||
* 如果你的包主要用于内部,那么 **Description** 字段只需要最少的信息或者指向公司 wiki 的链接,不然详细信息更有用。
|
||||
|
||||
|
||||
|
||||
然后创建 **debian/compat** 文件,它[主要出于历史目的而存在][10]:
|
||||
|
||||
|
||||
```
|
||||
`$ echo "9" > debian/compat`
|
||||
```
|
||||
|
||||
接下来,创建更新日志以告知包用户自上一发行版以来发生了什么变化。最简单的方法是使用 **dch --create** 创建模板,然后填写值。
|
||||
|
||||
填写后,它看起来像:
|
||||
|
||||
|
||||
```
|
||||
myhttp (2.0.0-1) stable; urgency=medium
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- Jan Doe <[jandoe@example.org][7]> Fri, 27 Mar 2020 01:09:22 +0000
|
||||
```
|
||||
|
||||
现在你需要告诉工具安装 HTTPie,但是哪个版本?
|
||||
|
||||
创建一个宽松版本的 **requirements.in** 文件:
|
||||
|
||||
|
||||
```
|
||||
`httpie`
|
||||
```
|
||||
|
||||
通常,宽松的需求文件将仅包含项目的直接依赖项,并在需要时指定最低版本。 不一定总是需要指定最低版本:这些工具通常偏向于将依赖关系转化为“可能的最新版本”。如果你的 Debian 包与一个内部 Python 包相对应,这是内部应用中的一种常见情况,那么宽松的需求文件看起来将很相似:仅包含包名的一行。
|
||||
|
||||
然后使用 **pip-compile**(可通过安装 PyPI 包 **pip-tools** 获得):
|
||||
|
||||
|
||||
```
|
||||
`$ pip-compile requirements.in > requirements.txt`
|
||||
```
|
||||
|
||||
这会生成一个严格的依赖文件,名为 **requirements.txt**:
|
||||
|
||||
|
||||
```
|
||||
#
|
||||
# This file is autogenerated by pip-compile
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile requirements.in
|
||||
#
|
||||
certifi==2019.11.28 # via requests
|
||||
chardet==3.0.4 # via requests
|
||||
httpie==2.0.0 # via -r requirements.in
|
||||
idna==2.9 # via requests
|
||||
pygments==2.6.1 # via httpie
|
||||
requests==2.23.0 # via httpie
|
||||
urllib3==1.25.8 # via requests
|
||||
```
|
||||
|
||||
最后,写一个 **debian/rules** 文件来创建包。因为 dh_virtualenv 会处理所有困难的事,因此规则文件很简单:
|
||||
|
||||
|
||||
```
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@ --with python-virtualenv --python /usr/bin/python3.7
|
||||
```
|
||||
|
||||
确保指定 Python 解释器。默认它会使用 **/usr/bin/python**,这是 Python2,但是你应该使用一个[受支持的 Python 版本][11]
|
||||
|
||||
完成了,接下来就是构建包:
|
||||
|
||||
|
||||
```
|
||||
`$ debuild -b -us -uc`
|
||||
```
|
||||
|
||||
这会在父目录生成一个类似 **myhttp_2.0.0-1_amd64.deb** 的文件。该文件可在任何兼容的系统上安装。
|
||||
|
||||
通常,最好在同一平台上构建用于特定平台(例如 Debian 10.0)的 Debian 包。
|
||||
|
||||
你可以将此 Debian 包保存在存仓库中,并使用例如 [Ansible][12] 的工具将其安装在所有相关系统上。
|
||||
|
||||
### 总结
|
||||
|
||||
给基于 Debian 的系统的打包应用是一个有多个步骤的过程。使用 dh_virtualenv 将使过程变得简单。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/4/package-python-applications-linux
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life-python.jpg?itok=F2PYP2wT (Python in a tree)
|
||||
[2]: https://opensource.com/article/19/12/pantheon-linux-desktop
|
||||
[3]: https://dh-virtualenv.readthedocs.io/en/latest/
|
||||
[4]: https://opensource.com/article/19/8/getting-started-httpie
|
||||
[5]: https://dh-virtualenv.readthedocs.io/en/1.1/tutorial.html
|
||||
[6]: http://man.he.net/man1/devscripts
|
||||
[7]: mailto:jandoe@example.org
|
||||
[8]: https://www.debian.org/doc/manuals/maint-guide/dreq.en.html#control
|
||||
[9]: mailto:infra-team-list@company.example.com
|
||||
[10]: https://www.debian.org/doc/manuals/maint-guide/dother.en.html#compat
|
||||
[11]: https://opensource.com/article/19/11/end-of-life-python-2
|
||||
[12]: https://opensource.com/resources/what-ansible
|
Loading…
Reference in New Issue
Block a user