licenseheaders icon indicating copy to clipboard operation
licenseheaders copied to clipboard

Code with inline comment disappear after apply licenseheaders

Open oatawa1 opened this issue 4 years ago • 9 comments

I installed licenseheaders via pip and get licenseheaders_0.8.5.

I applied licenseheaders on my code and the line with a comment symbol (#), which is continue from header block, is disappeared.

Here is my command and log.

$ licenseheaders -v -v -d target -t header.tmpl -b
licenseheaders_0.8.5 INFO: Using file //header.tmpl
licenseheaders_0.8.5 INFO: Processing file target/foo.py as python
licenseheaders_0.8.5 INFO: Backing up file target/foo.py to target/foo.py.bak

foo.py.bak (original)

#
# Copyright (c) 2020 Foo Inc. All rights reserved.
#
from XXX import YYY # Import package

foo.py (after)

#
# Copyright (c) 2020 Foo Inc. All rights reserved.
#

oatawa1 avatar Jul 27 '20 05:07 oatawa1

That looks like a terrible terrbile bug, thanks for reporting.

johann-petrak avatar Jul 27 '20 09:07 johann-petrak

I noticed this bug too. Is it easy to fix?

jdumas avatar Aug 28 '20 16:08 jdumas

@jdumas , Hello.

I found solution that looks like working.

Line 85 in licenseheaders.py.

Replace: "lineCommentStartPattern": re.compile(r'\s*#'), To: "lineCommentStartPattern": re.compile(r'^\s*#'),

Description: looks like pattern '\s*#' grab every line from beging that contain # . But with new one ^\s*# everything looks okay.

Igor1306 avatar Sep 01 '20 14:09 Igor1306

Probably wouldn't work if the line just below the header is a comment, but not part of the header itself.

jdumas avatar Sep 01 '20 14:09 jdumas

@jdumas, its working for this case:

#
# Copyright (c) 2020 Foo Inc. All rights reserved.
#
from XXX import YYY # Import package

Import will not be rewritten.

Igor1306 avatar Sep 01 '20 18:09 Igor1306

How about this one:

#
# Copyright (c) 2020 Foo Inc. All rights reserved.
#
# Import package
from XXX import YYY

jdumas avatar Sep 01 '20 18:09 jdumas

@Igor1306 Thank you. Your solution solved my issue.

Anyway, I try with this case but the #import package line is missing.

#
# Copyright (c) 2020 Foo Inc. All rights reserved.
#
# Import package
from XXX import YYY

I have this modification.

85c85
<         "lineCommentStartPattern": re.compile(r'\s*#'),
---
>         "lineCommentStartPattern": re.compile(r'^\s*#'),

Could you tell me any other modification?

oatawa1 avatar Sep 02 '20 09:09 oatawa1

@oatawa1, you are welcome. I will try to investigate this issue a little bit later, will inform about results.

Igor1306 avatar Sep 02 '20 11:09 Igor1306

@oatawa1 hello, sorry for long delay in response, I didn't come up with solution for now. Logic of licenseheader should be rewrite a little, for covering your case.

Igor1306 avatar Sep 09 '20 07:09 Igor1306