Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ python setup.py develop
python -m pytest # Run the tests without IPython.
pip install ipython
python -m pytest # Now run the tests with IPython.
pylint fire --ignore=test_components_py3.py,parser_fuzz_test.py,console
pre-commit run --all-files --show-diff-on-failure --
if [[ ${PYTHON_VERSION} == 3.7 ]]; then
# Run type-checking.
pip install pytype;
Expand Down
3 changes: 1 addition & 2 deletions .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
setuptools <=75.6.0
pip
pylint <3.3.2
pre-commit
pytest <=8.3.3
pytest-pylint <=1.1.2
pytest-runner <7.0.0
termcolor <2.6.0
hypothesis <6.123.0
Expand Down
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
default_language_version:
python: python3

#ci:
# autofix_prs: true
# autoupdate_commit_msg: "[pre-commit.ci] pre-commit suggestions"
# autoupdate_schedule: quarterly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
- id: check-yaml
- id: check-toml
- id: detect-private-key

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
# try to fix what is possible
- id: ruff
args: ["--fix"]
# perform formatting updates
#- id: ruff-format
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ Then run the tests by running `pytest` in the root directory of the repository.
## Linting

Please run lint on your pull requests to make accepting the requests easier.
To do this, run `pylint fire` in the root directory of the repository.
To do this, run `pre-commit run --all-files` in the root directory of the repository.
Note that even if lint is passing, additional style changes to your submission
may be made during merging.
6 changes: 3 additions & 3 deletions fire/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=invalid-name

"""Enables use of Python Fire as a "main" function (i.e. "python -m fire").

This allows using Fire with third-party libraries without modifying their code.
Expand Down Expand Up @@ -63,8 +63,8 @@ def import_from_file_path(path):
if spec is None:
raise OSError('Unable to load module from specified path.')

module = util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module) # pytype: disable=attribute-error
module = util.module_from_spec(spec)
spec.loader.exec_module(module)

return module, module_name

Expand Down
5 changes: 2 additions & 3 deletions fire/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def _BashScript(name, commands, default_options=None):
def _GetOptsAssignmentTemplate(command):
if command == name:
return opts_assignment_main_command_template
else:
return opts_assignment_subcommand_template
return opts_assignment_subcommand_template

lines = []
commands_set = set()
Expand Down Expand Up @@ -281,7 +280,7 @@ def _FishScript(name, commands, default_options=None):
)


def MemberVisible(component, name, member, class_attrs=None, verbose=False):
def MemberVisible(component, name, member, class_attrs=None, verbose=False): # noqa: C901
"""Returns whether a member should be included in auto-completion or help.

Determines whether a member of an object with the specified name should be
Expand Down
4 changes: 2 additions & 2 deletions fire/completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def testCompletionBashScript(self):
['halt'],
['halt', '--now'],
]
script = completion._BashScript(name='command', commands=commands) # pylint: disable=protected-access
script = completion._BashScript(name='command', commands=commands)
self.assertIn('command', script)
self.assertIn('halt', script)

Expand All @@ -44,7 +44,7 @@ def testCompletionFishScript(self):
['halt'],
['halt', '--now'],
]
script = completion._FishScript(name='command', commands=commands) # pylint: disable=protected-access
script = completion._FishScript(name='command', commands=commands)
self.assertIn('command', script)
self.assertIn('halt', script)
self.assertIn('-l now', script)
Expand Down
15 changes: 7 additions & 8 deletions fire/console/console_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _GetConsoleEncoding(self):
console_encoding = console_encoding.lower()
if 'utf-8' in console_encoding:
return 'utf8'
elif 'cp437' in console_encoding:
if 'cp437' in console_encoding:
return 'cp437'
return None

