创建可重现轮子的工具
项目描述
asaman: Amra Saman (আমরা সমান)
这是一个为您的Python项目或所有依赖项构建可重现轮子的工具。这意味着如果您使用相同的操作系统版本和类似级别的系统依赖项,您将始终得到相同的轮子。这使我们能够更好地保护免受侧信道攻击。任何轮子的用户都可以通过验证构建来验证他们是否使用了从确切源构建的正确构建。
为什么我们需要可重现的轮子?
一些不同的积极点
- 如果我们从已知源构建轮子(例如,通过requirements文件中的固定散列),我们还可以验证我们是否正在使用从它们构建的正确轮子。
- 任何用户/开发者都可以从固定的源重新构建轮子,并应该得到相同的轮子作为输出。因此,如果构建过程中有任何东西(例如在CI中)或轮子实际上是从不同的源构建的,自动化工具可以识别这种差异。
如何安装?
python3 -m pip install asaman
如何构建可重现的轮子?
asaman --help
Usage: asaman [OPTIONS]
  Tool to build reproducible wheels.
Options:
  -s, --source FILE          A single source tarball or zip file.
  -d, --directory DIRECTORY  A directory containing all source tarballs and
                             zips.
  -o, --output DIRECTORY     The output directory to store all wheel files.
                             Default: ./wheels
  -r, --requirement FILE     Path to the requirement.txt file which contains
                             all packages to build along with hashes.
  --sde TEXT                 Custom SOURCE_DATE_EPOCH value.
  --no-hash                  DO NOT USE UNLESS VERY SURE: In case we skip hash
                             checking for download.  [default: False]
  --keep-sources             Copy over the sources to output directory
                             [default: False]
  --with-index TEXT          In case you want to install build time
                             dependencies from an index, pass the URL.
                             [default: ]
  --trusted-host TEXT        Pass --trusted-host VALUE to pip, helps in local
                             indexes over HTTP. Pass the correct hostname.
                             [default: ]
  --skip-build-deps          While downloading the sources, skip downloading
                             the build dependencies as source  [default: True]
  --help                     Show this message and exit.
为给定的源tarball构建可重现的轮子
asaman -s dist/yourpackage_4.2.0.tar.gz
默认情况下,新鲜构建的轮子将存储在./wheels/目录中。您可以使用-o/--output指定不同的目录。
为目录中的所有源构建可重现的轮子
asaman -d path/to/sources/
或者,您可以指向包含所有依赖项及其散列的要求文件
asaman -r requirements.txt
如何从可重现的轮子生成带散列的要求文件?
asaman-generate requirements.txt
asaman-generate命令将帮助您创建一个全新的verified-requirements.txt,其中包含可重现轮子的散列。您可以通过-o/--output选项传递自定义文件名。
asaman-generate --help
Usage: asaman-generate [OPTIONS] REQUIREMENT
  Tool to build verified requirements file from reproducible wheels.
Options:
  -o, --output FILE       The output file. Default: verified-{requirement}.txt
  -w, --wheels DIRECTORY  The directory with reproducible wheels.
  -s, --skip TEXT         The packages we don't want in our final requirement
                          file.
  --help                  Show this message and exit.
如何从PyPI或您个人的索引生成带散列的要求文件?
使用pip-tools项目。
pip-compile --generate-hashes --allow-unsafe --output-file=requirements.txt requirements.in
请确保包含所有依赖项的构建依赖项。如果您不这样做,pip将从PyPI下载构建依赖项并将其安装到构建环境中。
在从需求文件构建时,为了帮助识别构建依赖项,在通过pip下载和提取每个源tarball的过程中,您可以注意任何具有构建时依赖项的依赖项。否则,您可以手动查看构建时依赖项。
例如,在以下文本中,您可以找到一些具有构建时依赖项的软件包。查看带有获取构建轮的依赖项的行。
Collecting build==0.7.0
  Using cached build-0.7.0.tar.gz (15 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting click==8.0.1
  Using cached click-8.0.1.tar.gz (327 kB)
Collecting packaging==21.0
  Using cached packaging-21.0.tar.gz (83 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting pep517==0.11.0
  Using cached pep517-0.11.0.tar.gz (25 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
初始化构建环境
对于任何生产用途,您还应该初始化构建环境,并创建初始虚拟环境,以便在该环境中仅构建所有依赖项。您可以将轮存存储在您想要的位置,例如(S3或git-lfs),并在下次创建环境时从那里开始。
在以下命令中,我们将为这样的初始化环境创建一组轮存。我们将从列出bootstrap.in中的构建需求开始,其内容如下
amrasaman >=0.1.0
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pip-tools # This is being downloaded directly from PyPI.
pip-compile --generate-hashes --allow-unsafe --output-file=bootstrap.txt bootstrap.in
asaman -r bootstrap.txt
这将在./wheels目录中创建所有轮存。
下次我们可以从./wheels目录中安装轮存。但首先我们将创建一个新的需求文件,其中仅包含可重复轮存中的哈希,输出文件名将为verified-bootstrap.txt。
asaman-generate bootstrap.txt
现在我们可以使用此需求文件来创建环境。
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --no-index --find-links ./wheels --require-hashes --only-binary :all: -r verified-bootstrap.txt 
名称的含义
在孟加拉语中,它意味着“我们相同”
开发者文档
阅读黑客指南。
项目详情
下载文件
下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
构建分布
asaman-0.2.1.tar.gz的哈希
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 2746e48ed5f99a3fccf1b4221b47a7934ca67d4a71e8c8024128034298fffb2a | |
| MD5 | b93e874921a611e53ce28432079f7c5f | |
| BLAKE2b-256 | 53839757885f5151395f31a33cf32887bea42242b5f90afdbcfb59b857ac5dfb | 
asaman-0.2.1-py3-none-any.whl的哈希
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | b1318178cd5b7a21a80bfc8d078ad6be8706acbfa482004f754225b14d3cefb3 | |
| MD5 | 960de38ece4403614391750eaf48b5d9 | |
| BLAKE2b-256 | 2c340018c97091f76699a8f66d56a8f260ac58145f63ae13e36595f0cf805a0a |