Skip to content

Commit 7620c6b

Browse files
committed
gyp: Improve our flake8 linting tests
PR-URL: nodejs#2356 Reviewed-By: Jiawen Geng <[email protected]>
1 parent 06ddde2 commit 7620c6b

File tree

4 files changed

+48
-51
lines changed

4 files changed

+48
-51
lines changed

.github/workflows/tests.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TODO: Line 47, enable pytest --doctest-modules
1+
# TODO: Line 43, enable pytest --doctest-modules
22

33
name: Tests
44
on: [push, pull_request]
@@ -36,16 +36,10 @@ jobs:
3636
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
3737
- name: Lint Python
3838
if: matrix.os == 'ubuntu-latest'
39-
run: |
40-
# stop the build if there are Python syntax errors or undefined names
41-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
42-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
43-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39+
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
4440
- name: Run Python tests
45-
run: |
46-
python -m pytest
41+
run: python -m pytest
4742
# - name: Run doctests with pytest
4843
# run: python -m pytest --doctest-modules
4944
- name: Run Node tests
50-
run: |
51-
npm test
45+
run: npm test

gyp/pylib/gyp/generator/msvs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3276,9 +3276,9 @@ def GetEdges(node):
32763276
# append to the default value. I.e. PATH=$(PATH);other_path
32773277
edges.update(
32783278
{
3279-
v
3280-
for v in MSVS_VARIABLE_REFERENCE.findall(value)
3281-
if v in properties and v != node
3279+
v
3280+
for v in MSVS_VARIABLE_REFERENCE.findall(value)
3281+
if v in properties and v != node
32823282
}
32833283
)
32843284
return edges

test/fixtures/test-charmap.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22
import locale
33

44
try:
5-
reload(sys)
5+
reload(sys)
66
except NameError: # Python 3
7-
pass
7+
pass
8+
89

910
def main():
10-
encoding = locale.getdefaultlocale()[1]
11-
if not encoding:
12-
return False
11+
encoding = locale.getdefaultlocale()[1]
12+
if not encoding:
13+
return False
1314

14-
try:
15-
sys.setdefaultencoding(encoding)
16-
except AttributeError: # Python 3
17-
pass
15+
try:
16+
sys.setdefaultencoding(encoding)
17+
except AttributeError: # Python 3
18+
pass
19+
20+
textmap = {
21+
"cp936": "\u4e2d\u6587",
22+
"cp1252": "Lat\u012Bna",
23+
"cp932": "\u306b\u307b\u3093\u3054",
24+
}
25+
if encoding in textmap:
26+
print(textmap[encoding])
27+
return True
1828

19-
textmap = {
20-
'cp936': '\u4e2d\u6587',
21-
'cp1252': 'Lat\u012Bna',
22-
'cp932': '\u306b\u307b\u3093\u3054'
23-
}
24-
if encoding in textmap:
25-
print(textmap[encoding])
26-
return True
2729

28-
if __name__ == '__main__':
29-
print(main())
30+
if __name__ == "__main__":
31+
print(main())

update-gyp.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import os
55
import shutil
66
import subprocess
7-
import sys
87
import tarfile
98
import tempfile
109
import urllib.request
1110

1211
BASE_URL = "https://github.com/nodejs/gyp-next/archive/"
1312
CHECKOUT_PATH = os.path.dirname(os.path.realpath(__file__))
14-
CHECKOUT_GYP_PATH = os.path.join(CHECKOUT_PATH, 'gyp')
13+
CHECKOUT_GYP_PATH = os.path.join(CHECKOUT_PATH, "gyp")
1514

1615
parser = argparse.ArgumentParser()
1716
parser.add_argument("tag", help="gyp tag to update to")
@@ -21,25 +20,27 @@
2120

2221
changed_files = subprocess.check_output(["git", "diff", "--name-only"]).strip()
2322
if changed_files:
24-
raise Exception("Can't update gyp while you have uncommitted changes in node-gyp")
23+
raise Exception("Can't update gyp while you have uncommitted changes in node-gyp")
2524

2625
with tempfile.TemporaryDirectory() as tmp_dir:
27-
tar_file = os.path.join(tmp_dir, 'gyp.tar.gz')
28-
unzip_target = os.path.join(tmp_dir, 'gyp')
29-
with open(tar_file, 'wb') as f:
30-
print("Downloading gyp-next@" + args.tag + " into temporary directory...")
31-
print("From: " + tar_url)
32-
with urllib.request.urlopen(tar_url) as in_file:
33-
f.write(in_file.read())
34-
35-
print("Unzipping...")
36-
with tarfile.open(tar_file, "r:gz") as tar_ref:
37-
tar_ref.extractall(unzip_target)
38-
39-
print("Moving to current checkout (" + CHECKOUT_PATH + ")...")
40-
if os.path.exists(CHECKOUT_GYP_PATH):
41-
shutil.rmtree(CHECKOUT_GYP_PATH)
42-
shutil.move(os.path.join(unzip_target, os.listdir(unzip_target)[0]), CHECKOUT_GYP_PATH)
26+
tar_file = os.path.join(tmp_dir, "gyp.tar.gz")
27+
unzip_target = os.path.join(tmp_dir, "gyp")
28+
with open(tar_file, "wb") as f:
29+
print("Downloading gyp-next@" + args.tag + " into temporary directory...")
30+
print("From: " + tar_url)
31+
with urllib.request.urlopen(tar_url) as in_file:
32+
f.write(in_file.read())
33+
34+
print("Unzipping...")
35+
with tarfile.open(tar_file, "r:gz") as tar_ref:
36+
tar_ref.extractall(unzip_target)
37+
38+
print("Moving to current checkout (" + CHECKOUT_PATH + ")...")
39+
if os.path.exists(CHECKOUT_GYP_PATH):
40+
shutil.rmtree(CHECKOUT_GYP_PATH)
41+
shutil.move(
42+
os.path.join(unzip_target, os.listdir(unzip_target)[0]), CHECKOUT_GYP_PATH
43+
)
4344

4445
subprocess.check_output(["git", "add", "gyp"], cwd=CHECKOUT_PATH)
4546
subprocess.check_output(["git", "commit", "-m", "gyp: update gyp to " + args.tag])

0 commit comments

Comments
 (0)