Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CLI to run pysr.install() to install Julia dependencies #298

Merged
merged 33 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3876e75
Added click and install
WilliamBC-SL Apr 19, 2023
edc9d51
Added requirements.
WilliamBC-SL Apr 19, 2023
973fb98
Refactored to remove relative file reference
WilliamBC-SL Apr 19, 2023
40ac644
Refactored main to appropriate folder
WilliamBC-SL Apr 19, 2023
b111a3b
Updated instructions to install Julia dependencies
WilliamBC-SL Apr 19, 2023
6b2e2da
Added requirements.
w2ll2am Apr 20, 2023
f145620
Refactored to remove relative file reference
w2ll2am Apr 20, 2023
6c1caad
Refactored main to appropriate folder
w2ll2am Apr 20, 2023
9941a00
Updated instructions to install Julia dependencies
w2ll2am Apr 20, 2023
54a4632
Merge branch 'master' of https://github.com/w2ll2am/PySR
w2ll2am Apr 20, 2023
808a4c3
Implemented PR changes.
w2ll2am Apr 20, 2023
37a4ac2
Fixed missing variable pointer
w2ll2am Apr 20, 2023
7b970f3
Changed click version
w2ll2am Apr 22, 2023
b706235
Updated setup tools
w2ll2am Apr 22, 2023
b667140
Consistent formatting in `requirements.txt`
MilesCranmer Apr 25, 2023
0a7daf2
Tweak documentation
MilesCranmer Apr 25, 2023
01ec39f
Added more informative help message
w2ll2am Apr 25, 2023
58c93fa
Merge branch 'master' of https://github.com/w2ll2am/PySR
w2ll2am Apr 25, 2023
8e9aba4
Added tests to check help messages
w2ll2am Apr 28, 2023
df9e8e7
Removed extrenous imports
w2ll2am Apr 28, 2023
6fbdb36
Merge branch 'MilesCranmer:master' into master
WilliamBC-SL Apr 28, 2023
5509b10
Merge branch 'master' of https://github.com/w2ll2am/PySR
w2ll2am Apr 28, 2023
82f5f4d
Added some comments to explain tests
w2ll2am Apr 28, 2023
92ac433
Added tests to pipeline
w2ll2am May 11, 2023
1163194
Add CLI tests to CI
MilesCranmer May 15, 2023
cd0e3b6
Fix deleted coverage information
MilesCranmer May 15, 2023
c12c386
Merge tag 'v0.13.0' into pr/w2ll2am/298
MilesCranmer May 20, 2023
0cace0c
Bump version with new install method
MilesCranmer May 20, 2023
86ade53
Rename test_cli.py for consistency
MilesCranmer May 20, 2023
f8b274c
Leave old instructions until new method is stable
MilesCranmer May 20, 2023
d8d6e2b
Fix formatting
MilesCranmer May 20, 2023
a0fd52f
Simplify CLI test
MilesCranmer May 20, 2023
4726b4a
Refactor CLI unittest with `click.testing`
MilesCranmer May 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
python -m pysr install
- name: "Install Coverage tool"
run: pip install coverage coveralls
- name: "Run tests"
run: coverage run --source=pysr --omit='*/test/*,*/feynman_problems.py' -m pysr.test main
run: |
coverage run --source=pysr --omit='*/test/*,*/feynman_problems.py' -m pysr.test main
coverage run --append --source=pysr --omit='*/test/*,*/feynman_problems.py' -m pysr.test cli
- name: "Install JAX"
run: pip install jax jaxlib # (optional import)
- name: "Run JAX tests"
Expand Down Expand Up @@ -112,7 +114,7 @@ jobs:
- name: "Install PySR"
run: |
python3 -m pip install .
python3 -c 'import pysr; pysr.install()'
python3 -m pysr install
- name: "Run tests"
run: cd /tmp && python -m pysr.test main

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/CI_Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
python -m pysr install
- name: "Run tests"
run: python -m pysr.test main
run: |
python -m pysr.test main
python -m pysr.test cli
- name: "Install Torch"
run: pip install torch # (optional import)
- name: "Run Torch tests"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
- name: Build docker
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} --build-arg PYVERSION=${{ matrix.python-version }} .
- name: Test docker
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test env'
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test cli && python3 -m pysr.test env'
2 changes: 1 addition & 1 deletion .github/workflows/CI_docker_large_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Build docker
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} .
- name: Test docker
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test env'
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test cli && python3 -m pysr.test env'
6 changes: 4 additions & 2 deletions .github/workflows/CI_large_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
python -m pysr install
- name: "Run tests"
run: python -m pysr.test main
run: |
python -m pysr.test main
python -m pysr.test cli
- name: "Run new env test"
run: python -m pysr.test env
if: ${{ !(matrix.os == 'windows-latest' && matrix.python-version == '3.7') }}
6 changes: 4 additions & 2 deletions .github/workflows/CI_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
python -m pysr install
- name: "Run tests"
run: python -m pysr.test main
run: |
python -m pysr.test main
python -m pysr.test cli
- name: "Install JAX"
run: pip install jax jaxlib # (optional import)
- name: "Run JAX tests"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ADD ./pysr/ /pysr/pysr/
RUN pip3 install .

# Install Julia pre-requisites:
RUN python3 -c 'import pysr; pysr.install()'
RUN python3 -m pysr install

