Skip to content

Commit 4170f19

Browse files
committed
Move sys.path manipulation to __main__.py
1 parent 7ae5351 commit 4170f19

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
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/eval_cmd.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from sage.cli.options import CliOptions
44
from sage.repl.preparse import preparse
55
from sage.all import sage_globals
6-
import os
7-
import sys
86

97

108
class EvalCmd:
@@ -38,9 +36,6 @@ def run(self) -> int:
3836
r"""
3937
Execute the given command.
4038
"""
41-
# Allow importing modules from the current directory, matching python behavior
42-
sys.path.append(os.getcwd())
43-
4439
code = preparse(self.options.command)
4540
eval(compile(code, "<cmdline>", "exec"), sage_globals())
4641
return 0

src/sage/cli/run_file_cmd.py

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

34
from sage.cli.options import CliOptions
45
from sage.repl.preparse import preparse_file_named
56
from sage.repl.load import load_cython
67
from sage.misc.temporary_file import tmp_filename
78
from sage.all import sage_globals
8-
import os
9-
import sys
109

1110

1211
class RunFileCmd:
@@ -41,9 +40,6 @@ def run(self) -> int:
4140
r"""
4241
Execute the given command.
4342
"""
44-
# Allow importing modules from the current directory, matching python behavior
45-
sys.path.append(os.getcwd())
46-
4743
input_file = self.options.file[0]
4844
if input_file.endswith('.sage'):
4945
input_file = str(preparse_file_named(input_file))

0 commit comments

Comments
 (0)