[Commands] Add env command (#352) · kampta/diffusers@59c1af7 · GitHub
Skip to content

Commit 59c1af7

Browse files
[Commands] Add env command (huggingface#352)
* [Commands] Add env command * Apply suggestions from code review
1 parent fd76845 commit 59c1af7

5 files changed

Lines changed: 147 additions & 1 deletion

File tree

‎.github/ISSUE_TEMPLATE/bug-report.yml‎

Lines changed: 8 additions & 0 deletions

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def run(self):
201201
python_requires=">=3.6.0",
202202
install_requires=install_requires,
203203
extras_require=extras,
204+
entry_points={"console_scripts": ["diffusers-cli=diffusers.commands.diffusers_cli:main"]},
204205
classifiers=[
205206
"Development Status :: 5 - Production/Stable",
206207
"Intended Audience :: Developers",
@@ -209,7 +210,6 @@ def run(self):
209210
"License :: OSI Approved :: Apache Software License",
210211
"Operating System :: OS Independent",
211212
"Programming Language :: Python :: 3",
212-
"Programming Language :: Python :: 3.6",
213213
"Programming Language :: Python :: 3.7",
214214
"Programming Language :: Python :: 3.8",
215215
"Programming Language :: Python :: 3.9",

‎src/diffusers/commands/__init__.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from abc import ABC, abstractmethod
16+
from argparse import ArgumentParser
17+
18+
19+
class BaseDiffusersCLICommand(ABC):
20+
@staticmethod
21+
@abstractmethod
22+
def register_subcommand(parser: ArgumentParser):
23+
raise NotImplementedError()
24+
25+
@abstractmethod
26+
def run(self):
27+
raise NotImplementedError()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# Copyright 2022 The HuggingFace Team. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from argparse import ArgumentParser
17+
18+
from .env import EnvironmentCommand
19+
20+
21+
def main():
22+
parser = ArgumentParser("Diffusers CLI tool", usage="diffusers-cli <command> [<args>]")
23+
commands_parser = parser.add_subparsers(help="diffusers-cli command helpers")
24+
25+
# Register commands
26+
EnvironmentCommand.register_subcommand(commands_parser)
27+
28+
# Let's go
29+
args = parser.parse_args()
30+
31+
if not hasattr(args, "func"):
32+
parser.print_help()
33+
exit(1)
34+
35+
# Run
36+
service = args.func(args)
37+
service.run()
38+
39+
40+
if __name__ == "__main__":
41+
main()

‎src/diffusers/commands/env.py‎

Lines changed: 70 additions & 0 deletions

0 commit comments

Comments
 (0)