|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +# Checks if datafusion-examples uses `datafusion-...` subcrates unnecessarily, as they are already |
| 20 | +# exported by the `datafusion` crate. |
| 21 | + |
| 22 | +import tomllib |
| 23 | +import sys |
| 24 | + |
| 25 | +allowed_datafusion_crates = { |
| 26 | + "datafusion", |
| 27 | + "datafusion-proto", |
| 28 | + "datafusion-substrait", |
| 29 | +} |
| 30 | + |
| 31 | +crates = set() |
| 32 | +with open("datafusion-examples/Cargo.toml", "rb") as f: |
| 33 | + cargo = tomllib.load(f) |
| 34 | + for section in ("dependencies", "dev-dependencies", "build-dependencies"): |
| 35 | + crates.update( |
| 36 | + value.get("package", name) if isinstance(value, dict) else name |
| 37 | + for name, value in cargo.get(section, {}).items() |
| 38 | + ) |
| 39 | + |
| 40 | +crates = [ |
| 41 | + crate for crate in crates if "datafusion" in crate and crate not in allowed_datafusion_crates |
| 42 | +] |
| 43 | + |
| 44 | +if len(crates) > 0: |
| 45 | + print( |
| 46 | + "datafusion-examples should only use the main datafusion crate and not its subcrates.", |
| 47 | + file=sys.stderr, |
| 48 | + ) |
| 49 | + print( |
| 50 | + f"Please remove the following crates and use `datafusion::...` instead: {crates}.", |
| 51 | + file=sys.stderr, |
| 52 | + ) |
| 53 | + |
| 54 | + sys.exit(1) |
0 commit comments