diff --git a/.github/workflows/test_pytest.yaml b/.github/workflows/test_pytest.yaml index ebd84b465..c5e665444 100644 --- a/.github/workflows/test_pytest.yaml +++ b/.github/workflows/test_pytest.yaml @@ -15,20 +15,20 @@ jobs: - 3.7 - 3.11 steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements_test.txt - - name: Build RocketPy - run: | - pip install -e . - - name: Test with pytest - run: | - pytest - cd rocketpy - pytest --doctest-modules \ No newline at end of file + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-tests.txt + - name: Build RocketPy + run: | + pip install -e.[all] + - name: Test with pytest + run: | + pytest + cd rocketpy + pytest --doctest-modules diff --git a/.travis.yml b/.travis.yml index 24cea5178..b2ec516aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,13 @@ language: python python: -- '3.8' + - "3.8" install: -- make install -- pip install -r requirements_test.txt + - make install + - pip install -r requirements-tests.txt before_script: -- make verify-lint + - make verify-lint script: -- make test + - make test deploy: provider: pypi username: __token__ diff --git a/docs/user/requirements.rst b/docs/user/requirements.rst index a6a5c07ef..c79f1dfb0 100644 --- a/docs/user/requirements.rst +++ b/docs/user/requirements.rst @@ -21,12 +21,9 @@ The following packages are needed in order to run RocketPy: - Scipy >= 1.0 - Matplotlib >= 3.0 - netCDF4 >= 1.4, < 1.6 for Python 3.7+, netCDF4 >= 1.6.2 for Python 3.11 -- windrose >= 1.6.8 - requests - pytz - simplekml -- ipywidgets >= 7.6.3 -- jsonpickle All of these packages, are automatically installed when RocketPy is installed using either ``pip`` or ``conda``. However, in case the user wants to install these packages manually, they can do so by following the instructions bellow. @@ -44,12 +41,9 @@ The packages needed can be installed via ``pip`` by running the following lines pip install "scipy>=1.0" pip install "matplotlib>=3.0" pip install "netCDF4>=1.6.2" - pip install "windrose >= 1.6.8" - pip install "ipywidgets>=7.6.3" pip install requests pip install pytz pip install simplekml - pip install jsonpickle Installing Required Packages Using ``conda`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,15 +61,27 @@ To update Scipy and install netCDF4 using Conda, the following code is used: Optional Packages ----------------- -Optionally, you can install timezonefinder to allow for automatic timezone detection when performing Enviornment Analysis. -This can be done by running the following line of code in your preferred terminal: +The EnvironmentAnalysis class requires a few extra packages to be installed. +In case you want to use this class, you will need to install the following packages: + +- `timezonefinder` : to allow for automatic timezone detection, +- `windrose` : to allow for windrose plots, +- `ipywidgets` : to allow for GIFs generation, +- `jsonpickle` : to allow for saving and loading of class instances. + +You can install all these packages by simply running the following lines in your preferred terminal: .. code-block:: shell - pip install timezonefinder + pip install rocketpy[env_analysis] + + +Alternatively, you can instal all extra packages by running the following line in your preferred terminal: + +.. code-block:: shell -Keep in mind that this package is not required to run RocketPy, but it can be useful if you want to perform Environment Analysis. -Furthermore, timezonefinder can only be used with Python 3.8+. + pip install rocketpy[all] + Useful Packages --------------- diff --git a/requirements_test.txt b/requirements-tests.txt similarity index 100% rename from requirements_test.txt rename to requirements-tests.txt diff --git a/rocketpy/EnvironmentAnalysis.py b/rocketpy/EnvironmentAnalysis.py index dc27c5dd9..b82ebd34e 100644 --- a/rocketpy/EnvironmentAnalysis.py +++ b/rocketpy/EnvironmentAnalysis.py @@ -10,7 +10,7 @@ import warnings from collections import defaultdict -import jsonpickle +import matplotlib.ticker as mtick import netCDF4 import numpy as np import pytz @@ -20,6 +20,17 @@ from rocketpy.Function import Function from rocketpy.units import convert_units +try: + import ipywidgets as widgets + import jsonpickle + from timezonefinder import TimezoneFinder + from windrose import WindroseAxes +except ImportError as error: + raise ImportError( + f"The following error was encountered while importing dependencies: '{error}'. " + "Please note that the EnvironmentAnalysis requires additional dependencies, " + "which can be installed by running 'pip install rocketpy[env_analysis]'." + ) from .plots.environment_analysis_plots import _EnvironmentAnalysisPlots from .prints.environment_analysis_prints import _EnvironmentAnalysisPrints @@ -420,16 +431,6 @@ def __localize_input_dates(self): def __find_preferred_timezone(self): if self.preferred_timezone is None: - try: - from timezonefinder import TimezoneFinder - except ImportError: - raise ImportError( - "The timezonefinder package is required to automatically " - + "determine local timezone based on lat,lon coordinates. " - + "Please specify the desired timezone using the `timezone` " - + "argument when initializing the EnvironmentAnalysis class " - + "or install timezonefinder with `pip install timezonefinder`." - ) # Use local timezone based on lat lon pair tf = TimezoneFinder() self.preferred_timezone = pytz.timezone( diff --git a/setup.py b/setup.py index 591ae3447..187e71c38 100644 --- a/setup.py +++ b/setup.py @@ -23,23 +23,30 @@ # https://github.com/Unidata/netcdf4-python/issues/1179 netCDF4_requirement = "netCDF4>=1.6.2" +necessary_require = [ + "numpy>=1.0", + "scipy>=1.0", + "matplotlib>=3.0", + netCDF4_requirement, + "requests", + "pytz", + "simplekml", +] + +env_analysis_require = [ + "timezonefinder", + "windrose>=1.6.8", + "ipywidgets>=7.6.3", + "jsonpickle", +] + setuptools.setup( name="rocketpy", version="0.13.1", - install_requires=[ - "numpy>=1.0", - "scipy>=1.0", - "matplotlib>=3.0", - netCDF4_requirement, - "windrose>=1.6.8", - "ipywidgets>=7.6.3", - "requests", - "pytz", - "simplekml", - "jsonpickle", - ], + install_requires=necessary_require, extras_require={ - "timezonefinder": ["timezonefinder"], + "env_analysis": env_analysis_require, + "all": necessary_require + env_analysis_require, }, maintainer="RocketPy Developers", author="Giovani Hidalgo Ceotto",