From 89d3fe7e78697d80a00325bfaa2929c9cddf571e Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 11:44:26 -0500 Subject: [PATCH 01/31] Updating github actions --- .github/workflows/ci_test.yml | 80 ++++++++++++++++++++++++++--------- Makefile | 6 +-- pyproject.toml | 12 ++++-- requirements.txt | 8 ++-- setup.py | 9 +++- tests/test_pulsar.py | 8 ++++ 6 files changed, 90 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 1afa64b7..3616142c 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -1,51 +1,89 @@ -name: CI-Tests +name: enterprise CI targets on: push: -# branches: -# - master + branches: [ master ] pull_request: + branches: [ master ] + release: + types: + - published + jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: psf/black@stable - build: + test-linux: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: [3.6, 3.7, 3.8] + steps: - - name: Checkout Repository + - name: Checkout repository uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pre-install + - name: Install non-python dependencies run: | sudo apt-get install libsuitesparse-dev - python -m pip install --upgrade pip - - name: Install Dependencies + curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh + - name: Install dependencies and package run: | - cat requirements_dev.txt | xargs -n 1 -L 1 pip install - cat requirements.txt | xargs -n 1 -L 1 pip install - python setup.py install + python -m pip install --upgrade pip + python -m pip install flake8 pytest black pytest-cov + pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | python -c "import sys; print(f'Python {sys.version}')" python -c "import pip; print(f'pip {pip.__version__}')" python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" pip freeze - - name: Run Tests and Lint - run: | - pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml - make lint + - name: Run lint + run: make lint + - name: Test with pytest + run: pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml - name: Codecov uses: codecov/codecov-action@v1 with: fail_ci_if_error: true + + + test-mac: + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install non-python dependencies + run: | + brew install suite-sparse + curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh + - name: Install dependencies and package + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest black pytest-cov + pip install -e . + - name: Display Python, pip, setuptools, and all installed versions + run: | + python -c "import sys; print(f'Python {sys.version}')" + python -c "import pip; print(f'pip {pip.__version__}')" + python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" + pip freeze + - name: Run lint + run: make lint + - name: Test with pytest + run: pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml + - name: Codecov + uses: codecov/codecov-action@v1 + with: + fail_ci_if_error: true \ No newline at end of file diff --git a/Makefile b/Makefile index e15585cf..375b358a 100644 --- a/Makefile +++ b/Makefile @@ -28,10 +28,10 @@ help: init: @python3 -m venv .enterprise --prompt enterprise - @./.enterprise/bin/python3 -m pip install numpy + @./.enterprise/bin/python3 -m pip install -U pip + @./.enterprise/bin/python3 -m pip install numpy cython @./.enterprise/bin/python3 -m pip install -r requirements.txt -U @./.enterprise/bin/python3 -m pip install -r requirements_dev.txt -U - @./.enterprise/bin/python3 -m pip install libstempo --install-option="--with-tempo2=$(TEMPO2)" @./.enterprise/bin/python3 -m pre_commit install --install-hooks --overwrite @./.enterprise/bin/python3 -m pip install -e . @@ -62,7 +62,7 @@ clean-test: ## remove test and coverage artifacts rm -f .coverage rm -fr htmlcov/ -test: ## run tests quickly with the default Python +test: lint ## run tests quickly with the default Python pytest -v --full-trace --cov-config .coveragerc --cov=enterprise tests #test-all: ## run tests on every Python version with tox diff --git a/pyproject.toml b/pyproject.toml index 571df8af..8d16d98a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,13 @@ exclude = ''' | .enterprise | enterprise/src )/ - | foo.py # also separately exclude a file named foo.py in - # the root of the project ) -''' \ No newline at end of file +''' +[build-system] +requires = [ + "setuptools>=40.8.0", + "wheel", + "Cython>=0.22", # need for scikit-sparse + "numpy>=1.15.0" # need for scikit-sparse +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 35be0917..66a6495e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,8 @@ numpy>=1.16.3 scipy>=1.2.0 ephem>=3.7.6.0 -Cython>=0.28.5 jplephem==2.6 -setuptools>=40.0.0 healpy>=1.14.0 -scikit-sparse>=0.4.2 --no-binary scikit-sparse -git+https://github.com/nanograv/PINT.git@master#egg=pint-pulsar -git+https://github.com/vallis/libstempo.git@master#egg=libstempo --install-option="--force-tempo2-install" +scikit-sparse>=0.4.2 +pint-pulsar>=0.8.2 +git+https://github.com/jellis18/libstempo.git@master#egg=libstempo diff --git a/setup.py b/setup.py index f1575ce0..de3b3667 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,14 @@ history = history_file.read() requirements = [ - # TODO: put package requirements here + "numpy>=1.16.3", + "scipy>=1.2.0", + "ephem>=3.7.6.0", + "jplephem==2.6", + "healpy>=1.14.0", + "scikit-sparse>=0.4.2", + "pint-pulsar>=0.8.2", + "libstempo @ git+https://github.com/jellis18/libstempo.git@master#egg=libstempo", ] test_requirements = [] diff --git a/tests/test_pulsar.py b/tests/test_pulsar.py index 95cad51e..41fb6901 100644 --- a/tests/test_pulsar.py +++ b/tests/test_pulsar.py @@ -10,6 +10,8 @@ """ +import os +import shutil import unittest import numpy as np @@ -31,6 +33,10 @@ def setUpClass(cls): # initialize Pulsar class cls.psr = Pulsar(datadir + "/B1855+09_NANOGrav_9yv1.gls.par", datadir + "/B1855+09_NANOGrav_9yv1.tim") + @classmethod + def tearDownClass(cls): + shutil.rmtree("pickle_dir") + def test_residuals(self): """Check Residual shape.""" @@ -117,6 +123,8 @@ def test_to_pickle(self): with open("B1855+09.pkl", "rb") as f: pkl_psr = pickle.load(f) + os.remove("B1855+09.pkl") + assert np.allclose(self.psr.residuals, pkl_psr.residuals, rtol=1e-10) self.psr.to_pickle("pickle_dir") From 213563303e67d4496abe2a41a493b7449c63b628 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 11:52:32 -0500 Subject: [PATCH 02/31] Update CI --- .github/workflows/ci_test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 3616142c..a92ade95 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -31,15 +31,15 @@ jobs: curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools wheel python -m pip install flake8 pytest black pytest-cov - pip install -e . + python -m pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | python -c "import sys; print(f'Python {sys.version}')" python -c "import pip; print(f'pip {pip.__version__}')" python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" - pip freeze + python -m pip freeze - name: Run lint run: make lint - name: Test with pytest @@ -70,15 +70,15 @@ jobs: curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools wheel python -m pip install flake8 pytest black pytest-cov - pip install -e . + python -m pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | python -c "import sys; print(f'Python {sys.version}')" python -c "import pip; print(f'pip {pip.__version__}')" python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" - pip freeze + python -m pip freeze - name: Run lint run: make lint - name: Test with pytest From 645e3503ea323f25b11c2688504fe2dc261f212c Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 12:21:32 -0500 Subject: [PATCH 03/31] add numpy cython install --- .github/workflows/ci_test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index a92ade95..2be092b6 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -33,6 +33,7 @@ jobs: run: | python -m pip install --upgrade pip setuptools wheel python -m pip install flake8 pytest black pytest-cov + python -m pip install numpy cython python -m pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | @@ -72,6 +73,7 @@ jobs: run: | python -m pip install --upgrade pip setuptools wheel python -m pip install flake8 pytest black pytest-cov + python -m pip install numpy cython python -m pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | From b52dada23da5355021b2e0b41e45d3e32c51670f Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 12:54:14 -0500 Subject: [PATCH 04/31] Check brew list --- .github/workflows/ci_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 2be092b6..1c6bea77 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,6 +67,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | + brew list brew install suite-sparse curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package From 264ac0fc2dd036ef11ade0fa05d0549698e3d8e4 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 13:27:13 -0500 Subject: [PATCH 05/31] Automake --- .github/workflows/ci_test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 1c6bea77..5285bca9 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,8 +67,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | - brew list - brew install suite-sparse + brew install suite-sparse automake curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From 786b6bdfc93983c5e03cc2b306dda74d5b0b971a Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 17:05:56 -0500 Subject: [PATCH 06/31] gfortran --- .github/workflows/ci_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 5285bca9..5c3556d0 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,7 +67,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | - brew install suite-sparse automake + brew install suite-sparse automake gfortran curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From 01ad5093ad2bedf483e3b068942260209d58f8e9 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 18:09:38 -0500 Subject: [PATCH 07/31] alias --- .github/workflows/ci_test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 5c3556d0..0188425f 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,7 +67,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | - brew install suite-sparse automake gfortran + alias gfortran=gfortran-9 + brew install suite-sparse automake curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From 2d5d4110b1cb7a785235e4441ab581af3e2ae084 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 18:19:56 -0500 Subject: [PATCH 08/31] environment variable --- .github/workflows/ci_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 0188425f..0d23fb89 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,8 +67,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | - alias gfortran=gfortran-9 brew install suite-sparse automake + export FC=gfortran-10 curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From 819625ec85dea5468072d755554278522b1ec946 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 18:43:54 -0500 Subject: [PATCH 09/31] brew link --- .github/workflows/ci_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 0d23fb89..22896d37 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,8 +67,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | + brew link gfortran brew install suite-sparse automake - export FC=gfortran-10 curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From 1fe00fa14dc1b7d465504eb59027c6a4e0419592 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 7 Mar 2021 20:33:10 -0500 Subject: [PATCH 10/31] try again --- .github/workflows/ci_test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 22896d37..6515d416 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -67,7 +67,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install non-python dependencies run: | - brew link gfortran + brew unlink gcc && brew link gcc + which gfortran brew install suite-sparse automake curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package From cbc877d50bccfd4fbe5c2ff6e2dbc6a5318e7413 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Mon, 8 Mar 2021 07:39:27 -0500 Subject: [PATCH 11/31] one block --- .github/workflows/ci_test.yml | 54 +++++++---------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 6515d416..ab5afa41 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -11,11 +11,12 @@ on: jobs: - test-linux: - runs-on: ubuntu-latest + tests: + runs-on: ${{ os.matrix.os }} strategy: fail-fast: false matrix: + os: [ubuntu-latest, macos-latest] python-version: [3.6, 3.7, 3.8] steps: @@ -25,51 +26,16 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Install non-python dependencies + - name: Install non-python dependencies on mac + if: runner.os == 'macOS' run: | - sudo apt-get install libsuitesparse-dev + brew unlink gcc && brew link gcc + brew install automake suite-sparse curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - - name: Install dependencies and package - run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install flake8 pytest black pytest-cov - python -m pip install numpy cython - python -m pip install -e . - - name: Display Python, pip, setuptools, and all installed versions + - name: Install non-python dependencies on linux + if: runner.os == 'Linux' run: | - python -c "import sys; print(f'Python {sys.version}')" - python -c "import pip; print(f'pip {pip.__version__}')" - python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" - python -m pip freeze - - name: Run lint - run: make lint - - name: Test with pytest - run: pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml - - name: Codecov - uses: codecov/codecov-action@v1 - with: - fail_ci_if_error: true - - - test-mac: - runs-on: macos-latest - strategy: - fail-fast: false - matrix: - python-version: [3.6, 3.7, 3.8] - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install non-python dependencies - run: | - brew unlink gcc && brew link gcc - which gfortran - brew install suite-sparse automake + sudo apt-get install libsuitesparse-dev curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | From c5a2962f21579dc10684907f73e6d8be25fa4850 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Mon, 8 Mar 2021 07:40:39 -0500 Subject: [PATCH 12/31] fix typo --- .github/workflows/ci_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index ab5afa41..230acfe2 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -12,7 +12,7 @@ on: jobs: tests: - runs-on: ${{ os.matrix.os }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: From c0c639b173e79ed6dc22aca4b541efc4d7085513 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Mon, 8 Mar 2021 07:42:07 -0500 Subject: [PATCH 13/31] indent --- .github/workflows/ci_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 230acfe2..e5cbfdc2 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Install non-python dependencies on mac + - name: Install non-python dependencies on mac if: runner.os == 'macOS' run: | brew unlink gcc && brew link gcc From 0ef8c1e6c6c0fd0a022437af3bec43fa94a93bc7 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Mon, 8 Mar 2021 17:21:11 -0500 Subject: [PATCH 14/31] remove numpy and cython from pyproject --- pyproject.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8d16d98a..6dcc2e86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,5 @@ exclude = ''' requires = [ "setuptools>=40.8.0", "wheel", - "Cython>=0.22", # need for scikit-sparse - "numpy>=1.15.0" # need for scikit-sparse ] build-backend = "setuptools.build_meta" \ No newline at end of file From c76dcf1d8e9d6920ebbc91a87130b17b90b4f6a5 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 08:29:52 -0500 Subject: [PATCH 15/31] change jellis-> vallis and add python requirement --- .github/workflows/ci_test.yml | 4 ++-- requirements.txt | 2 +- setup.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index e5cbfdc2..4871b797 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -31,12 +31,12 @@ jobs: run: | brew unlink gcc && brew link gcc brew install automake suite-sparse - curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh - name: Install non-python dependencies on linux if: runner.os == 'Linux' run: | sudo apt-get install libsuitesparse-dev - curl -sSL https://raw.githubusercontent.com/jellis18/libstempo/master/install_tempo2.sh | sh + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh - name: Install dependencies and package run: | python -m pip install --upgrade pip setuptools wheel diff --git a/requirements.txt b/requirements.txt index 66a6495e..0c6605b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ jplephem==2.6 healpy>=1.14.0 scikit-sparse>=0.4.2 pint-pulsar>=0.8.2 -git+https://github.com/jellis18/libstempo.git@master#egg=libstempo +git+https://github.com/vallis/libstempo.git@master#egg=libstempo diff --git a/setup.py b/setup.py index de3b3667..54e380a0 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ "healpy>=1.14.0", "scikit-sparse>=0.4.2", "pint-pulsar>=0.8.2", - "libstempo @ git+https://github.com/jellis18/libstempo.git@master#egg=libstempo", + "libstempo @ git+https://github.com/vallis/libstempo.git@master#egg=libstempo", ] test_requirements = [] @@ -35,6 +35,7 @@ package_dir={"enterprise": "enterprise"}, include_package_data=True, package_data={"enterprise": ["datafiles/*", "datafiles/ephemeris/*", "datafiles/ng9/*", "datafiles/mdc_open1/*"]}, + python_requires=">=3.6, <3.9", install_requires=requirements, license="MIT license", zip_safe=False, From 76a5f7f08a5a50196089f83220a54bf62effbb42 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 09:09:36 -0500 Subject: [PATCH 16/31] Using logger and adding isort --- .pre-commit-config.yaml | 5 +++++ Makefile | 2 +- enterprise/pulsar.py | 17 ++++++++--------- enterprise/signals/selections.py | 1 - enterprise/signals/signal_base.py | 16 ++++++++-------- enterprise/signals/utils.py | 15 ++++++++------- enterprise/signals/white_signals.py | 1 - tests/test_hierarchical_parameter.py | 1 - tests/test_vector_parameter.py | 1 - 9 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6208b137..b200a92b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,8 @@ repos: hooks: - id: flake8 args: ["--config=.flake8"] +- repo: https://github.com/timothycrosley/isort + rev: 5.6.1 + hooks: + - id: isort + diff --git a/Makefile b/Makefile index 375b358a..d3d3f8ae 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ help: init: @python3 -m venv .enterprise --prompt enterprise - @./.enterprise/bin/python3 -m pip install -U pip + @./.enterprise/bin/python3 -m pip install -U pip setuptools wheel @./.enterprise/bin/python3 -m pip install numpy cython @./.enterprise/bin/python3 -m pip install -r requirements.txt -U @./.enterprise/bin/python3 -m pip install -r requirements_dev.txt -U diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index f9f5ba2e..2de0a944 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -6,8 +6,8 @@ import logging import os -import astropy.units as u import astropy.constants as const +import astropy.units as u import numpy as np from ephem import Ecliptic, Equatorial @@ -19,19 +19,21 @@ except: import pickle +logger = logging.getLogger(__name__) + try: import libstempo as t2 except ImportError: - print("Ooh, no libstempo?") + logger.warning("libstempo not installed. Will use PINT instead.") t2 = None try: import pint - from pint.toa import TOAs - from pint.models import get_model_and_toas, TimingModel + from pint.models import TimingModel, get_model_and_toas from pint.residuals import Residuals as resids + from pint.toa import TOAs except ImportError: - print("Cannot import PINT? Meh...") + logger.warning("PINT not installed. Will use libstempo instead.") pint = None @@ -39,9 +41,6 @@ err_msg = "Must have either PINT or libstempo timing package installed" raise ImportError(err_msg) -# logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.INFO) -logger = logging.getLogger(__name__) - def get_maxobs(timfile): """Utility function to return number of lines in tim file. @@ -575,4 +574,4 @@ def Pulsar(*args, **kwargs): os.chdir(cwd) return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets) else: - print("Unknown arguments {}".format(args)) + logger.error("Unknown arguments {}".format(args)) diff --git a/enterprise/signals/selections.py b/enterprise/signals/selections.py index f7de81d0..daeac4e9 100644 --- a/enterprise/signals/selections.py +++ b/enterprise/signals/selections.py @@ -2,7 +2,6 @@ """Contains various selection functions to mask parameters by backend flags, time-intervals, etc.""" -from __future__ import absolute_import, division, print_function, unicode_literals import functools import inspect diff --git a/enterprise/signals/signal_base.py b/enterprise/signals/signal_base.py index f4e3c07f..cb0cc787 100644 --- a/enterprise/signals/signal_base.py +++ b/enterprise/signals/signal_base.py @@ -3,14 +3,13 @@ Defines the signal base classes and metaclasses. All signals will then be derived from these base classes. """ -from __future__ import absolute_import, division, print_function, unicode_literals - import collections try: from collections.abc import Sequence except: from collections import Sequence + import itertools import logging @@ -546,10 +545,11 @@ def _setpulsarcliques(self, slices, phis): try: self._cliques[slices[sc].start + phiind] = self._clcount self._clcount = self._clcount + 1 - except: - print(self._cliques.shape) - print("phiind", phiind, len(phiind)) - print(slices) + except Exception: + logger.exception("Exception raised in computing cliques") + logger.info(self._cliques.shape) + logger.info("phiind", phiind, len(phiind)) + logger.info(slices) raise def get_phi(self, params, cliques=False): @@ -654,7 +654,7 @@ def summary(self, include_params=True, to_stdout=False): :param include_params: [bool] list all parameters for each signal :param to_stdout: [bool] - print summary to `stdout` instead of returning it + logger.info summary to `stdout` instead of returning it :return: [string] """ summary = "" @@ -684,7 +684,7 @@ def summary(self, include_params=True, to_stdout=False): summary += "Fixed params: {}\n".format(copcount) summary += "Number of pulsars: {}\n".format(len(self._signalcollections)) if to_stdout: - print(summary) + logger.info(summary) else: return summary diff --git a/enterprise/signals/utils.py b/enterprise/signals/utils.py index fe1f1ccc..e90ea0cd 100644 --- a/enterprise/signals/utils.py +++ b/enterprise/signals/utils.py @@ -4,7 +4,7 @@ functions for use in other modules. """ -from __future__ import absolute_import, division, print_function, unicode_literals +import logging import numpy as np import scipy.linalg as sl @@ -16,22 +16,23 @@ import enterprise from enterprise import constants as const -from enterprise.signals.parameter import function -from enterprise.signals.gp_priors import powerlaw, turnover # noqa: F401 from enterprise import signals as sigs # noqa: F401 from enterprise.signals.gp_bases import ( # noqa: F401 - createfourierdesignmatrix_red, createfourierdesignmatrix_dm, createfourierdesignmatrix_env, - createfourierdesignmatrix_ephem, createfourierdesignmatrix_eph, + createfourierdesignmatrix_ephem, + createfourierdesignmatrix_red, ) +from enterprise.signals.gp_priors import powerlaw, turnover # noqa: F401 +from enterprise.signals.parameter import function +logger = logging.getLogger(__name__) try: from sksparse.cholmod import cholesky -except: - print("You'll need sksparse for get_coefficients() with common signals!") +except ImportError: + logger.warning("sksparse not installed. You'll need sksparse for get_coefficients() with common signals!") def get_coefficients(pta, params, n=1, phiinv_method="cliques", common_sparse=False): diff --git a/enterprise/signals/white_signals.py b/enterprise/signals/white_signals.py index d6703c1d..95b78871 100644 --- a/enterprise/signals/white_signals.py +++ b/enterprise/signals/white_signals.py @@ -3,7 +3,6 @@ defined as the class of signals that only modifies the white noise matrix `N`. """ -from __future__ import absolute_import, division, print_function, unicode_literals import numpy as np import scipy.sparse diff --git a/tests/test_hierarchical_parameter.py b/tests/test_hierarchical_parameter.py index b84f7bc7..9e767a0c 100644 --- a/tests/test_hierarchical_parameter.py +++ b/tests/test_hierarchical_parameter.py @@ -8,7 +8,6 @@ Tests for hierarchical parameter functionality """ -from __future__ import division import unittest diff --git a/tests/test_vector_parameter.py b/tests/test_vector_parameter.py index 77ae9faf..3d4b31d6 100644 --- a/tests/test_vector_parameter.py +++ b/tests/test_vector_parameter.py @@ -8,7 +8,6 @@ Tests for vector parameter functionality """ -from __future__ import division import unittest From 72fbfe40b55de72127b39e38fe8bf4046d4918f1 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 09:09:57 -0500 Subject: [PATCH 17/31] isort config --- .isort.cfg | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..b52cc737 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,6 @@ +[settings] +include_trailing_comma=True +indent=' ' +dedup_headings=True +line_length=120 +multi_line_output=3 \ No newline at end of file From 6f8926c0801b361e02738a73f8f82f3f528013b2 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 09:12:39 -0500 Subject: [PATCH 18/31] logger.info -> print in docsting --- enterprise/signals/signal_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enterprise/signals/signal_base.py b/enterprise/signals/signal_base.py index cb0cc787..3cc1cc2c 100644 --- a/enterprise/signals/signal_base.py +++ b/enterprise/signals/signal_base.py @@ -654,7 +654,7 @@ def summary(self, include_params=True, to_stdout=False): :param include_params: [bool] list all parameters for each signal :param to_stdout: [bool] - logger.info summary to `stdout` instead of returning it + print summary to `stdout` instead of returning it :return: [string] """ summary = "" From 2b36b1e52e40e50034ed22d12103269a87fcad86 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 11:14:07 -0500 Subject: [PATCH 19/31] Adding wheels and pypi --- .github/workflows/ci_test.yml | 74 ++++++++++++++++++++++++++++++++++- Makefile | 2 +- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 4871b797..4f8a57b0 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -56,4 +56,76 @@ jobs: - name: Codecov uses: codecov/codecov-action@v1 with: - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true + + + build: + needs: [tests] + name: Build source distribution + runs-on: ubuntu-latest + if: github.event_name == 'release' + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + - name: Install non-python dependencies on linux + run: | + sudo apt-get install libsuitesparse-dev + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh + - name: Build + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -r requirements.txt + make dist + - name: Test the sdist + run: | + mkdir tmp + cd tmp + python -m venv venv-sdist + venv-sdist/bin/python -m pip install --upgrade pip setuptools wheel + venv-sdist/bin/python -m pip install numpy cython + venv-sdist/bin/python -m pip install ../dist/enterprise*.tar.gz + venv-sdist/bin/python -c "import enterprise;print(enterprise.__version__)" + - name: Test the wheel + run: | + mkdir tmp2 + cd tmp2 + python -m venv venv-wheel + venv-wheel/bin/python -m pip install --upgrade pip setuptools + venv-wheel/bin/python -m pip install numpy cython + venv-wheel/bin/python -m pip install ../dist/enterprise*.whl + venv-wheel/bin/python -c "import enterprise;print(enterprise.__version__)" + - uses: actions/upload-artifact@v2 + with: + name: dist + path: dist/* + + + deploy: + needs: [tests, build] + runs-on: ubuntu-latest + if: github.event_name == 'release' + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Download wheel/dist from build + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* \ No newline at end of file diff --git a/Makefile b/Makefile index d3d3f8ae..43a59b17 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ clean-test: ## remove test and coverage artifacts rm -fr htmlcov/ test: lint ## run tests quickly with the default Python - pytest -v --full-trace --cov-config .coveragerc --cov=enterprise tests + pytest -v --durations=10 --full-trace --cov-config .coveragerc --cov=enterprise tests #test-all: ## run tests on every Python version with tox # tox From 7bf63850e01516623022a92bbc365f1a19e1cd1d Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 15:18:37 -0500 Subject: [PATCH 20/31] Adding "build requirements" for scikit-sparse --- .github/workflows/ci_test.yml | 1 + enterprise/pulsar.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 4f8a57b0..7fb1b01c 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -78,6 +78,7 @@ jobs: - name: Build run: | python -m pip install --upgrade pip setuptools wheel + pip install numpy==1.16.3 cython pip install -r requirements.txt make dist - name: Test the sdist diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index 2de0a944..88bd7e9e 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -118,7 +118,7 @@ def sort_data(self): """Sort data by time.""" if self._sort: self._isort = np.argsort(self._toas, kind="mergesort") - self._iisort = np.zeros(len(self._isort), dtype=np.int) + self._iisort = np.zeros(len(self._isort), dtype=int) for ii, p in enumerate(self._isort): self._iisort[p] = ii else: From 8da5573add417ed9df157c7ac5f3332ded8f4de6 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sat, 13 Mar 2021 18:05:36 -0500 Subject: [PATCH 21/31] Updating github actions and requirements (#3) * Updating github actions * Update CI * add numpy cython install * Check brew list * Automake * gfortran * alias * environment variable * brew link * try again * one block * fix typo * indent * remove numpy and cython from pyproject * change jellis-> vallis and add python requirement * Using logger and adding isort * isort config * logger.info -> print in docsting * Adding wheels and pypi * Adding "build requirements" for scikit-sparse --- .github/workflows/ci_test.yml | 127 ++++++++++++++++++++++----- .isort.cfg | 6 ++ .pre-commit-config.yaml | 5 ++ Makefile | 8 +- enterprise/pulsar.py | 19 ++-- enterprise/signals/selections.py | 1 - enterprise/signals/signal_base.py | 14 +-- enterprise/signals/utils.py | 15 ++-- enterprise/signals/white_signals.py | 1 - pyproject.toml | 10 ++- requirements.txt | 8 +- setup.py | 10 ++- tests/test_hierarchical_parameter.py | 1 - tests/test_pulsar.py | 8 ++ tests/test_vector_parameter.py | 1 - 15 files changed, 170 insertions(+), 64 deletions(-) create mode 100644 .isort.cfg diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 1afa64b7..7fb1b01c 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -1,51 +1,132 @@ -name: CI-Tests +name: enterprise CI targets on: push: -# branches: -# - master + branches: [ master ] pull_request: + branches: [ master ] + release: + types: + - published + jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: psf/black@stable - build: - runs-on: ubuntu-latest + tests: + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: + os: [ubuntu-latest, macos-latest] python-version: [3.6, 3.7, 3.8] + steps: - - name: Checkout Repository + - name: Checkout repository uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pre-install + - name: Install non-python dependencies on mac + if: runner.os == 'macOS' + run: | + brew unlink gcc && brew link gcc + brew install automake suite-sparse + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh + - name: Install non-python dependencies on linux + if: runner.os == 'Linux' run: | sudo apt-get install libsuitesparse-dev - python -m pip install --upgrade pip - - name: Install Dependencies + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh + - name: Install dependencies and package run: | - cat requirements_dev.txt | xargs -n 1 -L 1 pip install - cat requirements.txt | xargs -n 1 -L 1 pip install - python setup.py install + python -m pip install --upgrade pip setuptools wheel + python -m pip install flake8 pytest black pytest-cov + python -m pip install numpy cython + python -m pip install -e . - name: Display Python, pip, setuptools, and all installed versions run: | python -c "import sys; print(f'Python {sys.version}')" python -c "import pip; print(f'pip {pip.__version__}')" python -c "import setuptools; print(f'setuptools {setuptools.__version__}')" - pip freeze - - name: Run Tests and Lint - run: | - pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml - make lint + python -m pip freeze + - name: Run lint + run: make lint + - name: Test with pytest + run: pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml - name: Codecov uses: codecov/codecov-action@v1 with: fail_ci_if_error: true + + + build: + needs: [tests] + name: Build source distribution + runs-on: ubuntu-latest + if: github.event_name == 'release' + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + - name: Install non-python dependencies on linux + run: | + sudo apt-get install libsuitesparse-dev + curl -sSL https://raw.githubusercontent.com/vallis/libstempo/master/install_tempo2.sh | sh + - name: Build + run: | + python -m pip install --upgrade pip setuptools wheel + pip install numpy==1.16.3 cython + pip install -r requirements.txt + make dist + - name: Test the sdist + run: | + mkdir tmp + cd tmp + python -m venv venv-sdist + venv-sdist/bin/python -m pip install --upgrade pip setuptools wheel + venv-sdist/bin/python -m pip install numpy cython + venv-sdist/bin/python -m pip install ../dist/enterprise*.tar.gz + venv-sdist/bin/python -c "import enterprise;print(enterprise.__version__)" + - name: Test the wheel + run: | + mkdir tmp2 + cd tmp2 + python -m venv venv-wheel + venv-wheel/bin/python -m pip install --upgrade pip setuptools + venv-wheel/bin/python -m pip install numpy cython + venv-wheel/bin/python -m pip install ../dist/enterprise*.whl + venv-wheel/bin/python -c "import enterprise;print(enterprise.__version__)" + - uses: actions/upload-artifact@v2 + with: + name: dist + path: dist/* + + + deploy: + needs: [tests, build] + runs-on: ubuntu-latest + if: github.event_name == 'release' + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Download wheel/dist from build + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* \ No newline at end of file diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..b52cc737 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,6 @@ +[settings] +include_trailing_comma=True +indent=' ' +dedup_headings=True +line_length=120 +multi_line_output=3 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6208b137..b200a92b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,8 @@ repos: hooks: - id: flake8 args: ["--config=.flake8"] +- repo: https://github.com/timothycrosley/isort + rev: 5.6.1 + hooks: + - id: isort + diff --git a/Makefile b/Makefile index e15585cf..43a59b17 100644 --- a/Makefile +++ b/Makefile @@ -28,10 +28,10 @@ help: init: @python3 -m venv .enterprise --prompt enterprise - @./.enterprise/bin/python3 -m pip install numpy + @./.enterprise/bin/python3 -m pip install -U pip setuptools wheel + @./.enterprise/bin/python3 -m pip install numpy cython @./.enterprise/bin/python3 -m pip install -r requirements.txt -U @./.enterprise/bin/python3 -m pip install -r requirements_dev.txt -U - @./.enterprise/bin/python3 -m pip install libstempo --install-option="--with-tempo2=$(TEMPO2)" @./.enterprise/bin/python3 -m pre_commit install --install-hooks --overwrite @./.enterprise/bin/python3 -m pip install -e . @@ -62,8 +62,8 @@ clean-test: ## remove test and coverage artifacts rm -f .coverage rm -fr htmlcov/ -test: ## run tests quickly with the default Python - pytest -v --full-trace --cov-config .coveragerc --cov=enterprise tests +test: lint ## run tests quickly with the default Python + pytest -v --durations=10 --full-trace --cov-config .coveragerc --cov=enterprise tests #test-all: ## run tests on every Python version with tox # tox diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index f9f5ba2e..88bd7e9e 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -6,8 +6,8 @@ import logging import os -import astropy.units as u import astropy.constants as const +import astropy.units as u import numpy as np from ephem import Ecliptic, Equatorial @@ -19,19 +19,21 @@ except: import pickle +logger = logging.getLogger(__name__) + try: import libstempo as t2 except ImportError: - print("Ooh, no libstempo?") + logger.warning("libstempo not installed. Will use PINT instead.") t2 = None try: import pint - from pint.toa import TOAs - from pint.models import get_model_and_toas, TimingModel + from pint.models import TimingModel, get_model_and_toas from pint.residuals import Residuals as resids + from pint.toa import TOAs except ImportError: - print("Cannot import PINT? Meh...") + logger.warning("PINT not installed. Will use libstempo instead.") pint = None @@ -39,9 +41,6 @@ err_msg = "Must have either PINT or libstempo timing package installed" raise ImportError(err_msg) -# logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.INFO) -logger = logging.getLogger(__name__) - def get_maxobs(timfile): """Utility function to return number of lines in tim file. @@ -119,7 +118,7 @@ def sort_data(self): """Sort data by time.""" if self._sort: self._isort = np.argsort(self._toas, kind="mergesort") - self._iisort = np.zeros(len(self._isort), dtype=np.int) + self._iisort = np.zeros(len(self._isort), dtype=int) for ii, p in enumerate(self._isort): self._iisort[p] = ii else: @@ -575,4 +574,4 @@ def Pulsar(*args, **kwargs): os.chdir(cwd) return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets) else: - print("Unknown arguments {}".format(args)) + logger.error("Unknown arguments {}".format(args)) diff --git a/enterprise/signals/selections.py b/enterprise/signals/selections.py index f7de81d0..daeac4e9 100644 --- a/enterprise/signals/selections.py +++ b/enterprise/signals/selections.py @@ -2,7 +2,6 @@ """Contains various selection functions to mask parameters by backend flags, time-intervals, etc.""" -from __future__ import absolute_import, division, print_function, unicode_literals import functools import inspect diff --git a/enterprise/signals/signal_base.py b/enterprise/signals/signal_base.py index f4e3c07f..3cc1cc2c 100644 --- a/enterprise/signals/signal_base.py +++ b/enterprise/signals/signal_base.py @@ -3,14 +3,13 @@ Defines the signal base classes and metaclasses. All signals will then be derived from these base classes. """ -from __future__ import absolute_import, division, print_function, unicode_literals - import collections try: from collections.abc import Sequence except: from collections import Sequence + import itertools import logging @@ -546,10 +545,11 @@ def _setpulsarcliques(self, slices, phis): try: self._cliques[slices[sc].start + phiind] = self._clcount self._clcount = self._clcount + 1 - except: - print(self._cliques.shape) - print("phiind", phiind, len(phiind)) - print(slices) + except Exception: + logger.exception("Exception raised in computing cliques") + logger.info(self._cliques.shape) + logger.info("phiind", phiind, len(phiind)) + logger.info(slices) raise def get_phi(self, params, cliques=False): @@ -684,7 +684,7 @@ def summary(self, include_params=True, to_stdout=False): summary += "Fixed params: {}\n".format(copcount) summary += "Number of pulsars: {}\n".format(len(self._signalcollections)) if to_stdout: - print(summary) + logger.info(summary) else: return summary diff --git a/enterprise/signals/utils.py b/enterprise/signals/utils.py index fe1f1ccc..e90ea0cd 100644 --- a/enterprise/signals/utils.py +++ b/enterprise/signals/utils.py @@ -4,7 +4,7 @@ functions for use in other modules. """ -from __future__ import absolute_import, division, print_function, unicode_literals +import logging import numpy as np import scipy.linalg as sl @@ -16,22 +16,23 @@ import enterprise from enterprise import constants as const -from enterprise.signals.parameter import function -from enterprise.signals.gp_priors import powerlaw, turnover # noqa: F401 from enterprise import signals as sigs # noqa: F401 from enterprise.signals.gp_bases import ( # noqa: F401 - createfourierdesignmatrix_red, createfourierdesignmatrix_dm, createfourierdesignmatrix_env, - createfourierdesignmatrix_ephem, createfourierdesignmatrix_eph, + createfourierdesignmatrix_ephem, + createfourierdesignmatrix_red, ) +from enterprise.signals.gp_priors import powerlaw, turnover # noqa: F401 +from enterprise.signals.parameter import function +logger = logging.getLogger(__name__) try: from sksparse.cholmod import cholesky -except: - print("You'll need sksparse for get_coefficients() with common signals!") +except ImportError: + logger.warning("sksparse not installed. You'll need sksparse for get_coefficients() with common signals!") def get_coefficients(pta, params, n=1, phiinv_method="cliques", common_sparse=False): diff --git a/enterprise/signals/white_signals.py b/enterprise/signals/white_signals.py index d6703c1d..95b78871 100644 --- a/enterprise/signals/white_signals.py +++ b/enterprise/signals/white_signals.py @@ -3,7 +3,6 @@ defined as the class of signals that only modifies the white noise matrix `N`. """ -from __future__ import absolute_import, division, print_function, unicode_literals import numpy as np import scipy.sparse diff --git a/pyproject.toml b/pyproject.toml index 571df8af..6dcc2e86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,11 @@ exclude = ''' | .enterprise | enterprise/src )/ - | foo.py # also separately exclude a file named foo.py in - # the root of the project ) -''' \ No newline at end of file +''' +[build-system] +requires = [ + "setuptools>=40.8.0", + "wheel", +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 35be0917..0c6605b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,8 @@ numpy>=1.16.3 scipy>=1.2.0 ephem>=3.7.6.0 -Cython>=0.28.5 jplephem==2.6 -setuptools>=40.0.0 healpy>=1.14.0 -scikit-sparse>=0.4.2 --no-binary scikit-sparse -git+https://github.com/nanograv/PINT.git@master#egg=pint-pulsar -git+https://github.com/vallis/libstempo.git@master#egg=libstempo --install-option="--force-tempo2-install" +scikit-sparse>=0.4.2 +pint-pulsar>=0.8.2 +git+https://github.com/vallis/libstempo.git@master#egg=libstempo diff --git a/setup.py b/setup.py index f1575ce0..54e380a0 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,14 @@ history = history_file.read() requirements = [ - # TODO: put package requirements here + "numpy>=1.16.3", + "scipy>=1.2.0", + "ephem>=3.7.6.0", + "jplephem==2.6", + "healpy>=1.14.0", + "scikit-sparse>=0.4.2", + "pint-pulsar>=0.8.2", + "libstempo @ git+https://github.com/vallis/libstempo.git@master#egg=libstempo", ] test_requirements = [] @@ -28,6 +35,7 @@ package_dir={"enterprise": "enterprise"}, include_package_data=True, package_data={"enterprise": ["datafiles/*", "datafiles/ephemeris/*", "datafiles/ng9/*", "datafiles/mdc_open1/*"]}, + python_requires=">=3.6, <3.9", install_requires=requirements, license="MIT license", zip_safe=False, diff --git a/tests/test_hierarchical_parameter.py b/tests/test_hierarchical_parameter.py index b84f7bc7..9e767a0c 100644 --- a/tests/test_hierarchical_parameter.py +++ b/tests/test_hierarchical_parameter.py @@ -8,7 +8,6 @@ Tests for hierarchical parameter functionality """ -from __future__ import division import unittest diff --git a/tests/test_pulsar.py b/tests/test_pulsar.py index 95cad51e..41fb6901 100644 --- a/tests/test_pulsar.py +++ b/tests/test_pulsar.py @@ -10,6 +10,8 @@ """ +import os +import shutil import unittest import numpy as np @@ -31,6 +33,10 @@ def setUpClass(cls): # initialize Pulsar class cls.psr = Pulsar(datadir + "/B1855+09_NANOGrav_9yv1.gls.par", datadir + "/B1855+09_NANOGrav_9yv1.tim") + @classmethod + def tearDownClass(cls): + shutil.rmtree("pickle_dir") + def test_residuals(self): """Check Residual shape.""" @@ -117,6 +123,8 @@ def test_to_pickle(self): with open("B1855+09.pkl", "rb") as f: pkl_psr = pickle.load(f) + os.remove("B1855+09.pkl") + assert np.allclose(self.psr.residuals, pkl_psr.residuals, rtol=1e-10) self.psr.to_pickle("pickle_dir") diff --git a/tests/test_vector_parameter.py b/tests/test_vector_parameter.py index 77ae9faf..3d4b31d6 100644 --- a/tests/test_vector_parameter.py +++ b/tests/test_vector_parameter.py @@ -8,7 +8,6 @@ Tests for vector parameter functionality """ -from __future__ import division import unittest From d930cbf280424042c0b64ea459ee1f2b67f76ed7 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 14 Mar 2021 09:23:55 -0400 Subject: [PATCH 22/31] Naming to enterprise-pulsar for pypi --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 54e380a0..baf7b32a 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setup( - name="enterprise", + name="enterprise-pulsar", version="3.0.0", description="ENTERPRISE (Enhanced Numerical Toolbox Enabling a Robust PulsaR Inference SuitE)", long_description=readme + "\n\n" + history, From 104594fb36761bafc6e7a45321aeb28fd9ed15f6 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Fri, 19 Mar 2021 09:41:07 -0400 Subject: [PATCH 23/31] Small changes to makefile --- .github/workflows/ci_test.yml | 2 +- Makefile | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 7fb1b01c..ca391db6 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -52,7 +52,7 @@ jobs: - name: Run lint run: make lint - name: Test with pytest - run: pytest --cov-config=.coveragerc --cov=enterprise --cov-report=xml + run: make test - name: Codecov uses: codecov/codecov-action@v1 with: diff --git a/Makefile b/Makefile index 43a59b17..3e7ba194 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,8 @@ init: @./.enterprise/bin/python3 -m pip install -r requirements_dev.txt -U @./.enterprise/bin/python3 -m pre_commit install --install-hooks --overwrite @./.enterprise/bin/python3 -m pip install -e . + @echo "run source .enterprise/bin/activate to activate environment" + format: black . @@ -61,24 +63,18 @@ clean-test: ## remove test and coverage artifacts rm -fr .tox/ rm -f .coverage rm -fr htmlcov/ + rm -rf coverage.xml test: lint ## run tests quickly with the default Python - pytest -v --durations=10 --full-trace --cov-config .coveragerc --cov=enterprise tests - -#test-all: ## run tests on every Python version with tox -# tox + pytest -v --durations=10 --full-trace --cov-report html --cov-report xml --cov-config .coveragerc --cov=enterprise tests -coverage: ## check code coverage quickly with the default Python - coverage run --source enterprise setup.py test - coverage report -m - coverage html +coverage: test ## check code coverage quickly with the default Python $(BROWSER) htmlcov/index.html jupyter-docs: jupyter nbconvert --template docs/nb-rst.tpl --to rst docs/_static/notebooks/*.ipynb --output-dir docs/ cp -r docs/_static/notebooks/img docs/ - #jupyter nbconvert --template docs/nb-rst.tpl --to rst docs/_static/notebooks/tutorials/*.ipynb --output-dir docs/tutorials/ docs: ## generate Sphinx HTML documentation, including API docs rm -f docs/enterprise*.rst From 9e807219e7d2b0d447f6a06ae5de927e1aa554f9 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 21 Mar 2021 07:58:04 -0400 Subject: [PATCH 24/31] Add coverage percent to test --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3e7ba194..1e69d5fe 100644 --- a/Makefile +++ b/Makefile @@ -65,8 +65,11 @@ clean-test: ## remove test and coverage artifacts rm -fr htmlcov/ rm -rf coverage.xml +COV_COVERAGE_PERCENT ?= 85 test: lint ## run tests quickly with the default Python - pytest -v --durations=10 --full-trace --cov-report html --cov-report xml --cov-config .coveragerc --cov=enterprise tests + pytest -v --durations=10 --full-trace --cov-report html --cov-report xml \ + --cov-config .coveragerc --cov-fail-under=$(COV_COVERAGE_PERCENT) \ + --cov=enterprise tests coverage: test ## check code coverage quickly with the default Python From e0e767266b83e4c596481c9e05b7dae7c7627d67 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 21 Mar 2021 08:03:23 -0400 Subject: [PATCH 25/31] More cleaning of makefile --- Makefile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1e69d5fe..93f3e3cf 100644 --- a/Makefile +++ b/Makefile @@ -71,11 +71,10 @@ test: lint ## run tests quickly with the default Python --cov-config .coveragerc --cov-fail-under=$(COV_COVERAGE_PERCENT) \ --cov=enterprise tests - coverage: test ## check code coverage quickly with the default Python $(BROWSER) htmlcov/index.html -jupyter-docs: +jupyter-docs: ## biuld jupyter notebook docs jupyter nbconvert --template docs/nb-rst.tpl --to rst docs/_static/notebooks/*.ipynb --output-dir docs/ cp -r docs/_static/notebooks/img docs/ @@ -91,14 +90,7 @@ docs: ## generate Sphinx HTML documentation, including API docs servedocs: docs ## compile the docs watching for changes watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . -release: clean ## package and upload a release - python setup.py sdist upload - python setup.py bdist_wheel upload - dist: clean ## builds source and wheel package python setup.py sdist python setup.py bdist_wheel ls -l dist - -install: clean ## install the package to the active Python's site-packages - python setup.py install From 171d56c8fb37db52df0695a63315fc62b4a180a7 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 21 Mar 2021 09:01:24 -0400 Subject: [PATCH 26/31] log-level info in tests --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 93f3e3cf..e87c10eb 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ COV_COVERAGE_PERCENT ?= 85 test: lint ## run tests quickly with the default Python pytest -v --durations=10 --full-trace --cov-report html --cov-report xml \ --cov-config .coveragerc --cov-fail-under=$(COV_COVERAGE_PERCENT) \ - --cov=enterprise tests + --log-level=INFO --cov=enterprise tests coverage: test ## check code coverage quickly with the default Python $(BROWSER) htmlcov/index.html From 3b3c8c1310f52eb545cfcfa8b9c031c7a74ed6ea Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 21 Mar 2021 09:07:14 -0400 Subject: [PATCH 27/31] Udating contributing --- CONTRIBUTING.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 27469e39..5fc127d7 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -72,14 +72,15 @@ Ready to contribute? Here's how to set up `enterprise` for local development. $ git pull upstream master -4. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: +4. This is how you set up your fork for local development:: + + .. note:: + You will need to have ``tempo`` and ``suitesparse`` installed before + running the commands below. - $ mkvirtualenv enterprise $ cd enterprise/ - $ pip install -r requirements_dev.txt - $ pip install -r requirements.txt - $ pip install libstempo --install-option="--with-tempo2=$TEMPO2" - $ python setup.py develop + $ make init + $ source .enterprise/bin/activate 5. Create a branch for local development:: From 4b61097b175d15a42b4eaebc36a0296281cbaa7d Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Sun, 21 Mar 2021 10:04:54 -0400 Subject: [PATCH 28/31] Fix contributing.rst --- CONTRIBUTING.rst | 4 +++- Makefile | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5fc127d7..ad6c38ec 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -72,12 +72,14 @@ Ready to contribute? Here's how to set up `enterprise` for local development. $ git pull upstream master -4. This is how you set up your fork for local development:: +4. This is how you set up your fork for local development: .. note:: You will need to have ``tempo`` and ``suitesparse`` installed before running the commands below. + :: + $ cd enterprise/ $ make init $ source .enterprise/bin/activate diff --git a/Makefile b/Makefile index e87c10eb..93f3e3cf 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ COV_COVERAGE_PERCENT ?= 85 test: lint ## run tests quickly with the default Python pytest -v --durations=10 --full-trace --cov-report html --cov-report xml \ --cov-config .coveragerc --cov-fail-under=$(COV_COVERAGE_PERCENT) \ - --log-level=INFO --cov=enterprise tests + --cov=enterprise tests coverage: test ## check code coverage quickly with the default Python $(BROWSER) htmlcov/index.html From 2f0021a6ed1855a4da04f9e0c383de6afc40cd2c Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Wed, 24 Mar 2021 07:37:10 -0400 Subject: [PATCH 29/31] Adding libstempo pypi and dropping CI fail for coverage --- .github/workflows/ci_test.yml | 4 ++-- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index ca391db6..b07cfcb3 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -55,8 +55,8 @@ jobs: run: make test - name: Codecov uses: codecov/codecov-action@v1 - with: - fail_ci_if_error: true + #with: + # fail_ci_if_error: true build: diff --git a/requirements.txt b/requirements.txt index 0c6605b6..692e4acd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ jplephem==2.6 healpy>=1.14.0 scikit-sparse>=0.4.2 pint-pulsar>=0.8.2 -git+https://github.com/vallis/libstempo.git@master#egg=libstempo +libstempo>=2.4.0 diff --git a/setup.py b/setup.py index baf7b32a..5ab831a4 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ "healpy>=1.14.0", "scikit-sparse>=0.4.2", "pint-pulsar>=0.8.2", - "libstempo @ git+https://github.com/vallis/libstempo.git@master#egg=libstempo", + "libstempo>=2.4.0", ] test_requirements = [] From f35c2a33b745e73cf7229315551343b37e9e61d9 Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Thu, 25 Mar 2021 08:04:32 -0400 Subject: [PATCH 30/31] adding no-cover to exceptions --- enterprise/pulsar.py | 6 +++--- enterprise/signals/signal_base.py | 2 +- enterprise/signals/utils.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index 88bd7e9e..b35ac3bf 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -24,7 +24,7 @@ try: import libstempo as t2 except ImportError: - logger.warning("libstempo not installed. Will use PINT instead.") + logger.warning("libstempo not installed. Will use PINT instead.") # pragma: no cover t2 = None try: @@ -33,7 +33,7 @@ from pint.residuals import Residuals as resids from pint.toa import TOAs except ImportError: - logger.warning("PINT not installed. Will use libstempo instead.") + logger.warning("PINT not installed. Will use libstempo instead.") # pragma: no cover pint = None @@ -574,4 +574,4 @@ def Pulsar(*args, **kwargs): os.chdir(cwd) return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets) else: - logger.error("Unknown arguments {}".format(args)) + logger.error("Unknown arguments {}".format(args)) # pragma: no cover diff --git a/enterprise/signals/signal_base.py b/enterprise/signals/signal_base.py index 3cc1cc2c..306db7e2 100644 --- a/enterprise/signals/signal_base.py +++ b/enterprise/signals/signal_base.py @@ -545,7 +545,7 @@ def _setpulsarcliques(self, slices, phis): try: self._cliques[slices[sc].start + phiind] = self._clcount self._clcount = self._clcount + 1 - except Exception: + except Exception: # pragma: no cover logger.exception("Exception raised in computing cliques") logger.info(self._cliques.shape) logger.info("phiind", phiind, len(phiind)) diff --git a/enterprise/signals/utils.py b/enterprise/signals/utils.py index e90ea0cd..045ff9d4 100644 --- a/enterprise/signals/utils.py +++ b/enterprise/signals/utils.py @@ -31,7 +31,7 @@ try: from sksparse.cholmod import cholesky -except ImportError: +except ImportError: # pragma no cover logger.warning("sksparse not installed. You'll need sksparse for get_coefficients() with common signals!") From d46f2e53ff90f18af23ed93010798aadc768a6ba Mon Sep 17 00:00:00 2001 From: Justin Ellis Date: Thu, 25 Mar 2021 08:14:17 -0400 Subject: [PATCH 31/31] Updated test --- enterprise/pulsar.py | 4 ++-- tests/test_pulsar.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index b35ac3bf..11e0a40d 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -573,5 +573,5 @@ def Pulsar(*args, **kwargs): t2pulsar = t2.tempopulsar(relparfile, reltimfile, maxobs=maxobs, ephem=ephem, clk=clk) os.chdir(cwd) return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets) - else: - logger.error("Unknown arguments {}".format(args)) # pragma: no cover + + raise ValueError("Unknown arguments {}".format(args)) diff --git a/tests/test_pulsar.py b/tests/test_pulsar.py index 41fb6901..d4a269f6 100644 --- a/tests/test_pulsar.py +++ b/tests/test_pulsar.py @@ -142,6 +142,12 @@ def test_wrong_input(self): msg = "Cannot find parfile wrong.par or timfile wrong.tim!" self.assertTrue(msg in context.exception) + def test_value_error(self): + """Test exception when unknown argument is given""" + + with self.assertRaises(ValueError): + Pulsar(datadir + "/B1855+09_NANOGrav_9yv1.gls.par", datadir + "/B1855+09_NANOGrav_9yv1.time") + class TestPulsarPint(TestPulsar): @classmethod