Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve our flake8 linting tests #2356

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
gengjiawen marked this conversation as resolved.
Show resolved Hide resolved
- 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
Comment on lines -3279 to +3281
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation change looks correct, but it would be good to upstream it to gyp-next. (Or it will get overwritten next time node-gyp syncs with gyp-next again.)

(Seems like it was mixing indentation of 4 spaces and 8 spaces before. Now it's consistently 4 spaces. 👍 on the change.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
)
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])