Expand Down Expand Up @@ -649,15 +649,15 @@ def GetConsoleAttr(encoding=None, reset=False):
Returns:
The global ConsoleAttr state object.
"""
attr = ConsoleAttr._CONSOLE_ATTR_STATE # pylint: disable=protected-access
attr = ConsoleAttr._CONSOLE_ATTR_STATE
if not reset:
if not attr:
reset = True
elif encoding and encoding != attr.GetEncoding():
reset = True
if reset:
attr = ConsoleAttr(encoding=encoding)
ConsoleAttr._CONSOLE_ATTR_STATE = attr # pylint: disable=protected-access
ConsoleAttr._CONSOLE_ATTR_STATE = attr
return attr


Expand Down Expand Up @@ -700,15 +700,14 @@ def GetCharacterDisplayWidth(char):
if unicodedata.combining(char) != 0:
# Modifies the previous character and does not move the cursor.
return 0
elif unicodedata.category(char) == 'Cf':
if unicodedata.category(char) == 'Cf':
# Unprintable formatting char.
return 0
elif unicodedata.east_asian_width(char) in 'FW':
if unicodedata.east_asian_width(char) in 'FW':
# Fullwidth or Wide chars take 2 character positions.
return 2
else:
# Don't use this function on control chars.
return 1
# Don't use this function on control chars.
return 1


def SafeText(data, encoding=None, escape=True):
Expand Down
26 changes: 13 additions & 13 deletions fire/console/console_attr_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ def GetTermSize():
xy = get_terminal_size()
if xy:
break
except: # pylint: disable=bare-except
except: # noqa: E722
pass
return xy or (80, 24)


def _GetTermSizePosix():
"""Returns the Posix terminal x and y dimensions."""
# pylint: disable=g-import-not-at-top

import fcntl
# pylint: disable=g-import-not-at-top

import struct
# pylint: disable=g-import-not-at-top

import termios

def _GetXY(fd):
Expand All @@ -75,7 +75,7 @@ def _GetXY(fd):
# binary shorts to a (rows, columns) int tuple.
rc = struct.unpack(b'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'junk'))
return (rc[1], rc[0]) if rc else None
except: # pylint: disable=bare-except
except: # noqa: E722
return None

xy = _GetXY(0) or _GetXY(1) or _GetXY(2)
Expand All @@ -84,7 +84,7 @@ def _GetXY(fd):
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
xy = _GetXY(fd)
except: # pylint: disable=bare-except
except: # noqa: E722
xy = None
finally:
if fd is not None:
Expand All @@ -96,7 +96,7 @@ def _GetTermSizeWindows():
"""Returns the Windows terminal x and y dimensions."""
# pylint:disable=g-import-not-at-top
import struct
# pylint: disable=g-import-not-at-top

from ctypes import create_string_buffer
# pylint:disable=g-import-not-at-top
from ctypes import windll
Expand Down Expand Up @@ -124,7 +124,7 @@ def _GetTermSizeEnvironment():

def _GetTermSizeTput():
"""Returns the terminal x and y dimensions from tput(1)."""
import subprocess # pylint: disable=g-import-not-at-top
import subprocess
output = encoding.Decode(subprocess.check_output(['tput', 'cols'],
stderr=subprocess.STDOUT))
cols = int(output)
Expand Down Expand Up @@ -153,16 +153,16 @@ def GetRawKeyFunction():
_GetRawKeyFunctionWindows):
try:
return get_raw_key_function()
except: # pylint: disable=bare-except
except: # noqa: E722
pass
return lambda: None


def _GetRawKeyFunctionPosix():
"""_GetRawKeyFunction helper using Posix APIs."""
# pylint: disable=g-import-not-at-top

import tty
# pylint: disable=g-import-not-at-top

import termios

def _GetRawKeyPosix():
Expand Down Expand Up @@ -212,7 +212,7 @@ def _GetKeyChar():
c = prev_c
break
return ansi_to_key.get(c, '')
except: # pylint:disable=bare-except
except: # noqa: E722
c = None
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
Expand All @@ -223,7 +223,7 @@ def _GetKeyChar():

def _GetRawKeyFunctionWindows():
"""_GetRawKeyFunction helper using Windows APIs."""
# pylint: disable=g-import-not-at-top

import msvcrt

def _GetRawKeyWindows():
Expand Down
4 changes: 2 additions & 2 deletions fire/console/console_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _Help(self):
self._attr.GetRawKey()
self._Write('\n')

def Run(self):
def Run(self): # noqa: C901
"""Run the pager."""
# No paging if the contents are small enough.
if len(self._lines) <= self._height:
Expand Down Expand Up @@ -215,7 +215,7 @@ def Run(self):
):
# Quit.
return
elif c in ('/', '?'):
if c in ('/', '?'):
c = self._GetSearchCommand(c)
elif c.isdigit():
# Collect digits for operation count.
Expand Down
4 changes: 2 additions & 2 deletions fire/console/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def Decode(data, encoding=None):

# Try the filesystem encoding.
try:
return string.decode(sys.getfilesystemencoding()) # pytype: disable=attribute-error
return string.decode(sys.getfilesystemencoding()) # pytype: disable=attribute-error, # noqa: E501
except UnicodeError:
# string is not encoded for filesystem paths.
pass

# Try the system default encoding.
try:
return string.decode(sys.getdefaultencoding()) # pytype: disable=attribute-error
return string.decode(sys.getdefaultencoding()) # pytype: disable=attribute-error, # noqa: E501
except UnicodeError:
# string is not encoded using the default encoding.
pass
Expand Down
3 changes: 1 addition & 2 deletions fire/console/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def _FindExecutableOnPath(executable, path, pathext):
def _PlatformExecutableExtensions(platform):
if platform == platforms.OperatingSystem.WINDOWS:
return ('.exe', '.cmd', '.bat', '.com', '.ps1')
else:
return ('', '.sh')
return ('', '.sh')


def FindExecutableOnPath(executable, path=None, pathext=None,
Expand Down
28 changes: 13 additions & 15 deletions fire/console/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Error(Exception):
pass


class InvalidEnumValue(Error): # pylint: disable=g-bad-exception-name
class InvalidEnumValue(Error):
"""Exception for when a string could not be parsed to a valid enum value."""

def __init__(self, given, enum_type, options):
Expand All @@ -53,7 +53,7 @@ class OperatingSystem(object):
class _OS(object):
"""A single operating system."""

# pylint: disable=redefined-builtin

def __init__(self, id, name, file_name):
self.id = id
self.name = name
Expand Down Expand Up @@ -147,13 +147,13 @@ def Current():
"""
if os.name == 'nt':
return OperatingSystem.WINDOWS
elif 'linux' in sys.platform:
if 'linux' in sys.platform:
return OperatingSystem.LINUX
elif 'darwin' in sys.platform:
if 'darwin' in sys.platform:
return OperatingSystem.MACOSX
elif 'cygwin' in sys.platform:
if 'cygwin' in sys.platform:
return OperatingSystem.CYGWIN
elif 'msys' in sys.platform:
if 'msys' in sys.platform:
return OperatingSystem.MSYS
return None

