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

Code with inline comment disappear after apply licenseheaders #38

Open
oatawa1 opened this issue Jul 27, 2020 · 9 comments
Open

Code with inline comment disappear after apply licenseheaders #38

oatawa1 opened this issue Jul 27, 2020 · 9 comments

Comments

@oatawa1
Copy link

oatawa1 commented Jul 27, 2020

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.
#
@johann-petrak
Copy link
Owner

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

@jdumas
Copy link

jdumas commented Aug 28, 2020

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

@Igor1306
Copy link
Contributor

Igor1306 commented Sep 1, 2020

@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.

@jdumas
Copy link

jdumas commented Sep 1, 2020

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

@Igor1306
Copy link
Contributor

Igor1306 commented Sep 1, 2020

@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.

@jdumas
Copy link

jdumas commented Sep 1, 2020

How about this one:

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

@oatawa1
Copy link
Author

oatawa1 commented Sep 2, 2020

@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?

@Igor1306
Copy link
Contributor

Igor1306 commented Sep 2, 2020

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

@Igor1306
Copy link
Contributor

Igor1306 commented Sep 9, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants