Mark McLoughlin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Rebuilding the Wheel - Becoming a Build Job The [rebuilding the wheel](https://github.com/markmc/rebuilding-the-wheel) prototype has been hugely instructive. We can now boootstrap a self-contained package index containing binary distributions (wheels) for the entire dependency chains for complex packages like PyTorch and LangChain, all built from source. Where to from here? Assume we are hosting a package index containing these wheels, and we wish for new versions of existing packages to automatically be built and added to the index. Human input would usually only be required when new packages are to be added to the index - either because we wish to add a new toplevel package, or because a new version of an existing package has added this new package as a dependency. The purpose of this document is to design the steps of a build job that would be triggered under a number of circumstances: 1. The upload of a new version of an existing package to PyPI 2. The addition of a new PyPI package has been approved by a human reviewer 3. The rebuild of an existing package version 4. The change of any per-package metadata, patches, etc. that are used by the build process ## Download the source The default case is to download an sdist from PyPI given the package name and the new version (or latest version, for new packages) We might support alternative source locations for some packages (e.g. a github repo), but even in those cases we would ultimately create an archive (e.g. from a git clone) so that all projects have the same source distribution format. We would validate the downloaded source, starting with its checksum, but over time this could include security scanning or other automated analysis The archive would be stored for the next step, or subsequent rebuilds, or for auditing purposes. In the case of rebuilds, this step would be skipped. Relevant code: [sources.download_source()](https://github.com/markmc/rebuilding-the-wheel/blob/59fc62d7730ffbc32d6f453b6fe16d552eb6f776/mirror_builder/sources.py#L14) - but note that no "resolution" is required except in the case "latest version for new packages" case. ## Prepare build environment Create a fresh build environment, where we ensure reproducibility of what is available during the build. We'd use containers for this, but the philosophy would borrow from e.g. [mock](https://rpm-software-management.github.io/mock/). Some build requirements will be installed using RPMs - e.g. [cmake, auto*, gcc, rust, etc.](https://github.com/markmc/rebuilding-the-wheel/blob/main/Containerfile) - the list of these build requirements is not available from any upstream metadata source, so this will need to be stored somewhere. All other build requirements will be wheels - let's assume for now we know what these requirements are, and we install them in advance from our package index into a virtual environment. ### Determining (wheel-based) build requirements In the prepare build environment step, we deferred the question of how to know which wheels to install into the build environment. One option for how to handle this is a build requirements analysis step, where we use packages from our package index to recursively analyze the build requirements of the package ([relevant code](https://github.com/markmc/rebuilding-the-wheel/blob/59fc62d7730ffbc32d6f453b6fe16d552eb6f776/mirror_builder/sdist.py#L9)) and then store that list for the subsequent step. In this case, if a new package was detected, this would get queued up as a new package request for review by a human, and the build would fail. However, there is a simpler option - we could simply allow the build process to automatically install the build dependencies it requires from our package index, and fail if it doesn't exist. PyTorch [lists cmake as a build dependency](https://github.com/pytorch/pytorch/blob/836a86064cf27de91479dddd1d834dd57bb0bd07/pyproject.toml#L9) such that it gets installed from [a package on PyPI](https://pypi.org/project/cmake/) But it seems pretty straightforward that we would want to use [the system package](https://packages.fedoraproject.org/pkgs/cmake/cmake/) ## Prepare source Unpack the source into the (not yet-running) build environment and apply any patches ## Build wheel Launch the build environment - presumably. However, ensure that network access is blocked in order to ensure everything required by the build is coming from the build environment. If all required wheels are installed, there is no need to provide access to our package index. Build the package with `pip wheel` by default, as per [build_wheel()](https://github.com/markmc/rebuilding-the-wheel/blob/59fc62d7730ffbc32d6f453b6fe16d552eb6f776/mirror_builder/wheels.py#L20). Store the produced wheel. ## Validate install-time dependencies Using the newly built wheel, analyze its regular dependencies. If a new package is detected, this would get queued up as a new package request for review by a human, and the build would fail. Now test the wheel and all its dependencies can be installed using only our package index. Potentially perform other smoke-testing. ## Update index Place the newly built wheel into the index, and re-generate the index listing. We would likely have a separate index storing source archives for reference. A wheels-only index nobody using this index will unwittingly be building from source - on a different architecture, python version, etc. The source could be stored on a regular web server with a simple index. ## Misc/TODO Thoughts/comments/discussion points to incorporate above. * Automated update tracking - for packages that we have accepted into our system's allow-list, we would monitor PyPI for new versions and automatically kick off build jobs for the new version. * Build job mode - a build job for package `foo-1.2.3`, should only build `foo-1.2.3.whl`. Or conversely, you should be able to query for the build job that built `foo-1.2.3.whl` and look through the logs etc. * Bootstrap mode - analyze an entire dependency tree and kick off build jobs bottom-up all the way to the toplevel package. * Ideally, we should be able to bump a part of the version number when we rebuild a particular version of a package - e.g. `requests-2.28.2-5` is the fifth rebuild of 2.8.2 release. Are [post-releases](https://packaging.python.org/en/latest/specifications/version-specifiers/#post-releases) the answer? Or [local versions](https://packaging.python.org/en/latest/specifications/version-specifiers/#local-version-identifiers)? * There may not be a consistent way to inject a special version number into the metadata when building, so we may need multiple approaches depending on the build tool. * Unlike in Fedora, users expect multiple package versions in a Python Package Index - e.g. `torch==2.1.1`, `torch==2.2.*` - so part of our bootstrapping should involve building versions other than the latest * The ability to audit/inspect the build for a given wheel is of value - one of our build artifacts should be the output of `pip freeze` in the build environment * Potential upstream improvements for Python packaging * Some way to differentiate copies of the same distribution for optimized builds using info other than just CPU architecture (GPUs, etc.). This could be an extension to the architecture field (combining CPU and GPU arch, for example), or some other metadata that can be queried via a marker that the installer can determine. Maybe there are other options? * The prototype builds wheels for multiple versions of Python, but what will make sense in practice? Should an index for a given Fedora version be expected to work with the default version of Python in that version of Python? Or all versions of Python available in that version of Fedora? If we did decide to support multiple Python versions for a given Fedora version, should we have a separate set of wheels for each version? * [dhellmann] Different versions of Python do typically require different binary wheels for the same dist because the ABI of Python can change and the builds have to take that into account. The python version is included in the wheel filename, and pip is smart enough to identify the right wheel and use it, so we should be able to serve the same content out of a single wheel repo. * [dhellmann] If we start doing optimized builds for reasons other than the Python version, CPU arch, OS, etc. -- such as to incoroporate the GPU architecture -- then we will have to do something different because the python toolchain does not understand that sort of binary difference. (See the previous point about multiple versions of packages.)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully