Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LbDevTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LHCb Core Software
LbDevTools
Commits
aa751c65
Commit
aa751c65
authored
6 years ago
by
Marco Clemencic
Browse files
Options
Downloads
Plain Diff
Merge branch '14-save-python-encoding-declaration' into 'master'
Make sure the copyright is added after the encoding declaration Closes
#14
See merge request
!33
parents
69d3bfbd
645d386b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!33
Make sure the copyright is added after the encoding declaration
Pipeline
#557404
passed
6 years ago
Stage: test
Stage: package
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LbDevTools/CopyrightCheck.py
+17
-1
17 additions, 1 deletion
LbDevTools/CopyrightCheck.py
with
17 additions
and
1 deletion
LbDevTools/CopyrightCheck.py
+
17
−
1
View file @
aa751c65
...
@@ -36,6 +36,9 @@ granted to it by virtue of its status as an Intergovernmental Organization
...
@@ -36,6 +36,9 @@ granted to it by virtue of its status as an Intergovernmental Organization
or submit itself to any jurisdiction.
or submit itself to any jurisdiction.
'''
'''
# see https://www.python.org/dev/peps/pep-0263 for the regex
ENCODING_DECLARATION
=
re
.
compile
(
r
'
^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)
'
)
def
is_script
(
path
):
def
is_script
(
path
):
'''
'''
...
@@ -157,6 +160,16 @@ def lang_family(path):
...
@@ -157,6 +160,16 @@ def lang_family(path):
return
'
#
'
return
'
#
'
def
find_encoding_declaration_line
(
lines
,
limit
=
2
):
'''
Look for encoding declaration line (PEP-263) in a file and return the index
of the line containing it, or None if not found.
'''
for
i
,
l
in
enumerate
(
islice
(
lines
,
limit
)):
if
ENCODING_DECLARATION
.
match
(
l
):
return
i
def
add_copyright_to_file
(
path
,
year
=
None
):
def
add_copyright_to_file
(
path
,
year
=
None
):
'''
'''
Add copyright statement to the given file for the specified year (or range
Add copyright statement to the given file for the specified year (or range
...
@@ -170,7 +183,10 @@ def add_copyright_to_file(path, year=None):
...
@@ -170,7 +183,10 @@ def add_copyright_to_file(path, year=None):
data
=
f
.
readlines
()
data
=
f
.
readlines
()
offset
=
0
offset
=
0
if
data
[
0
].
startswith
(
'
#!
'
):
encoding_offset
=
find_encoding_declaration_line
(
data
)
if
encoding_offset
is
not
None
:
offset
=
encoding_offset
+
1
elif
data
[
0
].
startswith
(
'
#!
'
):
offset
=
1
offset
=
1
elif
lang
==
'
xml
'
:
elif
lang
==
'
xml
'
:
offset
=
1
offset
=
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment