Skip to content

Commit

Permalink
gyp: Improve our flake8 linting tests
Browse files Browse the repository at this point in the history
PR-URL: #2356
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
  • Loading branch information
cclauss authored and gengjiawen committed Mar 31, 2021
1 parent 06ddde2 commit 0093ec8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TODO: Line 47, enable pytest --doctest-modules
# TODO: Line 43, enable pytest --doctest-modules

name: Tests
on: [push, pull_request]
Expand Down Expand Up @@ -36,16 +36,10 @@ jobs:
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
- name: Lint Python
if: matrix.os == 'ubuntu-latest'
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
- name: Run Python tests
run: |
python -m pytest
run: python -m pytest
# - name: Run doctests with pytest
# run: python -m pytest --doctest-modules
- name: Run Node tests
run: |
npm test
run: npm test
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3276,9 +3276,9 @@ def GetEdges(node):
# append to the default value. I.e. PATH=$(PATH);other_path
edges.update(
{
v
for v in MSVS_VARIABLE_REFERENCE.findall(value)
if v in properties and v != node
v
for v in MSVS_VARIABLE_REFERENCE.findall(value)
if v in properties and v != node
}
)
return edges
Expand Down
40 changes: 21 additions & 19 deletions test/fixtures/test-charmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
import locale

try:
reload(sys)
reload(sys)
except NameError: # Python 3
pass
pass


def main():
encoding = locale.getdefaultlocale()[1]
if not encoding:
return False
encoding = locale.getdefaultlocale()[1]
if not encoding:
return False

try:
sys.setdefaultencoding(encoding)
except AttributeError: # Python 3
pass
try:
sys.setdefaultencoding(encoding)
except AttributeError: # Python 3
pass

textmap = {
"cp936": "\u4e2d\u6587",
"cp1252": "Lat\u012Bna",
"cp932": "\u306b\u307b\u3093\u3054",
}
if encoding in textmap:
print(textmap[encoding])
return True

textmap = {
'cp936': '\u4e2d\u6587',
'cp1252': 'Lat\u012Bna',
'cp932': '\u306b\u307b\u3093\u3054'
}
if encoding in textmap:
print(textmap[encoding])
return True

if __name__ == '__main__':
print(main())
if __name__ == "__main__":
print(main())
39 changes: 20 additions & 19 deletions update-gyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import os
import shutil
import subprocess
import sys
import tarfile
import tempfile
import urllib.request

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

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

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

with tempfile.TemporaryDirectory() as tmp_dir:
tar_file = os.path.join(tmp_dir, 'gyp.tar.gz')
unzip_target = os.path.join(tmp_dir, 'gyp')
with open(tar_file, 'wb') as f:
print("Downloading gyp-next@" + args.tag + " into temporary directory...")
print("From: " + tar_url)
with urllib.request.urlopen(tar_url) as in_file:
f.write(in_file.read())

print("Unzipping...")
with tarfile.open(tar_file, "r:gz") as tar_ref:
tar_ref.extractall(unzip_target)

print("Moving to current checkout (" + CHECKOUT_PATH + ")...")
if os.path.exists(CHECKOUT_GYP_PATH):
shutil.rmtree(CHECKOUT_GYP_PATH)
shutil.move(os.path.join(unzip_target, os.listdir(unzip_target)[0]), CHECKOUT_GYP_PATH)
tar_file = os.path.join(tmp_dir, "gyp.tar.gz")
unzip_target = os.path.join(tmp_dir, "gyp")
with open(tar_file, "wb") as f:
print("Downloading gyp-next@" + args.tag + " into temporary directory...")
print("From: " + tar_url)
with urllib.request.urlopen(tar_url) as in_file:
f.write(in_file.read())

print("Unzipping...")
with tarfile.open(tar_file, "r:gz") as tar_ref:
tar_ref.extractall(unzip_target)

print("Moving to current checkout (" + CHECKOUT_PATH + ")...")
if os.path.exists(CHECKOUT_GYP_PATH):
shutil.rmtree(CHECKOUT_GYP_PATH)
shutil.move(
os.path.join(unzip_target, os.listdir(unzip_target)[0]), CHECKOUT_GYP_PATH
)

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

0 comments on commit 0093ec8

Please sign in to comment.