Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
d8d6e2b
1
Parent(s):
f8b274c
Fix formatting
Browse files- pysr/__main__.py +1 -1
- pysr/_cli/main.py +25 -24
- pysr/export_latex.py +0 -1
- pysr/test/test_cli.py +30 -23
pysr/__main__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
from pysr._cli.main import pysr as _cli
|
2 |
|
3 |
-
if __name__ ==
|
4 |
_cli(prog_name="pysr")
|
|
|
1 |
from pysr._cli.main import pysr as _cli
|
2 |
|
3 |
+
if __name__ == "__main__":
|
4 |
_cli(prog_name="pysr")
|
pysr/_cli/main.py
CHANGED
@@ -8,29 +8,30 @@ def pysr(context):
|
|
8 |
ctx = context
|
9 |
|
10 |
|
11 |
-
@pysr.command("install",
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
def _install(julia_project, quiet, precompile):
|
36 |
install(julia_project, quiet, precompile)
|
|
|
8 |
ctx = context
|
9 |
|
10 |
|
11 |
+
@pysr.command("install", help="Install Julia dependencies for PySR.")
|
12 |
+
@click.option(
|
13 |
+
"-p",
|
14 |
+
"julia_project",
|
15 |
+
"--project",
|
16 |
+
default=None,
|
17 |
+
type=str,
|
18 |
+
help="Install in a specific Julia project (e.g., a local copy of SymbolicRegression.jl).",
|
19 |
+
metavar="PROJECT_DIRECTORY",
|
20 |
+
)
|
21 |
+
@click.option("-q", "--quiet", is_flag=True, default=False, help="Disable logging.")
|
22 |
+
@click.option(
|
23 |
+
"--precompile",
|
24 |
+
"precompile",
|
25 |
+
flag_value=True,
|
26 |
+
default=None,
|
27 |
+
help="Force precompilation of Julia libraries.",
|
28 |
+
)
|
29 |
+
@click.option(
|
30 |
+
"--no-precompile",
|
31 |
+
"precompile",
|
32 |
+
flag_value=False,
|
33 |
+
default=None,
|
34 |
+
help="Disable precompilation.",
|
35 |
+
)
|
36 |
def _install(julia_project, quiet, precompile):
|
37 |
install(julia_project, quiet, precompile)
|
pysr/export_latex.py
CHANGED
@@ -96,7 +96,6 @@ def generate_single_table(
|
|
96 |
"$" + output_variable_name + " = " + latex_equation + "$"
|
97 |
)
|
98 |
else:
|
99 |
-
|
100 |
broken_latex_equation = " ".join(
|
101 |
[
|
102 |
r"\begin{minipage}{0.8\linewidth}",
|
|
|
96 |
"$" + output_variable_name + " = " + latex_equation + "$"
|
97 |
)
|
98 |
else:
|
|
|
99 |
broken_latex_equation = " ".join(
|
100 |
[
|
101 |
r"\begin{minipage}{0.8\linewidth}",
|
pysr/test/test_cli.py
CHANGED
@@ -6,7 +6,11 @@ def run_command(command):
|
|
6 |
"""
|
7 |
Retrieve output of a command string, decode and convert from CRLF to LF formatting
|
8 |
"""
|
9 |
-
return
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def make_command(command):
|
@@ -17,17 +21,18 @@ def make_command(command):
|
|
17 |
|
18 |
|
19 |
class TestCli(unittest.TestCase):
|
20 |
-
|
21 |
def test_help_on_all_commands(self):
|
22 |
command_to_test = "python -m pysr --help"
|
23 |
-
expected_lines = [
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
|
32 |
expected = make_command(expected_lines)
|
33 |
actual = run_command(command_to_test)
|
@@ -35,19 +40,21 @@ class TestCli(unittest.TestCase):
|
|
35 |
|
36 |
def test_help_on_install(self):
|
37 |
command_to_test = "python -m pysr install --help"
|
38 |
-
expected_lines = [
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
"
|
|
|
|
|
51 |
|
52 |
expected = make_command(expected_lines)
|
53 |
actual = run_command(command_to_test)
|
|
|
6 |
"""
|
7 |
Retrieve output of a command string, decode and convert from CRLF to LF formatting
|
8 |
"""
|
9 |
+
return (
|
10 |
+
subprocess.run(command.split(" "), stdout=subprocess.PIPE)
|
11 |
+
.stdout.decode("utf-8")
|
12 |
+
.replace("\r\n", "\n")
|
13 |
+
)
|
14 |
|
15 |
|
16 |
def make_command(command):
|
|
|
21 |
|
22 |
|
23 |
class TestCli(unittest.TestCase):
|
|
|
24 |
def test_help_on_all_commands(self):
|
25 |
command_to_test = "python -m pysr --help"
|
26 |
+
expected_lines = [
|
27 |
+
"Usage: pysr [OPTIONS] COMMAND [ARGS]...",
|
28 |
+
"",
|
29 |
+
"Options:",
|
30 |
+
" --help Show this message and exit.",
|
31 |
+
"",
|
32 |
+
"Commands:",
|
33 |
+
" install Install Julia dependencies for PySR.",
|
34 |
+
"",
|
35 |
+
]
|
36 |
|
37 |
expected = make_command(expected_lines)
|
38 |
actual = run_command(command_to_test)
|
|
|
40 |
|
41 |
def test_help_on_install(self):
|
42 |
command_to_test = "python -m pysr install --help"
|
43 |
+
expected_lines = [
|
44 |
+
"Usage: pysr install [OPTIONS]",
|
45 |
+
"",
|
46 |
+
" Install Julia dependencies for PySR.",
|
47 |
+
"",
|
48 |
+
"Options:",
|
49 |
+
" -p, --project PROJECT_DIRECTORY",
|
50 |
+
" Install in a specific Julia project (e.g., a",
|
51 |
+
" local copy of SymbolicRegression.jl).",
|
52 |
+
" -q, --quiet Disable logging.",
|
53 |
+
" --precompile Force precompilation of Julia libraries.",
|
54 |
+
" --no-precompile Disable precompilation.",
|
55 |
+
" --help Show this message and exit.",
|
56 |
+
"",
|
57 |
+
]
|
58 |
|
59 |
expected = make_command(expected_lines)
|
60 |
actual = run_command(command_to_test)
|