Skip to content

Commit

Permalink
Fix recent python linting errors
Browse files Browse the repository at this point in the history
- Remove unneeded imports in 'fuscia-test-runner.py'
- Add explicit stacklevel to 'x.py'
- Fix mutable types as default args in `bootstrap.py` and  `bootstrap_test.py`
  • Loading branch information
tgross35 committed Aug 2, 2023
1 parent efc49e4 commit 9df0f5d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ def __init__(self):

class RustBuild(object):
"""Provide all the methods required to build Rust"""
def __init__(self, config_toml="", args=FakeArgs()):
def __init__(self, config_toml="", args=None):
if args is None:
args = FakeArgs()
self.git_version = None
self.nix_deps_dir = None
self._should_fix_bins_and_dylibs = None
Expand Down
19 changes: 14 additions & 5 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from __future__ import absolute_import, division, print_function
import os
import doctest
import unittest
import tempfile
import hashlib
Expand All @@ -16,12 +15,15 @@
bootstrap_dir = os.path.dirname(os.path.abspath(__file__))
# For the import below, have Python search in src/bootstrap first.
sys.path.insert(0, bootstrap_dir)
import bootstrap
import configure
import bootstrap # noqa: E402
import configure # noqa: E402

def serialize_and_parse(configure_args, bootstrap_args=bootstrap.FakeArgs()):
def serialize_and_parse(configure_args, bootstrap_args=None):
from io import StringIO

if bootstrap_args is None:
bootstrap_args = bootstrap.FakeArgs()

section_order, sections, targets = configure.parse_args(configure_args)
buffer = StringIO()
configure.write_config_toml(buffer, section_order, targets, sections)
Expand Down Expand Up @@ -129,7 +131,14 @@ def test_set_codegen_backends(self):
class BuildBootstrap(unittest.TestCase):
"""Test that we generate the appropriate arguments when building bootstrap"""

def build_args(self, configure_args=[], args=[], env={}):
def build_args(self, configure_args=None, args=None, env=None):
if configure_args is None:
configure_args = []
if args is None:
args = []
if env is None:
env = {}

env = env.copy()
env["PATH"] = os.environ["PATH"]

Expand Down
6 changes: 2 additions & 4 deletions src/ci/docker/scripts/fuchsia-test-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
import json
import os
import platform
import re
import shutil
import signal
import subprocess
import sys
from typing import ClassVar, List, Optional
from typing import ClassVar, List


@dataclass
Expand Down Expand Up @@ -523,7 +521,7 @@ def log(msg):
env_vars += '\n "RUST_BACKTRACE=0",'

# Use /tmp as the test temporary directory
env_vars += f'\n "RUST_TEST_TMPDIR=/tmp",'
env_vars += '\n "RUST_TEST_TMPDIR=/tmp",'

cml.write(
self.CML_TEMPLATE.format(env_vars=env_vars, exe_name=exe_name)
Expand Down
2 changes: 1 addition & 1 deletion x.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1`
""".format(major, minor))
warnings.warn(msg)
warnings.warn(msg, stacklevel=1)

rust_dir = os.path.dirname(os.path.abspath(__file__))
# For the import below, have Python search in src/bootstrap first.
Expand Down

0 comments on commit 9df0f5d

Please sign in to comment.