This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add check to ensure locked dependencies have source distributions available. #14742
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0aa18a2
Add a script to check the lockfile for dependencies without sdists.
reivilibre 4bb82b4
Add dependency on tomli
reivilibre e1148cc
Add workflow to ensure locked deps have sdists
reivilibre 4644a90
Newsfile
reivilibre 3b2d6e2
Support the other style of lockfile
reivilibre 170abb7
Revert lockfile changes from "Add dependency on tomli"
reivilibre c02c919
Merge branch 'develop' into rei/lockdeps_have_sdists
reivilibre 33bab13
Update the lockfile content hash only (needed to clear poetry caches)
reivilibre 44847bf
Remove write privileges
reivilibre 2e75a31
Only bother with Poetry 1.3+ lockfiles
reivilibre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
on: | ||
push: | ||
branches: ["develop", "release-*"] | ||
paths: | ||
- poetry.lock | ||
pull_request: | ||
paths: | ||
- poetry.lock | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: write | ||
reivilibre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
jobs: | ||
check-sdists: | ||
name: "Check locked dependencies have sdists" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
- run: pip install tomli | ||
- run: ./scripts-dev/check_locked_deps_have_sdists.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add check to ensure locked dependencies have source distributions available. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#! /usr/bin/env python | ||
# Copyright 2022 The Matrix.org Foundation C.I.C. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
from pathlib import Path | ||
from typing import Dict, List | ||
|
||
import tomli | ||
|
||
|
||
def main() -> None: | ||
lockfile_path = Path(__file__).parent.parent.joinpath("poetry.lock") | ||
with open(lockfile_path, "rb") as lockfile: | ||
lockfile_content = tomli.load(lockfile) | ||
|
||
packages_to_assets: Dict[str, List[Dict[str, str]]] | ||
# There seem to be two different formats for storing the list of files per package. | ||
if lockfile_content.get("metadata", {}).get("files") is not None: | ||
# either [metadata.files] | ||
packages_to_assets = lockfile_content["metadata"]["files"] | ||
else: | ||
# or a `files` inline table in each [[package]] | ||
packages_to_assets = { | ||
package["name"]: package["files"] for package in lockfile_content["package"] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to be part of the poetry 1.3 lockfile format, see python-poetry/poetry#6393 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I'm about to require the new lockfile format in #14860 |
||
|
||
success = True | ||
|
||
for package_name, assets in packages_to_assets.items(): | ||
has_sdist = any(asset["file"].endswith(".tar.gz") for asset in assets) | ||
if not has_sdist: | ||
success = False | ||
print( | ||
f"Locked package {package_name!r} does not have a source distribution!", | ||
file=sys.stderr, | ||
) | ||
|
||
if not success: | ||
print( | ||
"\nThere were some problems with the Poetry lockfile (poetry.lock).", | ||
file=sys.stderr, | ||
) | ||
sys.exit(1) | ||
|
||
print( | ||
f"Poetry lockfile OK. {len(packages_to_assets)} locked packages checked.", | ||
file=sys.stderr, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that we only trigger this if needed.
The downside is that it can't be fed into the
tests-done
job to tell github it's safe to merge this PR. But I think we can live with that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's frustrating how the default behaviour isn't just to make sure all the tests pass, but ah well