Expand All @@ -169,7 +169,7 @@ class Architecture(object):
class _ARCH(object):
"""A single architecture."""

# pylint: disable=redefined-builtin

def __init__(self, id, name, file_name):
self.id = id
self.name = name
Expand Down Expand Up @@ -323,12 +323,12 @@ def UserAgentFragment(self):
# '#1 SMP Tue May 21 02:35:06 PDT 2013', 'x86_64', 'x86_64')
return '({name} {version})'.format(
name=self.operating_system.name, version=platform.release())
elif self.operating_system == OperatingSystem.WINDOWS:
if self.operating_system == OperatingSystem.WINDOWS:
# ('Windows', '<hostname goes here>', '7', '6.1.7601', 'AMD64',
# 'Intel64 Family 6 Model 45 Stepping 7, GenuineIntel')
return '({name} NT {version})'.format(
name=self.operating_system.name, version=platform.version())
elif self.operating_system == OperatingSystem.MACOSX:
if self.operating_system == OperatingSystem.MACOSX:
# ('Darwin', '<hostname goes here>', '12.4.0',
# 'Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013;
# root:xnu-2050.24.15~1/RELEASE_X86_64', 'x86_64', 'i386')
Expand All @@ -337,8 +337,7 @@ def UserAgentFragment(self):
if self.architecture == Architecture.ppc else 'Intel')
return format_string.format(
name=arch_string, version=platform.release())
else:
return '()'
return '()'

def AsyncPopenArgs(self):
"""Returns the args for spawning an async process using Popen on this OS.
Expand Down Expand Up @@ -413,10 +412,9 @@ def SupportedVersionMessage(self, allow_py3):
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1],
PythonVersion.MIN_SUPPORTED_PY3_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY3_VERSION[1])
else:
return 'Please use Python version {0}.{1}.x.'.format(
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1])
return 'Please use Python version {0}.{1}.x.'.format(
PythonVersion.MIN_SUPPORTED_PY2_VERSION[0],
PythonVersion.MIN_SUPPORTED_PY2_VERSION[1])

def IsCompatible(self, allow_py3=False, raise_exception=False):
"""Ensure that the Python version we are using is compatible.
Expand Down
1 change: 0 additions & 1 deletion fire/console/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ class TextTypes(_TextTypes):
OUTPUT = 7
PT_SUCCESS = 8
PT_FAILURE = 9

Loading
Loading