Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ line-length = 100
# ditx plugins are extensionless Python scripts
extend-include = ["tools/ext/ditx-*"]
target-version = "py310" # Ubuntu 22.04 (Humble, the default); Jazzy has 3.12
extend-exclude = ["build", "domains/*/build", ".sim-robot"]
extend-exclude = ["build", "domains/*/build", ".sim-robot", "**/third_party"] # vendored upstream code

[format]
quote-style = "single" # same as ROS 2 (ament_flake8 / flake8-quotes)
Expand Down
23 changes: 19 additions & 4 deletions tools/check_boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

1. a domain may depend on base packages and ROS/system packages, never on a
package of another domain (talk through topics in contract.yaml instead);
2. every package name starts with its domain name (unique across repos);
2. every package name starts with its domain name (unique across repos),
except vendored upstream code under a `third_party/` directory (drivers without
a rosdep key keep their upstream name), which must still be unique across domains;
3. every domain has <domain>_bringup with launch/bringup.launch.py.

usage: check_boundaries.py WORKSPACE_ROOT DOMAIN...
Expand All @@ -30,20 +32,33 @@ def packages(root):
return out


THIRD_PARTY = 'third_party'


def vendored(path, domain_root):
return THIRD_PARTY in os.path.relpath(path, domain_root).split(os.sep)


def main():
root, domains = sys.argv[1], sys.argv[2:]
owner = {}
per_domain = {}
errors = []
for d in domains:
per_domain[d] = packages(os.path.join(root, 'domains', d))
for p in per_domain[d]:
if p in owner and owner[p] != d:
errors.append(f'package {p} exists in both domains {owner[p]} and {d}')
owner[p] = d
errors = []
for d, pkgs in per_domain.items():
domain_root = os.path.join(root, 'domains', d)
for name, (path, deps) in pkgs.items():
rel = os.path.relpath(path, root)
if not name.startswith(d + '_'):
errors.append(f'{rel}: package {name} must be prefixed with "{d}_"')
if not name.startswith(d + '_') and not vendored(path, domain_root):
errors.append(
f'{rel}: package {name} must be prefixed with "{d}_" '
f'(vendored upstream code goes under {THIRD_PARTY}/)'
)
for dep in sorted(deps):
if owner.get(dep, d) != d:
errors.append(
Expand Down
13 changes: 8 additions & 5 deletions tools/ditx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ def count_files(ws, targets):
extra = ('docker', 'infra', '.github')
for t in [*targets, *extra]:
for dirpath, dirnames, files in os.walk(os.path.join(ws.root, t)):
dirnames[:] = [d for d in dirnames if d != 'build' and not d.startswith('.')]
dirnames[:] = [
d for d in dirnames if d not in ('build', 'third_party') and not d.startswith('.')
]
if t not in extra:
cpp += sum(f.endswith(('.cpp', '.hpp', '.h', '.cc')) for f in files)
shf += sum(f.endswith('.sh') or dirpath.endswith('tools/shell') for f in files)
Expand Down Expand Up @@ -968,12 +970,12 @@ def cmd_lint(ws, args):
paths = ' '.join(shlex.quote(p) for p in lint_targets(ws, domains))
fix = args.fix
find_cpp = (
f"find {paths} -path '*/build' -prune -o -type f "
f"find {paths} \\( -path '*/build' -o -path '*/third_party' \\) -prune -o -type f "
"\\( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.cc' \\) -print"
)
find_sh = ( # + the shell rc of `ditx shell` and the root install.sh
f'find {paths} {ws.root}/docker {ws.root}/infra {ws.root}/.github {ws.root}/install.sh '
"-path '*/build' "
"\\( -path '*/build' -o -path '*/third_party' \\) "
"-prune -o -type f \\( -name '*.sh' -o -path '*tools/shell/*' \\) -print"
)
gen = f'{ws.root}/base/eurobot_common/scripts/gen_contract.py'
Expand Down Expand Up @@ -1005,8 +1007,9 @@ def cmd_lint(ws, args):
sh.append(
section_sh(
'ruff',
f'ruff check --output-format concise {"--fix " if fix else ""}{paths} && '
f'ruff format {"" if fix else "--check "}{paths}',
# format even when `check --fix` leaves problems, so --fix does all it can
f'ruff check --output-format concise {"--fix " if fix else ""}{paths}; rc=$?; '
f'ruff format {"" if fix else "--check "}{paths} && [ $rc -eq 0 ]',
stop=False,
)
)
Expand Down