Skip to content

Commit 2b0ebfa

Browse files
authored
Merge branch 'master' into bug-fix-typing-package
2 parents 9bc2ad3 + efcf60f commit 2b0ebfa

51 files changed

Lines changed: 250 additions & 533 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ updates:
77
directory: ".github/scripts/"
88
schedule:
99
interval: "monthly"
10-
labels: ["ci"]
10+
labels: ["dependabot"]
1111
pull-request-branch-name:
1212
separator: "-"
1313
open-pull-requests-limit: 5
@@ -23,7 +23,7 @@ updates:
2323
gh-actions:
2424
patterns:
2525
- "*" # Check all dependencies
26-
labels: ["ci"]
26+
labels: ["dependabot"]
2727
pull-request-branch-name:
2828
separator: "-"
2929
open-pull-requests-limit: 5

.github/scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Exit when any command fails.
1818
set -e
1919

20-
PYTHON_VERSION=${PYTHON_VERSION:-2.7}
20+
PYTHON_VERSION=${PYTHON_VERSION:-3.7}
2121

2222
pip install -U -r .github/scripts/requirements.txt
2323
python setup.py develop

.github/scripts/requirements.txt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
setuptools <65.7.0 ; python_version == '2.7'
2-
setuptools <=69.2.0 ; python_version >= '3.8'
3-
pip <23.0 ; python_version == '2.7'
4-
pip ; python_version >= '3.5'
5-
pylint <2.15.10
6-
pytest <=8.1.1
1+
setuptools <=75.1.0
2+
pip
3+
pylint <3.2.8
4+
pytest <=8.3.3
75
pytest-pylint <=1.1.2
86
pytest-runner <7.0.0
97
termcolor <2.5.0
10-
hypothesis <6.101.0
11-
python-Levenshtein <0.20.9 ; python_version == '2.7'
12-
levenshtein <=0.25.0 ; python_version >= '3.5'
13-
mock <6.0.0
8+
hypothesis <6.113.0
9+
levenshtein <=0.26.0

.github/workflows/build.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
name: Python Fire
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
build:
713
runs-on: ubuntu-20.04
814
strategy:
915
matrix:
10-
python-version: ["3.5", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
16+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13.0-rc.2"]
1117

1218
steps:
1319
# Checkout the repo.

docs/guide.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ the program to the command line.
3030
import fire
3131

3232
def hello(name):
33-
return 'Hello {name}!'.format(name=name)
33+
return f'Hello {name}!'
3434

3535
if __name__ == '__main__':
3636
fire.Fire()
@@ -52,7 +52,7 @@ command line.
5252
import fire
5353

5454
def hello(name):
55-
return 'Hello {name}!'.format(name=name)
55+
return f'Hello {name}!'
5656

5757
if __name__ == '__main__':
5858
fire.Fire(hello)
@@ -76,7 +76,7 @@ We can alternatively write this program like this:
7676
import fire
7777

7878
def hello(name):
79-
return 'Hello {name}!'.format(name=name)
79+
return f'Hello {name}!'
8080

8181
def main():
8282
fire.Fire(hello)
@@ -93,7 +93,7 @@ then simply this:
9393
import fire
9494

9595
def hello(name):
96-
return 'Hello {name}!'.format(name=name)
96+
return f'Hello {name}!'
9797

9898
def main():
9999
fire.Fire(hello)
@@ -105,7 +105,7 @@ If you have a file `example.py` that doesn't even import fire:
105105

106106
```python
107107
def hello(name):
108-
return 'Hello {name}!'.format(name=name)
108+
return f'Hello {name}!'
109109
```
110110

111111
Then you can use it with Fire like this:
@@ -589,6 +589,25 @@ default values that you don't want to specify. It is also important to remember
589589
to change the separator if you want to pass `-` as an argument.
590590

591591

592+
##### Async Functions
593+
594+
Fire supports calling async functions too. Here's a simple example.
595+
596+
```python
597+
import asyncio
598+
599+
async def count_to_ten():
600+
for i in range(1, 11):
601+
await asyncio.sleep(1)
602+
print(i)
603+
604+
if __name__ == '__main__':
605+
fire.Fire(count_to_ten)
606+
```
607+
608+
Whenever fire encounters a coroutine function, it runs it, blocking until it completes.
609+
610+
592611
### Argument Parsing
593612

594613
The types of the arguments are determined by their values, rather than by the

examples/widget/widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def whack(self, n=1):
2525

2626
def bang(self, noise='bang'):
2727
"""Makes a loud noise."""
28-
return '{noise} bang!'.format(noise=noise)
28+
return f'{noise} bang!'
2929

3030

3131
def main():

fire/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
"""The Python Fire module."""
1616

17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
20-
2117
from fire.core import Fire
2218

2319
__all__ = ['Fire']
24-
__version__ = '0.6.0'
20+
__version__ = '0.7.0'

fire/__main__.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
This allows using Fire with third-party libraries without modifying their code.
1919
"""
2020

21-
from __future__ import absolute_import
22-
from __future__ import division
23-
from __future__ import print_function
24-
2521
import importlib
22+
from importlib import util
2623
import os
2724
import sys
2825

@@ -57,31 +54,17 @@ def import_from_file_path(path):
5754
"""
5855

5956
if not os.path.exists(path):
60-
raise IOError('Given file path does not exist.')
57+
raise OSError('Given file path does not exist.')
6158

6259
module_name = os.path.basename(path)
6360

64-
if sys.version_info.major == 3 and sys.version_info.minor < 5:
65-
loader = importlib.machinery.SourceFileLoader( # pylint: disable=no-member
66-
fullname=module_name,
67-
path=path,
68-
)
69-
70-
module = loader.load_module(module_name) # pylint: disable=deprecated-method
71-
72-
elif sys.version_info.major == 3:
73-
from importlib import util # pylint: disable=g-import-not-at-top,import-outside-toplevel,no-name-in-module
74-
spec = util.spec_from_file_location(module_name, path)
75-
76-
if spec is None:
77-
raise IOError('Unable to load module from specified path.')
61+
spec = util.spec_from_file_location(module_name, path)
7862

79-
module = util.module_from_spec(spec) # pylint: disable=no-member
80-
spec.loader.exec_module(module) # pytype: disable=attribute-error
63+
if spec is None:
64+
raise OSError('Unable to load module from specified path.')
8165

82-
else:
83-
import imp # pylint: disable=g-import-not-at-top,import-outside-toplevel,deprecated-module,import-error
84-
module = imp.load_source(module_name, path)
66+
module = util.module_from_spec(spec) # pylint: disable=no-member
67+
spec.loader.exec_module(module) # pytype: disable=attribute-error
8568

8669
return module, module_name
8770

@@ -121,7 +104,7 @@ def import_module(module_or_filename):
121104
return import_from_file_path(module_or_filename)
122105

123106
if os.path.sep in module_or_filename: # Use / to detect if it was a filename.
124-
raise IOError('Fire was passed a filename which could not be found.')
107+
raise OSError('Fire was passed a filename which could not be found.')
125108

126109
return import_from_module_name(module_or_filename) # Assume it's a module.
127110

fire/completion.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import inspect
2424

2525
from fire import inspectutils
26-
import six
2726

2827

2928
def Script(name, component, default_options=None, shell='bash'):
@@ -278,10 +277,7 @@ def _FishScript(name, commands, default_options=None):
278277
)
279278

