diff --git a/.readthedocs.yaml b/.readthedocs.yaml index d8de548..98aa7ee 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -15,7 +15,10 @@ build: sphinx: configuration: docs/conf.py -# Optionally set the version of Python and requirements required to build your docs +# Install Python dependencies using pyproject.toml python: install: - - requirements: requirements/docs.txt + - method: pip + path: . + extra_requirements: + - docs diff --git a/Makefile b/Makefile index 94392b5..d9d3988 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,11 @@ clean-docs: install: python -m pip install --upgrade pip - pip install -r requirements/core.txt -r requirements/dev.txt -r requirements/docs.txt + pip install . + pip install .[dev,docs] install-examples: install - pip install -r requirements/examples.txt + pip install .[examples] examples: install-examples jupyter-lab diff --git a/docs/user/notebook.html b/docs/user/notebook.html index 84bf614..aa553ff 100644 --- a/docs/user/notebook.html +++ b/docs/user/notebook.html @@ -7495,12 +7495,12 @@

Harmony Py TutorialInĀ [1]:
@@ -7745,7 +7745,7 @@

Harmony Py Tutorial

@@ -7758,7 +7758,7 @@

Harmony Py Tutorial @@ -7771,7 +7771,7 @@

Harmony Py Tutorial @@ -7784,7 +7784,7 @@

Harmony Py Tutorial @@ -7797,7 +7797,7 @@

Harmony Py Tutorial @@ -7810,7 +7810,7 @@

Harmony Py Tutorial @@ -7823,7 +7823,7 @@

Harmony Py Tutorial @@ -7836,7 +7836,7 @@

Harmony Py Tutorial @@ -8009,7 +8009,7 @@

Harmony Py Tutorial @@ -8192,7 +8192,7 @@

Harmony Py Tutorial @@ -8232,7 +8232,7 @@

