From 4e363a2bb8753e903d516b4bf60e637007514105 Mon Sep 17 00:00:00 2001 From: Howard Isaacson Date: Wed, 8 Apr 2026 11:55:02 -0700 Subject: [PATCH] Working toward pip-installation. --- MANIFEST.in | 33 ++++-------------- README.rst | 63 ++++++++++++++++++++++++++++++++--- docs/source/popsycle_docs.rst | 36 +++++++++++++++++--- environment.yml | 26 +++++++++++++++ popsycle/run.py | 54 ++++++++++++++++++++++++------ pyproject.toml | 7 ++-- requirements.txt | 3 ++ setup.cfg | 47 ++++++++++++++++++++++---- setup.py | 16 +-------- 9 files changed, 217 insertions(+), 68 deletions(-) create mode 100644 environment.yml diff --git a/MANIFEST.in b/MANIFEST.in index 39c0fac8..c0bc63a6 100755 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,39 +1,18 @@ include README.rst -include CHANGES.rst - -include ah_bootstrap.py include setup.cfg +include pyproject.toml +include requirements.txt +include environment.yml +include contributors.md include popsycle/tests/coveragerc -recursive-include popsycle *.pyx *.c *.pxd +recursive-include popsycle *.py *.npz *.yaml *.rst recursive-include docs * recursive-include licenses * -recursive-include cextern * -recursive-include scripts * prune build +prune dist prune docs/_build prune docs/api - -# the next few stanzas are for astropy_helpers. It's derived from the -# astropy_helpers/MANIFEST.in, but requires additional includes for the actual -# package directory and egg-info. - -include astropy_helpers/README.rst -include astropy_helpers/CHANGES.rst -include astropy_helpers/LICENSE.rst -recursive-include astropy_helpers/licenses * - -include astropy_helpers/ah_bootstrap.py - -recursive-include astropy_helpers/astropy_helpers *.py *.pyx *.c *.h *.rst -recursive-include astropy_helpers/astropy_helpers.egg-info * -# include the sphinx stuff with "*" because there are css/html/rst/etc. -recursive-include astropy_helpers/astropy_helpers/sphinx * - -prune astropy_helpers/build -prune astropy_helpers/astropy_helpers/tests - - global-exclude *.pyc *.o diff --git a/README.rst b/README.rst index 3c364613..8be1b787 100755 --- a/README.rst +++ b/README.rst @@ -26,13 +26,68 @@ found at our galaxia GitHub repo: https://github.com/jluastro/galaxia. Installation ------------ -To install PopSyCLE, clone the GitHub repository and add the repository's -path to your `PYTHONPATH`. For example: +PopSyCLE is packaged and can be installed directly with either conda or pip. +For the full pipeline, use **Python 3.11**. This is the compatible overlap for +the current SPISEA and BAGLE dependency stack. + +Conda installation +^^^^^^^^^^^^^^^^^^ + +The repository ships with an ``environment.yml`` that installs the Python +dependencies and installs PopSyCLE in editable mode. + +.. code-block:: bash + + git clone https://github.com/MovingUniverseLab/PopSyCLE.git + cd PopSyCLE + conda env create -f environment.yml + conda activate popsycle + +Pip installation +^^^^^^^^^^^^^^^^ + +If you prefer virtual environments or already manage Python outside conda, +install PopSyCLE directly with pip: .. code-block:: bash - git clone git@github.com:jluastro/PopSyCLE.git - echo "export PYTHONPATH=$PWD/PopSyCLE:$PYTHONPATH" >> ~/.bashrc + git clone https://github.com/MovingUniverseLab/PopSyCLE.git + cd PopSyCLE + python3.11 -m venv .venv + source .venv/bin/activate + python -m pip install --upgrade pip + python -m pip install -e . + +SPISEA +^^^^^^ + +SPISEA is still distributed upstream as a source checkout rather than a normal +PyPI package, so install it separately after creating the PopSyCLE environment. +Follow the SPISEA repository instructions and make sure it is importable in the +same environment before running the PopSyCLE pipeline. + +.. code-block:: bash + + git clone https://github.com/astropy/SPISEA.git + export PYTHONPATH=$PWD/SPISEA:$PYTHONPATH + +Command line entry point +^^^^^^^^^^^^^^^^^^^^^^^^ + +After installation, the pipeline CLI is available as: + +.. code-block:: bash + + popsycle --help + +Galaxia +^^^^^^^ + +Galaxia is still a separate external dependency and must be installed manually. +PopSyCLE checks for the custom ``galaxia`` executable in ``$PATH`` and requires +version ``0.7.2.1`` from the PopSyCLE-compatible Galaxia fork. Follow the +Galaxia instructions in the documentation before running the synthesis +pipeline. Running PopSyCLE ---------------- diff --git a/docs/source/popsycle_docs.rst b/docs/source/popsycle_docs.rst index 17fe5b62..a9491317 100755 --- a/docs/source/popsycle_docs.rst +++ b/docs/source/popsycle_docs.rst @@ -9,6 +9,9 @@ Documentation 1 Installation ============== +For a full-featured installation, use Python 3.11. That is the supported +overlap for the current SPISEA and BAGLE dependency stack. + 1.1 Installing Galaxia ----------------------- @@ -82,17 +85,43 @@ Documentation 1.2 Installing SPISEA ---------------------- - SPISEA can be installed by cloning the repository from ``_ and following the instructions. + SPISEA still needs to be installed separately from source. Use the + repository at ``_ and make sure it is + importable in the same Python environment as PopSyCLE before running the + full pipeline. 1.3 Installing BAGLE ---------------------- - BAGLE can be installed by cloning the repository from ``_ and following the instructions. + BAGLE is installed automatically as part of the packaged PopSyCLE install + methods below. If you need to install it separately, see + ``_. 1.4 Installing Python libraries -------------------------------- - We recommend the Anaconda distribution. See `requirements.txt `_ for details. + We recommend one of the following installation flows from the repository + root. + + Conda: + + .. code-block:: bash + + conda env create -f environment.yml + conda activate popsycle + + Pip: + + .. code-block:: bash + + python3.11 -m venv .venv + source .venv/bin/activate + python -m pip install --upgrade pip + python -m pip install -e . + + SPISEA still needs to be installed separately from its source repository + and made importable in the same environment. After PopSyCLE and SPISEA are + installed, the PopSyCLE CLI is available as ``popsycle``. =============== 2 Reading Files @@ -1325,4 +1354,3 @@ Note: be careful with the branch of arctangent. Practically, use ``numpy.arctan2 :align: center Diagram of Heliocentric and Galactic coordinate systems. The red dot is the sun. - diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000..55b5a94c --- /dev/null +++ b/environment.yml @@ -0,0 +1,26 @@ +name: popsycle +channels: + - conda-forge +dependencies: + - python=3.11 + - pip + - numpy>=1.24.3 + - matplotlib>=3.7.1 + - astropy>=5.3 + - h5py>=3.8.0 + - scipy>=1.10.1 + - pyyaml>=6.0 + - pandas>=1.5.2 + - pysynphot>=2.0.0 + - synphot>=1.7.0 + - stsynphot>=1.5.1 + - scikit-learn + - celerite + - jplephem + - ephem + - pytest>=7.2.0 + - numpydoc>=1.5 + - sphinx_rtd_theme + - pip: + - --editable . +# Install SPISEA separately in this environment after creation. diff --git a/popsycle/run.py b/popsycle/run.py index 1e777bb2..13b9b975 100755 --- a/popsycle/run.py +++ b/popsycle/run.py @@ -12,16 +12,49 @@ import sys import time import glob -from popsycle import synthetic -from popsycle import utils -from popsycle.synthetic import _check_run_galaxia -from popsycle.synthetic import _check_perform_pop_syn -from popsycle.synthetic import _check_calc_events -from popsycle.synthetic import _check_refine_events -from popsycle.synthetic import _check_refine_binary_events -from popsycle.synthetic import multiplicity_list -from popsycle import binary_utils -from popsycle import phot_utils + +synthetic = None +utils = None +binary_utils = None +phot_utils = None +_check_run_galaxia = None +_check_perform_pop_syn = None +_check_calc_events = None +_check_refine_events = None +_check_refine_binary_events = None +multiplicity_list = None + + +def _load_runtime_dependencies(): + global synthetic + global utils + global binary_utils + global phot_utils + global _check_run_galaxia + global _check_perform_pop_syn + global _check_calc_events + global _check_refine_events + global _check_refine_binary_events + global multiplicity_list + + if synthetic is not None: + return + + from popsycle import synthetic as synthetic_mod + from popsycle import utils as utils_mod + from popsycle import binary_utils as binary_utils_mod + from popsycle import phot_utils as phot_utils_mod + + synthetic = synthetic_mod + utils = utils_mod + binary_utils = binary_utils_mod + phot_utils = phot_utils_mod + _check_run_galaxia = synthetic_mod._check_run_galaxia + _check_perform_pop_syn = synthetic_mod._check_perform_pop_syn + _check_calc_events = synthetic_mod._check_calc_events + _check_refine_events = synthetic_mod._check_refine_events + _check_refine_binary_events = synthetic_mod._check_refine_binary_events + multiplicity_list = synthetic_mod.multiplicity_list def _return_filename_dict(output_root, filter_dict, red_law, multiplicity = None): @@ -1356,6 +1389,7 @@ def main(): help="Skip running refine_binary_events.", action='store_true') args = parser.parse_args() + _load_runtime_dependencies() run(output_root=args.output_root, field_config_filename=args.field_config_filename, diff --git a/pyproject.toml b/pyproject.toml index 7e7daea4..9c45c187 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,10 @@ [build-system] -requires = ["setuptools", - "setuptools_scm", +requires = ["setuptools>=64", + "setuptools_scm[toml]>=8", "wheel"] build-backend = 'setuptools.build_meta' + +[tool.setuptools_scm] +write_to = "popsycle/version.py" diff --git a/requirements.txt b/requirements.txt index 520cb0a5..89a3e97b 100755 --- a/requirements.txt +++ b/requirements.txt @@ -11,8 +11,11 @@ pandas~=1.5.2 numpydoc~=1.5 sphinx_rtd_theme pysynphot +synphot +stsynphot scikit-learn # The following are needed for BAGLE celerite jplephem ephem +bagle>=1.0.5 diff --git a/setup.cfg b/setup.cfg index acf0db4b..588de26e 100755 --- a/setup.cfg +++ b/setup.cfg @@ -4,30 +4,65 @@ author = Casey Lam and Jessica Lu author_email = jlu.astro@berkeley.edu license = BSD 3-Clause license_file = licenses/LICENSE.rst -url = https://github.com/jluastro/PopSyCLE +url = https://github.com/MovingUniverseLab/PopSyCLE description = Population Synthesis for Compact-object Lensing Events long_description = file: README.rst long_description_content_type = text/x-rst edit_on_github = False -github_project = jluastro/PopSyCLE +github_project = MovingUniverseLab/PopSyCLE [options] zip_safe = False packages = find: -python_requires = >=3.6 -setup_requires = setuptools_scm +include_package_data = True +python_requires = >=3.11,<3.12 install_requires = - astropy + numpy>=1.24.3 + matplotlib>=3.7.1 + astropy>=5.3 + h5py>=3.8.0 + scipy>=1.10.1 + pyyaml>=6.0 + pandas>=1.5.2 + pysynphot>=2.0.0 + synphot>=1.7.0 + stsynphot>=1.5.1 + scikit-learn + celerite + jplephem + ephem + bagle>=1.0.5 [options.extras_require] test = + pytest>=7.2.0 pytest-astropy docs = + numpydoc>=1.5 + sphinx_rtd_theme sphinx-astropy +dev = + build + wheel + twine + +[options.entry_points] +console_scripts = + popsycle = popsycle.run:main [options.package_data] -popsycle = data/* +popsycle = + data/* + tests/data_correct/* + tests/data_test/* + +[options.packages.find] +namespaces = False +exclude = + popsycle.data + popsycle.tests.data_correct + popsycle.tests.data_test [tool:pytest] testpaths = "popsycle" "docs" diff --git a/setup.py b/setup.py index 14bc133f..f5148fc6 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ # NOTE: The configuration for the package, including the name, version, and # other information are set in the setup.cfg file. -import os import sys from setuptools import setup @@ -65,18 +64,5 @@ print(DOCS_HELP) sys.exit(1) -VERSION_TEMPLATE = """ -# Note that we need to fall back to the hard-coded version if either -# setuptools_scm can't be imported or setuptools_scm can't determine the -# version, so we catch the generic 'Exception'. -try: - from setuptools_scm import get_version - version = get_version(root='..', relative_to=__file__) -except Exception: - version = '{version}' -""".lstrip() - -setup(use_scm_version={'write_to': os.path.join('popsycle', 'version.py'), - 'write_to_template': VERSION_TEMPLATE}, - ext_modules=None) +setup(use_scm_version=True, ext_modules=None) # ext_modules=get_extensions())