Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check root dir #383

Closed
wants to merge 13 commits into from

Conversation

claireyywang
Copy link

@claireyywang claireyywang commented Sep 22, 2020

Adds a .root_dir marker file when first building a workspace. Check for .root_dir file whenever build or test verbs are invoked, terminate command if marker file not found. closes #369

What this PR does not cover:

  • discovering marker file in child directories. If colcon build is invoked in ~/, no error/warning will be output by this function, and a marker file will be generated in ~/
  • if a child directory is wrongly marked as root, user has to manually remove the .colcon file for this warning function to work properly

To test this function, follow build from source instruction here https://colcon.readthedocs.io/en/released/developer/bootstrap.html, then run colcon build in different directories to see the error msg.

Terminal output if colcon build in child dir:

$ colcon build 
[0.620s] ERROR:colcon:colcon build: '/home/claire/colcon-from-source/src/colcon-core' is not marked as the root directory. Please go to '/home/claire/colcon-from-source' for `colcon build`. If the current directory is intended to be the root workspace, please remove the '.root_dir' file in '/home/claire/colcon-from-source'.

still need to add test cases...

Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
@codecov
Copy link

codecov bot commented Sep 22, 2020

Codecov Report

Merging #383 into master will decrease coverage by 1.44%.
The diff coverage is 11.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #383      +/-   ##
==========================================
- Coverage   80.01%   78.57%   -1.45%     
==========================================
  Files          56       56              
  Lines        3272     3290      +18     
  Branches      543      546       +3     
==========================================
- Hits         2618     2585      -33     
- Misses        615      654      +39     
- Partials       39       51      +12     
Impacted Files Coverage Δ
colcon_core/verb/build.py 0.00% <0.00%> (ø)
colcon_core/verb/__init__.py 82.66% <7.14%> (-17.34%) ⬇️
colcon_core/verb/test.py 28.57% <50.00%> (+0.41%) ⬆️
colcon_core/shell/bat.py 71.42% <0.00%> (-19.05%) ⬇️
colcon_core/environment/path.py 93.10% <0.00%> (-6.90%) ⬇️
colcon_core/shell/sh.py 84.12% <0.00%> (-6.35%) ⬇️
colcon_core/event/command.py 94.33% <0.00%> (-5.67%) ⬇️
colcon_core/subprocess.py 60.15% <0.00%> (-5.47%) ⬇️
colcon_core/package_discovery/path.py 96.07% <0.00%> (-3.93%) ⬇️
colcon_core/logging.py 91.37% <0.00%> (-3.45%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update caee5e6...1414381. Read the comment docs.

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock / messages could be a bit clearer / more precise (and contain spelling mistakes) but let's first focus on the functional parts.

Why is the check limited to the build and test verbs? (Also the whole ticket description doesn't mention test.)

colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
:param str this_build_tool: The name of this build tool
:raises RuntimeError: if marker file is found in parent directory
"""
original_path = Path(os.getcwd())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be clearer (easier to test, and more reusable) if the function would have the start path as an argument rather then getting it internally from global state?

colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
Signed-off-by: claireyywang <[email protected]>
@claireyywang
Copy link
Author

claireyywang commented Sep 30, 2020

@dirk-thomas Thanks for the timely review. I tried to address most of the comments, but not sure about a few.

Why is the check limited to the build and test verbs?

Those are the only two verbs in colcon-core, and seem to address the feature request in #369. Is there anywhere else that could also use this check?

Wouldn't it be clearer (easier to test, and more reusable) if the function would have the start path as an argument rather then getting it internally from global state?

I added an arg start_path to address this comment, and set the default value using a global state variable. Not sure if that's the best way to do it, so I'm open to suggestions.

@claireyywang claireyywang marked this pull request as draft September 30, 2020 00:59
Signed-off-by: claireyywang <[email protected]>
@codebot
Copy link

codebot commented Oct 1, 2020

Thanks so much! This will be a very nice UX improvement.

@claireyywang claireyywang marked this pull request as ready for review October 1, 2020 20:33
@dirk-thomas dirk-thomas added the enhancement New feature or request label Oct 1, 2020
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the only two verbs in colcon-core, and seem to address the feature request in #369. Is there anywhere else that could also use this check?

The same check seems to be applicable to several other verbs: graph, info, list, test-result.

@@ -116,6 +123,7 @@ def add_arguments(self, *, parser): # noqa: D102
self.task_argument_destinations = decorated_parser.get_destinations()

def main(self, *, context): # noqa: D102
check_and_mark_root_dir(context.args.start_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the invocation here in the verb is too late since e.g. the log directory has already been created which isn't desired.

colcon_core/verb/__init__.py Outdated Show resolved Hide resolved
colcon_core/verb/build.py Outdated Show resolved Hide resolved
@claireyywang
Copy link
Author

The same check seems to be applicable to several other verbs: graph, info, list, test-result.

Wouldn't it limit the usability of these verbs if they can only be invoked in root directory?

@dirk-thomas
Copy link
Member

Wouldn't it limit the usability of these verbs if they can only be invoked in root directory?

Isn't that the whole idea of this PR - to limit the locations where colcon can be invoked to the root of a workspace?

@claireyywang
Copy link
Author

claireyywang commented Oct 2, 2020

Isn't that the whole idea of this PR - to limit the locations where colcon can be invoked to the root of a workspace?

I think the consequence of not running build and test at root dir is more significant than all the other verbs, cuz they rely on root level package discovery and create build and install folders even when the process is not successful. Whereas verbs like graph, info ... can be executed in child directories relatively faster and easier without creating substantial overhead. I can also think of use cases like running colcon list within a repo to figure out what packages are available inside, which will not be available is all verbs are limited to root workspace.

The idea of this PR is to address discussion in #139 and #369, which both point to the build verb.

@dirk-thomas
Copy link
Member

How about test-result which wouldn't work correctly if not invoked in the root?

@claireyywang
Copy link
Author

How about test-result which wouldn't work correctly if not invoked in the root?

lol I've actually never used that verb. I'll take a look and see if I can add the root dir check to it as well. Thanks for the heads up.

@dirk-thomas
Copy link
Member

@claireyywang Friendly ping.

@claireyywang claireyywang self-assigned this Nov 30, 2020
@claireyywang claireyywang removed their assignment Feb 18, 2021
@Flova
Copy link

Flova commented Jan 23, 2024

What is the state of this PR? This as well as #487 are some quite significant UX improvements that people who start out in ROS 2 (coming from ROS 1) find very much annoying. If @claireyywang is not available anymore, I would take a look at it. But I don't want to invest time and effort only for it to end up like #487.

@cottsay
Copy link
Member

cottsay commented Jan 23, 2024

We will address this with a separate colcon extension. There has been discussion in #139. I'll close this PR since this isn't the approach we plan to take.

@cottsay cottsay closed this Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

usability enhancement: fail with a polite message when invoking in src
5 participants