# metainformation
LABEL org.opencontainers.image.authors = "Miles Cranmer"
Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies:
- setuptools
- pyjulia
- openlibm
- openspecfun
- openspecfun
- click
4 changes: 4 additions & 0 deletions pysr/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pysr._cli.main import pysr as _cli

if __name__ == "__main__":
_cli(prog_name="pysr")
Empty file added pysr/_cli/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions pysr/_cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import click
from ..julia_helpers import install


@click.group("pysr")
@click.pass_context
def pysr(context):
ctx = context


@pysr.command("install", help="Install Julia dependencies for PySR.")
@click.option(
"-p",
"julia_project",
"--project",
default=None,
type=str,
help="Install in a specific Julia project (e.g., a local copy of SymbolicRegression.jl).",
metavar="PROJECT_DIRECTORY",
)
@click.option("-q", "--quiet", is_flag=True, default=False, help="Disable logging.")
@click.option(
"--precompile",
"precompile",
flag_value=True,
default=None,
help="Force precompilation of Julia libraries.",
)
@click.option(
"--no-precompile",
"precompile",
flag_value=False,
default=None,
help="Disable precompilation.",
)
def _install(julia_project, quiet, precompile):
install(julia_project, quiet, precompile)
1 change: 0 additions & 1 deletion pysr/export_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def generate_single_table(
"$" + output_variable_name + " = " + latex_equation + "$"
)
else:

broken_latex_equation = " ".join(
[
r"\begin{minipage}{0.8\linewidth}",
Expand Down
10 changes: 4 additions & 6 deletions pysr/julia_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ def install(julia_project=None, quiet=False, precompile=None): # pragma: no cov

def _import_error():
return """
Required dependencies are not installed or built. Run the following code in the Python REPL:

>>> import pysr
>>> pysr.install()
Required dependencies are not installed or built. Run the following command in your terminal:
python3 -m pysr install
"""


Expand Down Expand Up @@ -286,14 +284,14 @@ def _backend_version_assertion(Main):
f"does not match expected version {expected_backend_version}. "
"Things may break. "
"Please update your PySR installation with "
"`python -c 'import pysr; pysr.install()'`."
"`python3 -m pysr install`."
)
except JuliaError: # pragma: no cover
warnings.warn(
"You seem to have an outdated version of SymbolicRegression.jl. "
"Things may break. "
"Please update your PySR installation with "
"`python -c 'import pysr; pysr.install()'`."
"`python3 -m pysr install`."
)


Expand Down
1 change: 1 addition & 0 deletions pysr/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .test_env import runtests as runtests_env
from .test_jax import runtests as runtests_jax
from .test_torch import runtests as runtests_torch
from .test_cli import runtests as runtests_cli
6 changes: 4 additions & 2 deletions pysr/test/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
parser.add_argument(
"test",
nargs="*",
help="Test to run. One or more of 'main', 'env', 'jax', 'torch'.",
help="Test to run. One or more of 'main', 'env', 'jax', 'torch', 'cli'.",
)

# Parse args:
Expand All @@ -25,7 +25,7 @@

# Run tests:
for test in tests:
if test in {"main", "env", "jax", "torch"}:
if test in {"main", "env", "jax", "torch", "cli"}:
cur_dir = os.path.dirname(os.path.abspath(__file__))
print(f"Running test from {cur_dir}")
if test == "main":
Expand All @@ -36,6 +36,8 @@
runtests_jax()
elif test == "torch":
runtests_torch()
elif test == "cli":
runtests_cli()
else:
parser.print_help()
raise SystemExit(1)
57 changes: 57 additions & 0 deletions pysr/test/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from click import testing as click_testing
from .._cli.main import pysr


class TestCli(unittest.TestCase):
# TODO: Include test for custom project here.
def setUp(self):
self.cli_runner = click_testing.CliRunner()

def test_help_on_all_commands(self):
expected = "\n".join(
[
"Usage: pysr [OPTIONS] COMMAND [ARGS]...",
"",
"Options:",
" --help Show this message and exit.",
"",
"Commands:",
" install Install Julia dependencies for PySR.",
"",
]
)
result = self.cli_runner.invoke(pysr, ["--help"])
self.assertEqual(expected, result.output)
self.assertEqual(0, result.exit_code)

def test_help_on_install(self):
expected = "\n".join(
[
"Usage: pysr install [OPTIONS]",
"",
" Install Julia dependencies for PySR.",
"",
"Options:",
" -p, --project PROJECT_DIRECTORY",
" Install in a specific Julia project (e.g., a",
" local copy of SymbolicRegression.jl).",
" -q, --quiet Disable logging.",
" --precompile Force precompilation of Julia libraries.",
" --no-precompile Disable precompilation.",
" --help Show this message and exit.",
"",
]
)
result = self.cli_runner.invoke(pysr, ["install", "--help"])
self.assertEqual(expected, result.output)
self.assertEqual(0, result.exit_code)


def runtests():
"""Run all tests in cliTest.py."""
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTests(loader.loadTestsFromTestCase(TestCli))
runner = unittest.TextTestRunner()
return runner.run(suite)
2 changes: 1 addition & 1 deletion pysr/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.13.0"
__version__ = "0.14.0"
__symbolic_regression_jl_version__ = "0.18.0"
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sympy
pandas
numpy
scikit_learn >= 1.0.0
julia >= 0.6.0
scikit_learn>=1.0.0
julia>=0.6.0
click>=7.0.0
setuptools>=50.0.0