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

Added more robust comment format support. #82

Closed
wants to merge 2 commits into from

Conversation

allenh1
Copy link

@allenh1 allenh1 commented Aug 4, 2017

I've tested this as-is with the following:

/*
 * slam_gmapping
 * Copyright (c) 2008, Willow Garage, Inc.
 * Copyright (c) 2017, Open Source Robotics Foundation, Inc.
 *
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
 * COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
 * COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
 * AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO
 * BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS
 * CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
 * CONDITIONS.
 *
 */

and got

src/slam_gmapping.cpp: copyright=Willow Garage, Inc. (2008), Open Source Robotics Foundation, Inc. (2017), license=<unknown>

which seems to be correct (since we don't have a BSD template).

I do not know enough to call this resolved, however.

connects to #75


This change is Reviewable

@allenh1 allenh1 added the in progress Actively being worked on (Kanban column) label Aug 4, 2017
@allenh1 allenh1 self-assigned this Aug 4, 2017
@@ -175,7 +175,7 @@ def search_copyright_information(content):
year = '\d{4}'
year_range = '%s-%s' % (year, year)
year_or_year_range = '(?:%s|%s)' % (year, year_range)
pattern = '^[^\n\r]?\s*Copyright(?:\s+\(c\))?\s+(%s(?:,\s*%s)*),?\s+([^\n\r]+)$' % \
pattern = '^[^\n\r]?[\s\*\w]*Copyright(?:\s+\(c\))?\s+(%s(?:,\s*%s)*),?\s+([^\n\r]+)$' % \
Copy link
Author

Choose a reason for hiding this comment

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

I'm very hesitant to allow for arbitrary alpha-numeric characters here... I don't know enough about licensing to state if this is valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? Is this aiming to allow newlines anywhere in the comment? Would it be sufficient to only make it flexible within the license?

Copy link
Author

Choose a reason for hiding this comment

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

This is because of things like

/*
 * My Amazing Project
 * Copyright (c) 2017

I saw a lot of that in some old willow code (like GMapping).

Copy link
Author

Choose a reason for hiding this comment

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

I don't think the \* is needed, however.

@@ -248,6 +249,8 @@ def get_comment_block(content, index):
comment_token = match.group(1)
start_index = match.start(1)

if comment_token in ['/*', '/**']:
comment_token = ' *'
Copy link
Author

Choose a reason for hiding this comment

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

This is rather unfortunate -- does anyone see a better way?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the leading space should not be required. This should be valid:

/**
* text
*/

Copy link
Author

Choose a reason for hiding this comment

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

Ok -- I can add that functionality.

/**
text
*/

is that also acceptable?

Copy link
Author

Choose a reason for hiding this comment

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

I'm thinking something like this:

if comment_token in ['/*', '/**']:
    comment_token = '*'
"""
more code
"""
lines = [line[line.index(comment_token) + 1:] for line in lines]

That works for the existing copyright cases, but not for the new ones.

@allenh1
Copy link
Author

allenh1 commented Aug 9, 2017

I've determined I don't have the time to make this as robust as I'd like, as it will require a very significant rewrite in the parser.py file (many assumptions are made based on the fact that the comments start with the same prefix on every line, and that they are on every line).

This PR only supports

/*
 *
 */

because of the * on the end of the last comment line. This does, however, add the desired newline robustness.

@mikaelarguedas
Copy link
Contributor

@allenh1 if you are not working on this anymore, can you reflect it in the labels? (by removing the 'in progress' label from this and the parent issue)

@allenh1
Copy link
Author

allenh1 commented Aug 10, 2017

@mikaelarguedas done

@allenh1 allenh1 removed the in progress Actively being worked on (Kanban column) label Aug 10, 2017
@mikaelarguedas mikaelarguedas assigned wjwwood and unassigned allenh1 Aug 30, 2017
@mikaelarguedas
Copy link
Contributor

@wjwwood FYI:
This works for bloc comments right now.

/*
 * stuff
 */

Current cases not covered:

  • more than 1 space between comment marker and text:
/*
 *      stuff
 */
  • no space between comment marker and text:
/*
 *stuff
 */
  • not leading * for each line within the block comment
/*
stuff
*/
  • not leading space before *
/*
* stuff
*/

@dirk-thomas dirk-thomas added the enhancement New feature or request label Feb 22, 2018
@greimela-si
Copy link

@wjwwood @mikaelarguedas Are there any plans to merge this?

@wjwwood
Copy link
Contributor

wjwwood commented Jul 11, 2018

It's not on my todo-list right now. I doubt I'll have time to address it in the short-term.

@wjwwood wjwwood added the help wanted Extra attention is needed label Jul 11, 2018
@wjwwood wjwwood removed their assignment Jul 11, 2018
tfoote added a commit to ros2/rcutils that referenced this pull request Aug 6, 2018
tfoote added a commit to ros2/rcutils that referenced this pull request Aug 7, 2018
tfoote added a commit to ros2/rcutils that referenced this pull request Jul 24, 2019
tfoote added a commit to ros2/rcutils that referenced this pull request Jul 24, 2019
Working around ament/ament_lint#82

Signed-off-by: Tully Foote <tfoote@osrfoundation.org>
@dirk-thomas
Copy link
Contributor

Closing due to no activity.

Recent related work: #160.

@dirk-thomas dirk-thomas deleted the copyright-newline-robustness-75 branch July 30, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants