Skip to content

Commit 2193be7

Browse files
authored
Merge pull request #420 from dhellmann/linter-command
add linter command
2 parents a4380c2 + da5596f commit 2193be7

File tree

7 files changed

+86
-20
lines changed

7 files changed

+86
-20
lines changed

e2e/common.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ source .tox/e2e/bin/activate
2929
# Set a variable to constrain packages used in the tests
3030
export FROMAGER_CONSTRAINTS_FILE="${SCRIPTDIR}/constraints.txt"
3131

32+
OS=$(uname)
33+
if [ "$OS" = "Darwin" ]; then
34+
NETWORK_ISOLATION=""
35+
# The tag comes back as something like "macosx-10.9-universal2" but the
36+
# filename contains "macosx_10_9_universal2".
37+
WHEEL_PLATFORM_TAG=$(python3 -c 'import sysconfig; print(sysconfig.get_platform().replace("-", "_").replace(".", "_"))')
38+
HAS_ELFDEP="0"
39+
else
40+
NETWORK_ISOLATION="--network-isolation"
41+
WHEEL_PLATFORM_TAG="linux_x86_64"
42+
HAS_ELFDEP="1"
43+
fi
44+
export NETWORK_ISOLATION
45+
export WHEEL_PLATFORM_TAG
46+
export HAS_ELFDEP
47+
3248
# Local web server management
3349
HTTP_SERVER_PID=""
3450
on_exit() {

e2e/test_elfdeps.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ source "$SCRIPTDIR/common.sh"
1111
DIST="MarkupSafe"
1212
VERSION="2.1.5"
1313

14-
OS=$(uname)
15-
if [ "$OS" = "Darwin" ]; then
16-
NETWORK_ISOLATION=""
17-
WHEEL_PLATFORM_TAG="macosx_10_9_universal2"
18-
HAS_ELFDEP="0"
19-
else
20-
NETWORK_ISOLATION="--network-isolation"
21-
WHEEL_PLATFORM_TAG="linux_x86_64"
22-
HAS_ELFDEP="1"
23-
fi
24-
2514
# Bootstrap the test project
2615
fromager \
2716
$NETWORK_ISOLATION \

e2e/test_rust_vendor.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ source "$SCRIPTDIR/common.sh"
1212
DIST="maturin"
1313
VERSION="1.6.0"
1414

15-
OS=$(uname)
16-
if [ "$OS" = "Darwin" ]; then
17-
NETWORK_ISOLATION=""
18-
WHEEL_PLATFORM_TAG="macosx_10_9_universal2"
19-
else
20-
NETWORK_ISOLATION="--network-isolation"
21-
WHEEL_PLATFORM_TAG="linux_x86_64"
22-
fi
23-
2415
# Bootstrap the test project
2516
fromager \
2617
$NETWORK_ISOLATION \

src/fromager/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def main(
210210
variant=variant,
211211
network_isolation=network_isolation,
212212
max_jobs=jobs,
213+
settings_dir=settings_dir,
213214
)
214215
wkctx.setup()
215216
ctx.obj = wkctx

src/fromager/commands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
canonicalize,
66
download_sequence,
77
graph,
8+
lint,
89
list_overrides,
910
migrate_config,
1011
server,
@@ -17,6 +18,7 @@
1718
build.build_sequence,
1819
build_order.build_order,
1920
graph.graph,
21+
lint.lint,
2022
list_overrides.list_overrides,
2123
migrate_config.migrate_config,
2224
step.step,

src/fromager/commands/lint.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import logging
2+
3+
import click
4+
5+
from .. import context, overrides
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
@click.command()
11+
@click.pass_obj
12+
def lint(
13+
wkctx: context.WorkContext,
14+
) -> None:
15+
"""Review existing settings and overrides for potential configuration errors."""
16+
errors = 0
17+
18+
logger.info(f"Checking patches in {wkctx.settings.patches_dir}...")
19+
for entry in wkctx.settings.patches_dir.glob("*"):
20+
logger.debug(entry)
21+
if "-" in entry.name:
22+
actual_package_name, _, version_str = entry.name.rpartition("-")
23+
expected_package_name = overrides.pkgname_to_override_module(
24+
actual_package_name
25+
)
26+
if actual_package_name != expected_package_name:
27+
errors += 1
28+
logger.error(
29+
f"ERROR: Patch directory {entry.name} should be {expected_package_name}-{version_str}"
30+
)
31+
else:
32+
expected_package_name = overrides.pkgname_to_override_module(entry.name)
33+
if actual_package_name != expected_package_name:
34+
errors += 1
35+
logger.error(
36+
f"ERROR: Patch directory {entry.name} should be {expected_package_name}"
37+
)
38+
39+
if wkctx.settings_dir is not None:
40+
logger.info(f"Checking settings files in {wkctx.settings_dir}...")
41+
for entry in wkctx.settings_dir.glob("*"):
42+
logger.debug(entry)
43+
if entry.suffix != ".yaml":
44+
errors += 1
45+
logger.error(
46+
f"ERROR: settings file {entry.name} should use extension '.yaml'"
47+
)
48+
expected_package_name = overrides.pkgname_to_override_module(entry.stem)
49+
if entry.stem != expected_package_name:
50+
errors += 1
51+
logger.error(
52+
f"ERROR: Settings file {entry.name} should be {expected_package_name}.yaml"
53+
)
54+
55+
logger.info("Checking entry points...")
56+
exts = overrides._get_extensions()
57+
for name in exts.names():
58+
logger.debug(name)
59+
expected_name = overrides.pkgname_to_override_module(name)
60+
if name != expected_name:
61+
errors += 1
62+
logger.error(f"ERROR: plugin name {name} should be {expected_name}")
63+
64+
if errors:
65+
raise SystemExit(f"Found {errors} errors")

src/fromager/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(
3737
variant: str = "cpu",
3838
network_isolation: bool = False,
3939
max_jobs: int | None = None,
40+
settings_dir: pathlib.Path | None = None,
4041
):
4142
if active_settings is None:
4243
active_settings = packagesettings.Settings(
@@ -67,6 +68,7 @@ def __init__(
6768
self.cleanup = cleanup
6869
self.variant = variant
6970
self.network_isolation = network_isolation
71+
self.settings_dir = settings_dir
7072

7173
self._build_order_filename = self.work_dir / "build-order.json"
7274
self._constraints_filename = self.work_dir / "constraints.txt"

0 commit comments

Comments
 (0)