Merge lp:~widelands-dev/widelands-website/pyformat_util into lp:widelands-website

Proposed by GunChleoc
Status: Merged
Merged at revision: 443
Proposed branch: lp:~widelands-dev/widelands-website/pyformat_util
Merge into: lp:widelands-website
Diff against target: 50 lines (+46/-0)
1 file modified
_ops/fix_formatting.py (+46/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/pyformat_util
Reviewer Review Type Date Requested Status
SirVer Approve
kaputtnik (community) Approve
Review via email: mp+312427@code.launchpad.net

Description of the change

Added script to run pyformat over the code base.

In the future, when merging branches into trunk, this could be run before the bzr commit.

To post a comment you must log in.
Revision history for this message
kaputtnik (franku) wrote :

Is this meant to run with python3 or python2?

I put some comments in the diff.

Revision history for this message
kaputtnik (franku) wrote :

Ah, forgotton: Wouldn't it be better to have this script in the _ops directory?

Revision history for this message
GunChleoc (gunchleoc) wrote :

If that directory does the same job as utils does on Widelands, yes.

Revision history for this message
kaputtnik (franku) wrote :

I think '_ops' is meant as 'operators', or as https://de.wikipedia.org/wiki/Ops ?

In both cases it would fit to have this script in '_ops', i believe :-)

440. By GunChleoc

Merged trunk.

441. By GunChleoc

Addressed code review.

Revision history for this message
GunChleoc (gunchleoc) wrote :

OK, moved :)

Revision history for this message
kaputtnik (franku) wrote :

Runs with python3 and python2 now. :-)

I don't know why the PYTHON3=... is still in there? Maybe i miss something here?

review: Approve
Revision history for this message
SirVer (sirver) wrote :

same nit as kaputtnik had, otherwise lgtm.

review: Approve
442. By GunChleoc

Removed superfluous line.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the nit - fixed :)

Revision history for this message
kaputtnik (franku) wrote :

Merged with trunk, ran the script, merged into trunk, deployed.

Thanks for the tool :-)

Revision history for this message
GunChleoc (gunchleoc) wrote :

You're welcome :)

I wanted it for Widelands, so why not have it for the website as well. You made me aware of pyformat in the first place!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '_ops/fix_formatting.py'
2--- _ops/fix_formatting.py 1970-01-01 00:00:00 +0000
3+++ _ops/fix_formatting.py 2016-12-12 15:39:05 +0000
4@@ -0,0 +1,46 @@
5+#!/usr/bin/env python
6+# -*- coding: utf-8 -*-
7+
8+
9+"""This script runs pyformat over the code base.
10+"""
11+
12+import argparse
13+import os
14+import re
15+import sys
16+from subprocess import call
17+
18+def parse_args():
19+ p = argparse.ArgumentParser(
20+ description='Run pyformat over the code base.'
21+ ' Recurses over all relevant files.')
22+ return p.parse_args()
23+
24+
25+def find_files(startpath, extensions):
26+ for (dirpath, _, filenames) in os.walk(startpath):
27+ for filename in filenames:
28+ if os.path.splitext(filename)[-1].lower() in extensions:
29+ yield os.path.join(dirpath, filename)
30+
31+
32+def main():
33+ parse_args()
34+
35+ if not os.path.isdir('pybb') or not os.path.isdir('_ops'):
36+ print('CWD is not the root of the repository.')
37+ return 1
38+
39+ sys.stdout.write('\nFormatting Python code ')
40+ for filename in find_files('.', ['.py']):
41+ sys.stdout.write('.')
42+ sys.stdout.flush()
43+ call(['pyformat', '-i', filename])
44+ print(' done.')
45+
46+ print ('Formatting finished.')
47+ return 0
48+
49+if __name__ == '__main__':
50+ sys.exit(main())

Subscribers

People subscribed via source and target branches