Skip to content

Commit 8d27d97

Browse files
feat: change --manifest-path to --path (#94)
Co-authored-by: remimimimimi <[email protected]>
1 parent 37ad651 commit 8d27d97

File tree

10 files changed

+352
-19
lines changed

10 files changed

+352
-19
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323

2424
jobs:
2525
test-linux-x86_64:
26-
timeout-minutes: 10
26+
timeout-minutes: 15
2727
name: Build test Linux x86_64
2828
runs-on: 8core_ubuntu_latest_runner
2929
steps:
@@ -44,7 +44,7 @@ jobs:
4444
run: pixi run --locked test-slow
4545

4646
test-windows-x86_64:
47-
timeout-minutes: 10
47+
timeout-minutes: 15
4848
name: Build test Windows x86_64
4949
runs-on: windows-latest
5050
steps:
@@ -74,7 +74,7 @@ jobs:
7474
working-directory: ${{ env.PIXI_WORKSPACE }}
7575

7676
test-macos-aarch64:
77-
timeout-minutes: 10
77+
timeout-minutes: 15
7878
name: Build test macOS aarch64
7979
runs-on: macos-14
8080
steps:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package:
2+
name: c
3+
version: 0.1.0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(navigator)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
# find dependencies
9+
find_package(ament_cmake REQUIRED)
10+
find_package(rclcpp REQUIRED)
11+
find_package(geometry_msgs REQUIRED)
12+
find_package(turtlesim REQUIRED)
13+
14+
add_executable(navigator src/navigator.cpp)
15+
target_include_directories(navigator PUBLIC
16+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
17+
$<INSTALL_INTERFACE:include>)
18+
target_compile_features(navigator PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
19+
ament_target_dependencies(
20+
navigator
21+
"rclcpp"
22+
"geometry_msgs"
23+
"turtlesim"
24+
)
25+
26+
install(TARGETS navigator
27+
DESTINATION lib/${PROJECT_NAME})
28+
29+
# if(BUILD_TESTING)
30+
# find_package(ament_lint_auto REQUIRED)
31+
# # the following line skips the linter which checks for copyrights
32+
# # comment the line when a copyright and license is added to all source files
33+
# set(ament_cmake_copyright_FOUND TRUE)
34+
# # the following line skips cpplint (only works in a git repo)
35+
# # comment the line when this package is in a git repo and when
36+
# # a copyright and license is added to all source files
37+
# set(ament_cmake_cpplint_FOUND TRUE)
38+
# ament_lint_auto_find_test_dependencies()
39+
# endif()
40+
41+
ament_package()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>navigator</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">rarts</maintainer>
8+
<license>BSD-3-Clause</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>rclcpp</depend>
13+
<depend>geometry_msgs</depend>
14+
<depend>turtlesim</depend>
15+
16+
<test_depend>ament_lint_auto</test_depend>
17+
<test_depend>ament_lint_common</test_depend>
18+
19+
<export>
20+
<build_type>ament_cmake</build_type>
21+
</export>
22+
</package>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#define _USE_MATH_DEFINES
2+
3+
#include <cmath>
4+
5+
#include "rclcpp/rclcpp.hpp"
6+
#include "geometry_msgs/msg/point.hpp"
7+
#include "geometry_msgs/msg/twist.hpp"
8+
#include "turtlesim/msg/pose.hpp"
9+
10+
class TurtleNavigator : public rclcpp::Node
11+
{
12+
public:
13+
TurtleNavigator()
14+
: Node("turtle_navigator"), x_goal_(4.0), y_goal_(5.0), kp_(1.0), ki_(0.0), kd_(0.05), prev_error_(0.0), integral_(0.0)
15+
{
16+
subscription_ = this->create_subscription<geometry_msgs::msg::Point>(
17+
"coordinates", 10, std::bind(&TurtleNavigator::goal_callback, this, std::placeholders::_1));
18+
pose_subscription_ = this->create_subscription<turtlesim::msg::Pose>(
19+
"turtle1/pose", 10, std::bind(&TurtleNavigator::pose_callback, this, std::placeholders::_1));
20+
publisher_ = this->create_publisher<geometry_msgs::msg::Twist>("turtle1/cmd_vel", 10);
21+
22+
timer_ = this->create_wall_timer(
23+
std::chrono::milliseconds(100), std::bind(&TurtleNavigator::control_loop, this));
24+
25+
RCLCPP_INFO(this->get_logger(), "Turtle Navigator has been started!");
26+
RCLCPP_INFO(this->get_logger(), "Initial goal: x=%f, y=%f", x_goal_, y_goal_);
27+
}
28+
29+
private:
30+
void goal_callback(const geometry_msgs::msg::Point::SharedPtr msg)
31+
{
32+
x_goal_ = msg->x;
33+
y_goal_ = msg->y;
34+
RCLCPP_INFO(this->get_logger(), "Received goal: x=%f, y=%f", x_goal_, y_goal_);
35+
}
36+
37+
void pose_callback(const turtlesim::msg::Pose::SharedPtr msg)
38+
{
39+
x_current_ = msg->x;
40+
y_current_ = msg->y;
41+
theta_current_ = msg->theta;
42+
}
43+
44+
void control_loop()
45+
{
46+
// RCLCPP_INFO(this->get_logger(), "Hello Ruben!");
47+
double error_x = x_goal_ - x_current_;
48+
double error_y = y_goal_ - y_current_;
49+
double distance_error = std::sqrt(error_x * error_x + error_y * error_y);
50+
51+
double angle_to_goal = std::atan2(error_y, error_x);
52+
double angle_error = angle_to_goal - theta_current_;
53+
54+
// Normalize angle error to the range [-pi, pi]
55+
while (angle_error > M_PI) angle_error -= 2 * M_PI;
56+
while (angle_error < -M_PI) angle_error += 2 * M_PI;
57+
58+
// PID control
59+
double control_signal = kp_ * distance_error + ki_ * integral_ + kd_ * (distance_error - prev_error_);
60+
integral_ += distance_error;
61+
prev_error_ = distance_error;
62+
63+
// Limit control signal
64+
double max_linear_speed = 2.0; // Max linear speed
65+
double max_angular_speed = 2.0; // Max angular speed
66+
control_signal = std::clamp(control_signal, -max_linear_speed, max_linear_speed);
67+
68+
// Publish velocity commands
69+
auto msg = geometry_msgs::msg::Twist();
70+
msg.linear.x = control_signal;
71+
msg.angular.z = 4.0 * angle_error; // simple P controller for angle
72+
msg.angular.z = std::clamp(msg.angular.z, -max_angular_speed, max_angular_speed);
73+
74+
publisher_->publish(msg);
75+
}
76+
77+
rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr subscription_;
78+
rclcpp::Subscription<turtlesim::msg::Pose>::SharedPtr pose_subscription_;
79+
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher_;
80+
rclcpp::TimerBase::SharedPtr timer_;
81+
82+
double x_goal_, y_goal_;
83+
double x_current_, y_current_, theta_current_;
84+
double kp_, ki_, kd_;
85+
double prev_error_, integral_;
86+
};
87+
88+
int main(int argc, char *argv[])
89+
{
90+
rclcpp::init(argc, argv);
91+
rclcpp::spin(std::make_shared<TurtleNavigator>());
92+
rclcpp::shutdown();
93+
return 0;
94+
}

tests/integration_python/test_build.py

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_build_conda_package(
2626
[
2727
pixi,
2828
"build",
29-
"--manifest-path",
29+
"--path",
3030
simple_workspace.package_dir,
3131
"--output-dir",
3232
simple_workspace.workspace_dir,
@@ -245,7 +245,7 @@ def test_build_using_rattler_build_backend(
245245

246246
# Running pixi build should build the recipe.yaml
247247
verify_cli_command(
248-
[pixi, "build", "-v", "--manifest-path", manifest_path, "--output-dir", tmp_pixi_workspace],
248+
[pixi, "build", "-v", "--path", manifest_path, "--output-dir", tmp_pixi_workspace],
249249
)
250250

251251
# really make sure that conda package was built
@@ -256,7 +256,7 @@ def test_build_using_rattler_build_backend(
256256

257257
# check that immediately repeating the build also works (prefix-dev/pixi-build-backends#287)
258258
verify_cli_command(
259-
[pixi, "build", "-v", "--manifest-path", manifest_path, "--output-dir", tmp_pixi_workspace],
259+
[pixi, "build", "-v", "--path", manifest_path, "--output-dir", tmp_pixi_workspace],
260260
)
261261

262262

@@ -276,14 +276,14 @@ def test_incremental_builds(
276276
manifest_path = tmp_pixi_workspace / "pixi.toml"
277277

278278
verify_cli_command(
279-
[pixi, "build", "-v", "--manifest-path", manifest_path, "--output-dir", tmp_pixi_workspace],
279+
[pixi, "build", "-v", "--path", manifest_path, "--output-dir", tmp_pixi_workspace],
280280
stderr_contains=non_incremental_evidence,
281281
strip_ansi=True,
282282
)
283283

284284
# immediately repeating the build should give evidence of incremental compilation
285285
verify_cli_command(
286-
[pixi, "build", "-v", "--manifest-path", manifest_path, "--output-dir", tmp_pixi_workspace],
286+
[pixi, "build", "-v", "--path", manifest_path, "--output-dir", tmp_pixi_workspace],
287287
stderr_excludes=non_incremental_evidence,
288288
strip_ansi=True,
289289
)
@@ -352,6 +352,93 @@ def test_rattler_build_source_dependency(
352352
)
353353

354354

355+
def test_rattler_build_point_to_recipe(
356+
pixi: Path, build_data: Path, tmp_pixi_workspace: Path
357+
) -> None:
358+
test_data = build_data.joinpath("rattler-build-backend")
359+
# copy the whole smokey2 project to the tmp_pixi_workspace
360+
copytree_with_local_backend(
361+
test_data / "source-dependency", tmp_pixi_workspace / "source-dependency"
362+
)
363+
manifest_path = tmp_pixi_workspace / "source-dependency" / "c" / "recipe.yaml"
364+
365+
output_dir = tmp_pixi_workspace.joinpath("dist")
366+
output_dir.mkdir(parents=True, exist_ok=True)
367+
368+
verify_cli_command(
369+
[
370+
pixi,
371+
"build",
372+
"-v",
373+
"--path",
374+
manifest_path,
375+
"--output-dir",
376+
output_dir,
377+
],
378+
expected_exit_code=ExitCode.SUCCESS,
379+
)
380+
381+
built_packages = list(output_dir.glob("*.conda"))
382+
assert built_packages, "no package artifacts produced"
383+
384+
385+
def test_rattler_build_autodiscovery(
386+
pixi: Path, build_data: Path, tmp_pixi_workspace: Path
387+
) -> None:
388+
test_data = build_data.joinpath("rattler-build-backend")
389+
# copy the whole smokey2 project to the tmp_pixi_workspace
390+
copytree_with_local_backend(
391+
test_data / "source-dependency", tmp_pixi_workspace / "source-dependency"
392+
)
393+
# don-t point to recipe.yaml, but to the directory containing it
394+
manifest_path = tmp_pixi_workspace / "source-dependency" / "c"
395+
396+
output_dir = tmp_pixi_workspace.joinpath("dist")
397+
output_dir.mkdir(parents=True, exist_ok=True)
398+
399+
verify_cli_command(
400+
[
401+
pixi,
402+
"build",
403+
"-v",
404+
"--path",
405+
manifest_path,
406+
"--output-dir",
407+
output_dir,
408+
],
409+
expected_exit_code=ExitCode.SUCCESS,
410+
)
411+
412+
built_packages = list(output_dir.glob("*.conda"))
413+
assert built_packages, "no package artifacts produced"
414+
415+
416+
def test_suggest_what_manifest_file_should_be(
417+
pixi: Path, build_data: Path, tmp_pixi_workspace: Path
418+
) -> None:
419+
test_data = build_data.joinpath("rattler-build-backend")
420+
# copy the whole smokey2 project to the tmp_pixi_workspace
421+
copytree_with_local_backend(
422+
test_data / "source-dependency", tmp_pixi_workspace / "source-dependency"
423+
)
424+
# don-t point to recipe.yaml, but to the directory containing it
425+
manifest_path = tmp_pixi_workspace / "source-dependency" / "empty-dir"
426+
427+
manifest_path.mkdir(parents=True, exist_ok=True)
428+
429+
verify_cli_command(
430+
[
431+
pixi,
432+
"build",
433+
"-v",
434+
"--path",
435+
manifest_path,
436+
],
437+
expected_exit_code=ExitCode.FAILURE,
438+
stderr_contains="Ensure that the source directory contains a valid pixi.toml, pyproject.toml, recipe.yaml, package.xml or mojoproject.toml file.",
439+
)
440+
441+
355442
@pytest.mark.slow
356443
def test_recursive_source_run_dependencies(
357444
pixi: Path, build_data: Path, tmp_pixi_workspace: Path
@@ -469,7 +556,7 @@ def test_source_path(pixi: Path, build_data: Path, tmp_pixi_workspace: Path) ->
469556
[
470557
pixi,
471558
"build",
472-
"--manifest-path",
559+
"--path",
473560
tmp_pixi_workspace,
474561
"--output-dir",
475562
tmp_pixi_workspace,
@@ -524,5 +611,5 @@ def test_target_specific_dependency(
524611
manifest_path.write_text(tomli_w.dumps(manifest))
525612

526613
verify_cli_command(
527-
[pixi, "build", "--manifest-path", manifest_path, "--output-dir", tmp_pixi_workspace],
614+
[pixi, "build", "--path", manifest_path, "--output-dir", tmp_pixi_workspace],
528615
)

tests/integration_python/test_multi_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_build(pixi: Path, build_data: Path, tmp_pixi_workspace: Path) -> None:
1414
[
1515
pixi,
1616
"build",
17-
"--manifest-path",
17+
"--path",
1818
package_manifest,
1919
"--output-dir",
2020
tmp_pixi_workspace,

0 commit comments

Comments
 (0)