Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: convert windrose ipywidgets and jsonpickle to optional dependencies #368

Merged
merged 10 commits into from
Jun 14, 2023
Merged
34 changes: 17 additions & 17 deletions .github/workflows/test_pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
28 changes: 17 additions & 11 deletions docs/user/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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
---------------
Expand Down
File renamed without changes.
23 changes: 12 additions & 11 deletions rocketpy/EnvironmentAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down
33 changes: 20 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved
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",
Expand Down