[
https://issues.apache.org/jira/browse/BEAM-8739?focusedWorklogId=353154&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-353154
]
ASF GitHub Bot logged work on BEAM-8739:
----------------------------------------
Author: ASF GitHub Bot
Created on: 04/Dec/19 00:58
Start Date: 04/Dec/19 00:58
Worklog Time Spent: 10m
Work Description: robertwb commented on issue #10149: [BEAM-8739]
Consistently use with Pipeline(...) syntax
URL: https://github.com/apache/beam/pull/10149#issuecomment-561426430
Just a bunch of regular expression munging...
```
import re
import sys
for file in sys.argv[1:]:
with open(file) as fin:
contents = fin.read().split('\n')
new_contents = []
in_pipeline = False
indent = None
converted_pipelines = 0
total_pipelines = 0
for ix, line in enumerate(contents):
if in_pipeline:
if line.startswith('%s%s.run()' % (indent, pipeline_var)):
converted_pipelines += 1
new_contents.append('%swith %s as %s:' % (indent, pipeline_expr,
pipeline_var))
for b in body:
new_contents.append(' ' + b if b.strip() and b[0] != '#' else b)
# if body[-1]:
# new_contents.append('\n')
in_pipeline = False
elif not line.startswith(indent) and line.strip() and not re.match('^
*#', line):
print('END', file, ix, list(filter(lambda x: x, [b.strip() for b in
body]))[-2:])
new_contents.append(pipeline_init)
new_contents.extend(body)
new_contents.append(line)
in_pipeline = False
else:
body.append(line)
else:
m = re.match(r'^( *)(\S+) = (\S*Pipeline[(].*)', line)
if m:
total_pipelines += 1
in_pipeline = True
indent = m.group(1)
pipeline_init = line
pipeline_var = m.group(2)
pipeline_expr = m.group(3)
body = []
else:
new_contents.append(line)
if in_pipeline and body:
new_contents.append(pipeline_init)
new_contents.extend(body)
if new_contents != contents:
with open(file, 'w') as fout:
fout.write('\n'.join(new_contents))
if total_pipelines:
print(file, converted_pipelines, total_pipelines)
print()
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 353154)
Time Spent: 40m (was: 0.5h)
> Consistently use with Pipeline(...) syntax
> ------------------------------------------
>
> Key: BEAM-8739
> URL: https://issues.apache.org/jira/browse/BEAM-8739
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Reporter: Robert Bradshaw
> Assignee: Robert Bradshaw
> Priority: Major
> Time Spent: 40m
> Remaining Estimate: 0h
>
> I've run into a couple of tests that forgot to do p.run(). In addition, I'm
> seeing new tests written in this old style. We should consistently use the
> with syntax where possible for our examples and tests.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)