You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.8 KiB

  1. #! /usr/bin/env python
  2. # Copyright 2022 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. from pathlib import Path
  17. from typing import Dict, List
  18. import tomli
  19. def main() -> None:
  20. lockfile_path = Path(__file__).parent.parent.joinpath("poetry.lock")
  21. with open(lockfile_path, "rb") as lockfile:
  22. lockfile_content = tomli.load(lockfile)
  23. # Poetry 1.3+ lockfile format:
  24. # There's a `files` inline table in each [[package]]
  25. packages_to_assets: Dict[str, List[Dict[str, str]]] = {
  26. package["name"]: package["files"] for package in lockfile_content["package"]
  27. }
  28. success = True
  29. for package_name, assets in packages_to_assets.items():
  30. has_sdist = any(asset["file"].endswith(".tar.gz") for asset in assets)
  31. if not has_sdist:
  32. success = False
  33. print(
  34. f"Locked package {package_name!r} does not have a source distribution!",
  35. file=sys.stderr,
  36. )
  37. if not success:
  38. print(
  39. "\nThere were some problems with the Poetry lockfile (poetry.lock).",
  40. file=sys.stderr,
  41. )
  42. sys.exit(1)
  43. print(
  44. f"Poetry lockfile OK. {len(packages_to_assets)} locked packages checked.",
  45. file=sys.stderr,
  46. )
  47. if __name__ == "__main__":
  48. main()