Harmony Py Tutorial diff --git a/examples/helper.py b/examples/helper.py index a2879b0..43ed4d5 100644 --- a/examples/helper.py +++ b/examples/helper.py @@ -1,17 +1,33 @@ import sys -sys.path.append('..') - -import datetime as dt -from getpass import getpass -from glob import glob -from time import sleep - -import ipyplot -from ipywidgets import IntSlider, Password, Text -from IPython.display import display, JSON +import os import rasterio from rasterio.plot import show -import requests + +def install_project_and_dependencies(project_root, libs=None): + """ + Change to the project root, install the project and its optional dependencies, + then switch back to the original directory. + + :param project_root: Path to the project root directory where pyproject.toml or setup.py is located. + :param libs: List of optional pip extra dependencies (e.g., ['examples', 'dev']). + """ + # Save the current working directory + original_dir = os.getcwd() + + try: + # Change directory to the project root + os.chdir(project_root) + + # If libs are specified, install them + if libs: + libs_str = ','.join(libs) + os.system(f'{sys.executable} -m pip install -q .[{libs_str}]') + + # Install the project itself + os.system(f'{sys.executable} -m pip install -q .') + finally: + # Switch back to the original directory after installation + os.chdir(original_dir) def show_result(filename): diff --git a/examples/tutorial.ipynb b/examples/tutorial.ipynb index 0019382..d7b3ff8 100644 --- a/examples/tutorial.ipynb +++ b/examples/tutorial.ipynb @@ -21,12 +21,12 @@ }, "outputs": [], "source": [ - "import sys; sys.path.append('..')\n", - "!{sys.executable} -m pip install -q -r ../requirements/examples.txt\n", + "import helper\n", "\n", - "# Install harmony-py requirements. Not necessary if you ran `pip install harmony-py` in your kernel\n", - "!{sys.executable} -m pip install -q -r ../requirements/core.txt\n", + "# Install the project and 'examples' dependencies\n", + "helper.install_project_and_dependencies('..', libs=['examples'])\n", "\n", + "import sys\n", "import datetime as dt\n", "from IPython.display import display, JSON\n", "import rasterio\n", @@ -34,7 +34,7 @@ "import netCDF4 as nc4\n", "from matplotlib import pyplot as plt\n", "import numpy as np\n", - "import helper\n", + "\n", "\n", "from harmony import BBox, WKT, Client, Collection, Request, Environment" ] diff --git a/pyproject.toml b/pyproject.toml index 35bed21..a0222aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,20 +26,57 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3 :: Only", ] -dynamic = ["dependencies", "optional-dependencies", "version"] +dynamic = ["version"] +dependencies = [ + "python-dateutil ~= 2.8.2", + "python-dotenv ~= 0.20.0", + "progressbar2 ~= 4.2.0", + "requests ~= 2.32.3", + "sphinxcontrib-napoleon ~= 0.7", + "curlify ~= 2.2.1", + "shapely ~= 2.0.4" +] [project.urls] Homepage = "https://github.com/nasa/harmony-py" Documentation = "https://harmony-py.readthedocs.io/en/main/" Repository = "https://github.com/nasa/harmony-py.git" -[project.dependencies] -dependencies = ["-r requirements/core.txt"] - [project.optional-dependencies] -dev = ["-r requirements/dev.txt"] -docs = ["-r requirements/docs.txt"] -examples = ["-r requirements/examples.txt"] +dev = [ + "coverage ~= 5.4", + "flake8 ~= 7.1.1", + "hypothesis ~= 6.2", + "PyYAML ~= 6.0.1", + "pytest ~= 6.2", + "pytest-cov ~= 2.11", + "pytest-mock ~= 3.5", + "pytest-watch ~= 4.2", + "responses ~= 0.25.3" +] +docs = [ + "curlify ~= 2.2.1", + "Jinja2 ~= 3.1.2", + "load-dotenv ~=0.1.0", + "nbconvert ~= 7.10.0", + "progressbar2 ~= 4.2.0", + "sphinx ~= 7.1.2", + "sphinx-rtd-theme ~= 1.3.0", + "shapely ~= 2.0.4" +] +examples = [ + "boto3 ~= 1.28", + "intake-stac ~= 0.4.0", + "ipyplot ~= 1.1", + "ipywidgets ~= 8.1", + "jupyterlab ~= 4.0", + "matplotlib ~= 3.8", + "netCDF4 ~= 1.6", + "numpy ~= 1.26", + "pillow ~= 10.1", # A dependency of ipyplot, pinned to avoid critical vulnerability. + "pystac ~= 1.9.0", + "rasterio ~= 1.3" +] [tool.setuptools.dynamic] # Will read __version__ from harmony.__init__.py @@ -48,12 +85,6 @@ version = {attr = "harmony.__version__"} [tool.setuptools.packages.find] exclude = ["contrib", "docs", "tests*"] -[tool.setuptools] -include_package_data = true - -[tool.setuptools.test] -test_suite = "tests" - [tool.flake8] max-line-length = 99 ignore = ["F401", "W503"] diff --git a/requirements/core.txt b/requirements/core.txt deleted file mode 100644 index f72f88d..0000000 --- a/requirements/core.txt +++ /dev/null @@ -1,7 +0,0 @@ -python-dateutil ~= 2.8.2 -python-dotenv ~= 0.20.0 -progressbar2 ~= 4.2.0 -requests ~= 2.32.3 -sphinxcontrib-napoleon ~= 0.7 -curlify ~= 2.2.1 -shapely ~= 2.0.4 diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index 0ea26e1..0000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,9 +0,0 @@ -coverage ~= 5.4 -flake8 ~= 7.1.1 -hypothesis ~= 6.2 -PyYAML ~= 6.0.1 -pytest ~= 6.2 -pytest-cov ~= 2.11 -pytest-mock ~= 3.5 -pytest-watch ~= 4.2 -responses ~= 0.25.3 diff --git a/requirements/docs.txt b/requirements/docs.txt deleted file mode 100644 index eed7885..0000000 --- a/requirements/docs.txt +++ /dev/null @@ -1,8 +0,0 @@ -curlify ~= 2.2.1 -Jinja2 ~= 3.1.2 -load-dotenv ~=0.1.0 -nbconvert ~= 7.10.0 -progressbar2 ~= 4.2.0 -sphinx ~= 7.1.2 -sphinx-rtd-theme ~= 1.3.0 -shapely ~= 2.0.4 diff --git a/requirements/examples.txt b/requirements/examples.txt deleted file mode 100644 index 73907fb..0000000 --- a/requirements/examples.txt +++ /dev/null @@ -1,11 +0,0 @@ -boto3 ~= 1.28 -intake-stac ~= 0.4.0 -ipyplot ~= 1.1 -ipywidgets ~= 8.1 -jupyterlab ~= 4.0 -matplotlib ~= 3.8 -netCDF4 ~= 1.6 -numpy ~= 1.26 -pillow ~= 10.1 # A dependency of ipyplot, pinned to avoid critical vulnerability. -pystac ~= 1.9.0 -rasterio ~= 1.3