280279
return fish_source.format(
281-
global_options=' '.join(
282-
'"{option}"'.format(option=option)
283-
for option in global_options
284-
)
280+
global_options=' '.join(f'"{option}"' for option in global_options)
285281
)
286282

287283

@@ -308,18 +304,19 @@ def MemberVisible(component, name, member, class_attrs=None, verbose=False):
308304
Returns
309305
A boolean value indicating whether the member should be included.
310306
"""
311-
if isinstance(name, six.string_types) and name.startswith('__'):
307+
if isinstance(name, str) and name.startswith('__'):
312308
return False
313309
if verbose:
314310
return True
315311
if (member is absolute_import
316312
or member is division
317313
or member is print_function):
318314
return False
319-
if isinstance(member, type(absolute_import)) and six.PY34:
315+
if isinstance(member, type(absolute_import)):
320316
return False
321-
if inspect.ismodule(member) and member is six:
322-
# TODO(dbieber): Determine more generally which modules to hide.
317+
# TODO(dbieber): Determine more generally which modules to hide.
318+
modules_to_hide = []
319+
if inspect.ismodule(member) and member in modules_to_hide:
323320
return False
324321
if inspect.isclass(component):
325322
# If class_attrs has not been provided, compute it.
@@ -336,14 +333,7 @@ def MemberVisible(component, name, member, class_attrs=None, verbose=False):
336333
tuplegetter = getattr(collections, '_tuplegetter', type(None))
337334
if isinstance(class_attr.object, tuplegetter):
338335
return False
339-
if (six.PY2 and inspect.isfunction(component)
340-
and name in ('func_closure', 'func_code', 'func_defaults',
341-
'func_dict', 'func_doc', 'func_globals', 'func_name')):
342-
return False
343-
if (six.PY2 and inspect.ismethod(component)
344-
and name in ('im_class', 'im_func', 'im_self')):
345-
return False
346-
if isinstance(name, six.string_types):
336+
if isinstance(name, str):
347337
return not name.startswith('_')
348338
return True # Default to including the member
349339

@@ -392,7 +382,7 @@ def _CompletionsFromArgs(fn_args):
392382
completions = []
393383
for arg in fn_args:
394384
arg = arg.replace('_', '-')
395-
completions.append('--{arg}'.format(arg=arg))
385+
completions.append(f'--{arg}')
396386
return completions
397387

398388

@@ -438,7 +428,7 @@ def _FormatForCommand(token):
438428
Returns:
439429
The transformed token.
440430
"""
441-
if not isinstance(token, six.string_types):
431+
if not isinstance(token, str):
442432
token = str(token)
443433

444434
if token.startswith('_'):

fire/completion_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
"""Tests for the completion module."""
1616

17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
20-
2117
from fire import completion
2218
from fire import test_components as tc
2319
from fire import testutils
@@ -37,9 +33,8 @@ def testCompletionBashScript(self):
3733
self.assertIn('command', script)
3834
self.assertIn('halt', script)
3935

40-
assert_template = '{command})'
4136
for last_command in ['command', 'halt']:
42-
self.assertIn(assert_template.format(command=last_command), script)
37+
self.assertIn(f'{last_command})', script)
4338

4439
def testCompletionFishScript(self):
4540
# A sanity check test to make sure the fish completion script satisfies

0 commit comments

Comments
 (0)