MCPcopy Index your code
hub / github.com/httpie/cli / Plugin

Class Plugin

tests/utils/plugins_cli.py:37–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36@dataclass
37class Plugin:
38 interface: 'Interface'
39
40 name: str = field(default_factory=make_name)
41 version: str = '1.0.0'
42 entry_points: List[EntryPoint] = field(default_factory=list)
43
44 def build(self) -> None:
45 '''
46 Create an installable dummy plugin at the given path.
47
48 It will create a setup.py with the specified entry points,
49 as well as dummy classes in a python module to imitate
50 real plugins.
51 '''
52
53 groups = defaultdict(list)
54 for entry_point in self.entry_points:
55 groups[entry_point.group].append(entry_point.name)
56
57 setup_eps = {
58 group: [
59 f'{name} = {self.import_name}:{name.title()}'
60 for name in names
61 ]
62 for group, names in groups.items()
63 }
64
65 self.path.mkdir(parents=True, exist_ok=True)
66 with open(self.path / 'setup.py', 'w') as stream:
67 stream.write(textwrap.dedent(f'''
68 from setuptools import setup
69
70 setup(
71 name='{self.name}',
72 version='{self.version}',
73 py_modules=['{self.import_name}'],
74 entry_points={setup_eps!r},
75 install_requires=['httpie']
76 )
77 '''))
78
79 with open(self.path / (self.import_name + '.py'), 'w') as stream:
80 stream.write('from httpie.plugins import *\n')
81 stream.writelines(
82 f'class {name.title()}({CLASSES[group].__name__}): ...\n'
83 for group, names in groups.items()
84 for name in names
85 )
86
87 def dump(self) -> Dict[str, Any]:
88 return {
89 'version': self.version,
90 'entry_points': [
91 entry_point.dump()
92 for entry_point in self.entry_points
93 ]
94 }

Callers 1

make_dummy_pluginMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected