-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39ebbe4
commit 8da18d6
Showing
9 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
|
||
from sage.cli.interactive_shell_cmd import InteractiveShellCmd | ||
from sage.cli.options import CliOptions | ||
from sage.cli.version_cmd import VersionCmd | ||
|
||
|
||
def main() -> int: | ||
input_args = sys.argv[1:] | ||
parser = argparse.ArgumentParser( | ||
prog="sage", | ||
description="If no command is given, starts the interactive interpreter where you can enter statements and expressions, immediately execute them and see their results.", | ||
) | ||
parser.add_argument( | ||
"-v", | ||
"--verbose", | ||
action="store_true", | ||
default=False, | ||
help="print additional information", | ||
) | ||
|
||
VersionCmd.extend_parser(parser) | ||
|
||
if not input_args: | ||
InteractiveShellCmd(CliOptions()).run() | ||
|
||
args = parser.parse_args(input_args) | ||
options = CliOptions(**vars(args)) | ||
|
||
logging.basicConfig(level=logging.DEBUG if options.verbose else logging.INFO) | ||
|
||
return InteractiveShellCmd(options).run() | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from sage.cli.options import CliOptions | ||
|
||
|
||
class InteractiveShellCmd: | ||
def __init__(self, options: CliOptions): | ||
r""" | ||
Initialize the command. | ||
""" | ||
self.options = options | ||
|
||
def run(self) -> int: | ||
r""" | ||
Start the interactive shell. | ||
""" | ||
# Display startup banner. Do this before anything else to give the user | ||
# early feedback that Sage is starting. | ||
from sage.misc.banner import banner | ||
|
||
banner() | ||
|
||
from sage.repl.interpreter import SageTerminalApp | ||
|
||
app = SageTerminalApp.instance() | ||
app.initialize([]) | ||
return app.start() # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
py.install_sources( | ||
'__init__.py', | ||
'interactive_shell_cmd.py', | ||
'options.py', | ||
'version_cmd.py', | ||
subdir: 'sage/cli', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class CliOptions: | ||
""" | ||
A TypedDict for command-line interface options. | ||
Attributes: | ||
verbose (bool): Indicates whether verbose output is enabled. | ||
""" | ||
|
||
verbose: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import argparse | ||
|
||
from sage.version import version | ||
|
||
|
||
class VersionCmd: | ||
@staticmethod | ||
def extend_parser(parser: argparse.ArgumentParser): | ||
r""" | ||
Extend the parser with the version command. | ||
INPUT: | ||
- ``parsers`` -- the parsers to extend. | ||
OUTPUT: | ||
- the extended parser. | ||
""" | ||
parser.add_argument( | ||
"--version", | ||
action="version", | ||
version=version, | ||
help="print the version number and exit", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,4 @@ subdir('symbolic') | |
subdir('tests') | ||
subdir('dynamics') | ||
subdir('sat') | ||
subdir('cli') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule singular
added at
16cd1d