diff --git a/.github/workflows/build-sphinx-no-deploy.yml b/.github/workflows/build-sphinx-no-deploy.yml index 75844cd2..3facec96 100644 --- a/.github/workflows/build-sphinx-no-deploy.yml +++ b/.github/workflows/build-sphinx-no-deploy.yml @@ -16,7 +16,7 @@ jobs: - uses: mamba-org/setup-micromamba@v1 with: generate-run-shell: true - environment-file: requirements.yml + environment-file: environment.yml create-args: >- python=3.10 pillow diff --git a/.github/workflows/build-sphinx.yml b/.github/workflows/build-sphinx.yml index 477337f8..eabf99e5 100644 --- a/.github/workflows/build-sphinx.yml +++ b/.github/workflows/build-sphinx.yml @@ -16,7 +16,7 @@ jobs: - uses: mamba-org/setup-micromamba@v1 with: generate-run-shell: true - environment-file: requirements.yml + environment-file: environment.yml create-args: >- python=3.9 pillow diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 9bb56913..e3a28df3 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -27,7 +27,7 @@ jobs: - uses: mamba-org/setup-micromamba@v1 with: generate-run-shell: true - environment-file: requirements.yml + environment-file: environment.yml create-args: >- python=${{ matrix.python-version }} diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index ffd51a9c..ffc9c8fc 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -19,7 +19,7 @@ jobs: - uses: mamba-org/setup-micromamba@v1 with: generate-run-shell: true - environment-file: requirements.yml + environment-file: environment.yml create-args: >- python=3.10 @@ -28,13 +28,13 @@ jobs: conda info -a conda list - - name: Create sdist + - name: Create sdist and wheel run: | - python setup.py check - python setup.py sdist + python -m pip install --upgrade pip build + python -m build - name: Publish Package - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.pypi_upload_token }} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/MANIFEST.in b/MANIFEST.in index e976934b..aaeb24dd 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,7 @@ include README.md include CONTRIBUTING.md include CODE_OF_CONDUCT.md include Dockerfile -include LICENSE.txt +include LICENSE include CHANGELOG.md include CREDITS.md include codemeta.json @@ -23,8 +23,5 @@ global-exclude .git* global-exclude *.pyc global-exclude *.html global-exclude *.so -global-exclude *.xls -global-exclude *.xlsm -global-exclude *.xlsx global-exclude *~ global-exclude .DS_Store diff --git a/README.md b/README.md index 929bd174..2dc5a981 100644 --- a/README.md +++ b/README.md @@ -89,4 +89,4 @@ Development of pyCSEP is a group effort. A list of developers that have contribu are listed in the [credits](CREDITS.md) file in this repository. # License: -The pyCSEP software is distributed under the BSD 3-Clause open-source license. Please see the [license](LICENSE.txt) file for more information. +The pyCSEP software is distributed under the BSD 3-Clause open-source license. Please see the [license](LICENSE) file for more information. diff --git a/csep/__init__.py b/csep/__init__.py index aff53316..31a18015 100644 --- a/csep/__init__.py +++ b/csep/__init__.py @@ -2,18 +2,22 @@ import os import time -from csep._version import __version__ -from csep.core import catalog_evaluations -from csep.core import catalogs from csep.core import forecasts +from csep.core import catalogs from csep.core import poisson_evaluations +from csep.core import catalog_evaluations from csep.core import regions -from csep.core.exceptions import CSEPCatalogException -from csep.core.forecasts import GriddedForecast, CatalogForecast from csep.core.repositories import ( load_json, write_json ) + +from csep.core.exceptions import CSEPCatalogException + +from csep.utils import datasets +from csep.utils import readers + +from csep.core.forecasts import GriddedForecast, CatalogForecast from csep.models import ( EvaluationResult, CatalogNumberTestResult, @@ -22,8 +26,7 @@ CatalogPseudolikelihoodTestResult, CalibrationTestResult ) -from csep.utils import datasets -from csep.utils import readers + from csep.utils.time_utils import ( utc_now_datetime, strptime_to_utc_datetime, @@ -32,6 +35,13 @@ utc_now_epoch ) +from importlib.metadata import version as _pkg_version, PackageNotFoundError + +try: + __version__ = _pkg_version("pycsep") +except PackageNotFoundError: + __version__ = "0+unknown" + # this defines what is imported on a `from csep import *` __all__ = [ 'load_json', @@ -75,8 +85,8 @@ def load_stochastic_event_sets(filename, type='csv', format='native', (generator): :class:`~csep.core.catalogs.AbstractBaseCatalog` """ - if type not in ('ucerf3', 'csv'): - raise ValueError("type must be one of the following: (ucerf3)") + if type not in ('ucerf3', 'csv', 'csep'): + raise ValueError("type must be one of the following: (ucerf3, csv, csep)") # use mapping to dispatch to correct function # in general, stochastic event sets are loaded with classmethods and single catalogs use the @@ -100,7 +110,7 @@ def load_stochastic_event_sets(filename, type='csv', format='native', elif format == 'csep': yield catalog.get_csep_format() else: - raise ValueError('format must be either "native" or "csep!') + raise ValueError('format must be either "native" or "csep!"') def load_catalog(filename, type='csep-csv', format='native', loader=None, diff --git a/csep/_version.py b/csep/_version.py deleted file mode 100644 index 12c96448..00000000 --- a/csep/_version.py +++ /dev/null @@ -1,2 +0,0 @@ -__version__ = "0.7.0" - diff --git a/docs/getting_started/installing.rst b/docs/getting_started/installing.rst index d9c0fd07..fd36f14d 100644 --- a/docs/getting_started/installing.rst +++ b/docs/getting_started/installing.rst @@ -60,7 +60,7 @@ If you don't have ``conda`` on your machine, download and install `Miniconda /pycsep.git cd pycsep - conda env create -f requirements.yml + conda env create -f environment.yml conda activate csep-dev - pip install -e .[all] + pip install -e .[dev] # Allow sync with default repository git remote add upstream https://github.com/SCECCode/pycsep.git diff --git a/requirements.yml b/environment.yml similarity index 92% rename from requirements.yml rename to environment.yml index 82d6d180..38c9f71f 100644 --- a/requirements.yml +++ b/environment.yml @@ -3,7 +3,7 @@ channels: - conda-forge - defaults dependencies: - - python>=3.7 + - pip - numpy - pandas - scipy diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..2cafe7d3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,71 @@ +[build-system] +requires = ["setuptools>=69", "wheel", "build", "setuptools-scm>=8"] +build-backend = "setuptools.build_meta" + +[project] +name = "pycsep" +dynamic = ["version"] # <— version comes from SCM +description = "Python tools from the Collaboratory for the Study of Earthquake Predictability" +readme = "README.md" +requires-python = ">=3.9" +license = { file = "LICENSE" } +authors = [{ name = "William Savran", email = "wsavran@unr.edu" }] +urls = { "Homepage" = "https://github.com/SCECCode/pycsep" } + +dependencies = [ + "numpy", + "scipy", + "pandas", + "matplotlib", + "cartopy", + "obspy", + "pyproj", + "python-dateutil", + "rasterio", + "mercantile", + "shapely", +] + +[project.optional-dependencies] +dev = ["pytest", "vcrpy", "pytest-cov", "sphinx", "sphinx-gallery", "sphinx-rtd-theme", "pillow", "tox"] + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +where = ["."] +include = ["csep*"] + +[tool.setuptools_scm] +version_scheme = "post-release" + +[tool.tox] +min_version = "4.0" +env_list = ["py39", "py310", "py311", "py312"] +skip_missing_interpreters = true + +[tool.tox.requires] +requires = ["tox-conda>=0.10"] + +[tool.tox.env.py] +package = "wheel" +wheel_build_env = ".pkg" +extras = ["dev"] +conda_channels = ["conda-forge"] +conda_deps = [ + "python", + "numpy", + "pandas", + "scipy", + "matplotlib", + "pyproj", + "obspy", + "python-dateutil", + "cartopy", + "shapely", + "rasterio", + "mercantile" +] +set_env = { MPLBACKEND = "Agg" } +pass_env = ["PYTEST_ADDOPTS"] +commands = ["pytest --basetemp={envtmpdir}"] \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index d75022ee..00000000 --- a/setup.py +++ /dev/null @@ -1,68 +0,0 @@ -import re -from setuptools import setup, find_packages - -def get_version(): - VERSIONFILE = "csep/_version.py" - verstrline = open(VERSIONFILE, "rt").read() - VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]" - mo = re.search(VSRE, verstrline, re.M) - if mo: - verstr = mo.group(1) - else: - raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,)) - return verstr - - -with open("README.md",'r') as fh: - long_description = fh.read() - -setup( - name='pycsep', - version=get_version(), - author='William Savran', - author_email='wsavran@usc.edu', - packages=find_packages(), - license='LICENSE', - description='Python tools from the Collaboratory for the Study of Earthquake Predictability', - long_description=long_description, - long_description_content_type='text/markdown', - install_requires=[ - 'numpy', - 'scipy', - 'pandas', - 'matplotlib', - 'cartopy', - 'obspy', - 'pyproj', - 'python-dateutil', - 'rasterio', - 'mercantile', - 'shapely' - ], - extras_require = { - 'test': [ - 'pytest', - 'vcrpy', - 'pytest-cov' - ], - 'dev': [ - 'sphinx', - 'sphinx-gallery', - 'sphinx-rtd-theme', - 'pillow' - ], - 'all': [ - 'pytest', - 'vcrpy', - 'pytest-cov', - 'sphinx', - 'sphinx-gallery', - 'sphinx-rtd-theme', - 'pillow' - ] - }, - include_package_data=True, - python_requires=">=3.7", - zip_safe=False, - url='https://github.com/SCECCode/pycsep' -)