Skip to content

Commit 10351f6

Browse files
author
Release Manager
committed
sagemathgh-40912: cli: Allow importing modules from the current directory when running a command or a file. Matches python behavior, and fixes another regression with respect to the bash script Fixes sagemath#40908 ### ⌛ Dependencies sagemath#40872 URL: sagemath#40912 Reported by: Antonio Rojas Reviewer(s): Tobias Diez
2 parents 7f36934 + 5829e85 commit 10351f6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ content-type = "text/markdown"
103103
file = "README.md"
104104

105105
[project.scripts]
106-
sage = "sage.cli:main"
106+
sage = "sage.cli.__main__:main"
107107

108108
[tool.conda-lock]
109109
platforms = ['linux-64', 'linux-aarch64', 'osx-64', 'osx-arm64']

src/sage/cli/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import os
12
import sys
23

4+
# Allow importing modules from the current directory, matching python behavior
5+
sys.path.append(os.getcwd())
6+
37
from sage.cli import main
48

59
sys.exit(main())

src/sage/cli/run_file_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import sys
23

34
from sage.cli.options import CliOptions
45
from sage.repl.preparse import preparse_file_named
@@ -33,7 +34,6 @@ def __init__(self, options: CliOptions):
3334
"""
3435
self.options = options
3536
# shift sys.argv for compatibility with the old sage bash script and python command when consuming arguments from the command line
36-
import sys
3737
del sys.argv[0]
3838

3939
def run(self) -> int:

0 commit comments

Comments
 (0)