@@ -21,10 +21,11 @@ def should_process_file(config_file, name):
21
21
or name .endswith (".java" )
22
22
) and not license_regex .search (name )
23
23
24
- def __try_regex (self , lines , last_year , license_template ):
24
+ def __try_regex (self , repo_relative_name , lines , last_year , license_template ):
25
25
"""Try finding license with regex of license template.
26
26
27
27
Keyword arguments:
28
+ repo_relative_name -- repo-relative filename
28
29
lines -- lines of file
29
30
last_year -- last year in copyright range
30
31
license_template -- license_template string
@@ -44,6 +45,7 @@ def __try_regex(self, lines, last_year, license_template):
44
45
.replace (")" , r"\)" )
45
46
.replace ("{year}" , r"(?P<year>[0-9]+)(-[0-9]+)?" )
46
47
.replace ("{padding}" , "[ ]*" )
48
+ .replace ("{filename}" , "" )
47
49
)
48
50
license_rgx = regex .compile (license_rgxstr , regex .M )
49
51
@@ -135,6 +137,8 @@ def __try_string_search(self, lines, last_year, license_template):
135
137
def run_pipeline (self , config_file , name , lines ):
136
138
linesep = super ().get_linesep (lines )
137
139
140
+ repo_relative_name = name [len (Task .get_repo_root ()) + 1 :]
141
+
138
142
_ , license_template = Config .read_file (
139
143
os .path .dirname (os .path .abspath (name )), ".styleguide-license"
140
144
)
@@ -160,7 +164,7 @@ def run_pipeline(self, config_file, name, lines):
160
164
last_year = str (date .today ().year )
161
165
162
166
success , first_year , appendix = self .__try_regex (
163
- lines , last_year , license_template
167
+ repo_relative_name , lines , last_year , license_template
164
168
)
165
169
if not success :
166
170
success , first_year , appendix = self .__try_string_search (
@@ -179,6 +183,9 @@ def run_pipeline(self, config_file, name, lines):
179
183
# Insert copyright year range
180
184
line = line .replace ("{year}" , year_range )
181
185
186
+ # Insert filename
187
+ line = line .replace ("{filename}" , repo_relative_name )
188
+
182
189
# Insert padding which expands to the 80th column. If there is more
183
190
# than one padding token, the line may contain fewer than 80
184
191
# characters due to rounding during the padding width calculation.
0 commit comments