From c798869c6762628f6bcbab86f3381b0857f2dce7 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:46:11 +0200 Subject: [PATCH 01/10] Added comments to test init method --- colcon_cargo/task/cargo/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/colcon_cargo/task/cargo/test.py b/colcon_cargo/task/cargo/test.py index 8b1db36..6e0a4a9 100644 --- a/colcon_cargo/task/cargo/test.py +++ b/colcon_cargo/task/cargo/test.py @@ -18,6 +18,11 @@ class CargoTestTask(TaskExtensionPoint): """Test Cargo packages.""" def __init__(self): # noqa: D107 + """ + Initialize the CargoTestTask. + + This method calls the __init__ method of the parent class TaskExtensionPoint. + """ super().__init__() satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') From e249eb3a6d11e1bc8b825258eae0c38e75cd0978 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:46:26 +0200 Subject: [PATCH 02/10] Added pydoc comments to add arguments method --- colcon_cargo/task/cargo/test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/colcon_cargo/task/cargo/test.py b/colcon_cargo/task/cargo/test.py index 6e0a4a9..973ab32 100644 --- a/colcon_cargo/task/cargo/test.py +++ b/colcon_cargo/task/cargo/test.py @@ -27,6 +27,14 @@ def __init__(self): # noqa: D107 satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 + """ + Add command-line arguments for the CargoTestTask. + + This method is currently empty and does not add any arguments. + + Args: + parser: The argument parser to add arguments to. + """ pass async def test(self, *, additional_hooks=None): # noqa: D102 From 59656ea4b93e8543694a06e6f200754180b5c9a2 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:46:42 +0200 Subject: [PATCH 03/10] Added comments to async def method --- colcon_cargo/task/cargo/test.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/colcon_cargo/task/cargo/test.py b/colcon_cargo/task/cargo/test.py index 973ab32..54b3706 100644 --- a/colcon_cargo/task/cargo/test.py +++ b/colcon_cargo/task/cargo/test.py @@ -38,6 +38,19 @@ def add_arguments(self, *, parser): # noqa: D102 pass async def test(self, *, additional_hooks=None): # noqa: D102 + """ + Test the Cargo package. + + This method runs the 'cargo test' command to test the Cargo package specified + in the context. It sets up the necessary environment, runs the test command, + and handles the test results. + + Args: + additional_hooks: Additional hooks to be executed. + + Returns: + An integer return code. 0 indicates success, and a non-zero value indicates failure. + """ pkg = self.context.pkg args = self.context.args From b6022cbd18c0ce4c9ec3ac142f93dc36fbb18da1 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:49:48 +0200 Subject: [PATCH 04/10] added pydoc comments to init method --- colcon_cargo/task/cargo/build.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index a52ed0a..7592208 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -19,6 +19,12 @@ class CargoBuildTask(TaskExtensionPoint): """Build Cargo packages.""" def __init__(self): # noqa: D107 + """ + Initialize the CargoBuildTask. + + This method calls the __init__ method of the parent class TaskExtensionPoint + and checks the version compatibility. + """ super().__init__() satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') From 6a62b7174d021d8a1bbdc28b6146a8b4a1477e7a Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:50:30 +0200 Subject: [PATCH 05/10] added pydoc comments to add_arguments method --- colcon_cargo/task/cargo/build.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index 7592208..746e929 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -29,6 +29,15 @@ def __init__(self): # noqa: D107 satisfies_version(TaskExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def add_arguments(self, *, parser): # noqa: D102 + """ + Add command-line arguments for the CargoBuildTask. + + This method adds arguments to the parser for passing arguments to Cargo + projects and for cleaning the build directory before the build. + + Args: + parser: The argument parser to add arguments to. + """ parser.add_argument( '--cargo-args', nargs='*', metavar='*', type=str.lstrip, From 10b1a830e97152c39d74e7423c334b4f19934381 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:51:24 +0200 Subject: [PATCH 06/10] Added comments to async build method --- colcon_cargo/task/cargo/build.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index 746e929..49e4d65 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -52,6 +52,20 @@ def add_arguments(self, *, parser): # noqa: D102 async def build( # noqa: D102 self, *, additional_hooks=None, skip_hook_creation=False ): + """ + Build the Cargo package. + + This method builds the Cargo package specified in the context. It sets up + the necessary environment, prepares the build directory, invokes the build + command, and creates environment scripts if requested. + + Args: + additional_hooks: Additional hooks to be executed. + skip_hook_creation: Whether to skip creating environment hooks. + + Returns: + An integer return code. 0 indicates success, and a non-zero value indicates failure. + """ if additional_hooks is None: additional_hooks = [] args = self.context.args From 3488b1c94c787e6ad238fd3df5d74bd04d10dec7 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:52:47 +0200 Subject: [PATCH 07/10] Added comments to _prepare method --- colcon_cargo/task/cargo/build.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index 49e4d65..4081ad4 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -115,6 +115,16 @@ async def build( # noqa: D102 # Overridden by colcon-ros-cargo def _prepare(self, env, additional_hooks): + """ + Prepare the build environment. + + This method is intended to be overridden by colcon-ros-cargo. + It creates an environment hook for the package's PATH. + + Args: + env: The environment to prepare. + additional_hooks: Additional hooks to be executed. + """ pkg = self.context.pkg additional_hooks += create_environment_hook( 'cargo_{}_path'.format(pkg.name), From b2a78250d7b65ea9a4197309446b93dd554bca35 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 12:53:02 +0200 Subject: [PATCH 08/10] Added comments to _build method --- colcon_cargo/task/cargo/build.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/colcon_cargo/task/cargo/build.py b/colcon_cargo/task/cargo/build.py index 4081ad4..332d5d2 100644 --- a/colcon_cargo/task/cargo/build.py +++ b/colcon_cargo/task/cargo/build.py @@ -134,6 +134,18 @@ def _prepare(self, env, additional_hooks): # Overridden by colcon-ros-cargo def _build_cmd(self, cargo_args): + """ + Get the build command for Cargo. + + This method is intended to be overridden by colcon-ros-cargo. + It returns the command to run 'cargo install' with the provided arguments. + + Args: + cargo_args: Additional arguments to pass to Cargo. + + Returns: + A list containing the Cargo build command and its arguments. + """ args = self.context.args return [ CARGO_EXECUTABLE, 'install', From 1b75568b8c288de0db6d53676fa08a95f7bd666c Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 13:00:30 +0200 Subject: [PATCH 09/10] added pydoc comments to package identification init method --- colcon_cargo/package_identification/cargo.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/colcon_cargo/package_identification/cargo.py b/colcon_cargo/package_identification/cargo.py index 367b399..8b42034 100644 --- a/colcon_cargo/package_identification/cargo.py +++ b/colcon_cargo/package_identification/cargo.py @@ -15,6 +15,12 @@ class CargoPackageIdentification(PackageIdentificationExtensionPoint): """Identify Cargo packages with `Cargo.toml` files.""" def __init__(self): # noqa: D107 + """ + Initialize the CargoPackageIdentification. + + This method calls the __init__ method of the parent class PackageIdentificationExtensionPoint + and checks the version compatibility. + """ super().__init__() satisfies_version( PackageIdentificationExtensionPoint.EXTENSION_POINT_VERSION, From 52e600124755f3ef16c2a7c57786832216d53d35 Mon Sep 17 00:00:00 2001 From: GueLaKais Date: Sat, 29 Jun 2024 13:08:05 +0200 Subject: [PATCH 10/10] added comments to the argcompleter method --- .../argcomplete_completer/cargo_args.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/colcon_cargo/argcomplete_completer/cargo_args.py b/colcon_cargo/argcomplete_completer/cargo_args.py index 53d5cc4..17466bf 100644 --- a/colcon_cargo/argcomplete_completer/cargo_args.py +++ b/colcon_cargo/argcomplete_completer/cargo_args.py @@ -20,7 +20,25 @@ def __init__(self): # noqa: D107 ArgcompleteCompleterExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') def get_completer(self, parser, *args, **kwargs): # noqa: D102 - if '--cargo-args' not in args: + """ + Get the completer for Cargo arguments. + + This method checks if the '--cargo-args' argument is present in the provided arguments. + If it is, it tries to import the ChoicesCompleter from the argcomplete package and returns + an instance of it with an empty list of choices. If the '--cargo-args' argument is not + present or the argcomplete package is not installed, it returns None. + + Args: + parser: The argument parser. + *args: Positional arguments passed to the method. + **kwargs: Keyword arguments passed to the method. + + Returns: + ChoicesCompleter or None: An instance of ChoicesCompleter with an empty list of choices, + or None if the '--cargo-args' argument is not present or the argcomplete package is not + installed. + """ + if "--cargo-args" not in args: return None try: