Skip to content

Commit

Permalink
refactor: refactor dependencies for standard installation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhughes-usgs committed May 8, 2023
1 parent f623e5c commit c82b98a
Show file tree
Hide file tree
Showing 22 changed files with 959 additions and 182 deletions.
49 changes: 0 additions & 49 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
[metadata]
name = pywatershed
version = attr: pywatershed.version.__version__
description = pywatershed is a hydrologic model
long_description = pywatershed is a Python package for hydrologic modeling
long_description_content_type = text/markdown
author = USGS Enterprise Capacity Team
author_email = modflow@usgs.gov
maintainer = James McCreight
maintainer_email = jmccreight@usgs.gov
license = CC0
license_files = LICENSE, LICENSE.md
platform = Mac OS-X, Linux
keywords = PRMS, hydrology
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Science/Research
License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Programming Language :: Python
Programming Language :: Python :: 3 :: Only
Topic :: Scientific/Engineering :: Hydrology
url = https://github.com/EC-USGS/prmsNHMpy
download_url = https://pypi.org/project/pywatershed
project_urls =
Bug Tracker = https://github.com/EC-USGS/pywatershed/issues
Source Code = https://github.com/EC-USGS/pywatershed

[options]
include_package_data = True # includes files listed in MANIFEST.in
zip_safe = False
packages = find:
python_requires = >=3.7
install_requires =
epiweeks
netCDF4
networkx
numpy
numba
pandas
pyyaml
xarray

[options.package_data]
pywatershed =
static/metadata/*.yaml

[sdist]
formats = zip

[flake8]
exclude =
.git
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# python
build/
dist/
*.egg-info/
*.pkl

Expand Down Expand Up @@ -58,7 +59,7 @@ autotest/temp
generated/

# gis data
examples/pynhm_gis
examples/pywatershed_gis
examples/pywatershed_gis
examples/model_loop_custom_output

Expand Down
20 changes: 20 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cff-version: 1.2.0
message: If you use this software, please cite the software itself.
type: software
title: pywatershed
version: 3.3.7
date-released: '2023-04-28'
abstract: pywatershed is a Python package for hydrologic modeling.
repository-artifact: https://pypi.org/project/pywatershed
repository-code: https://github.com/modflowpy/flopy
license: CC0-1.0
authors:
- family-names: McCreight
given-names: James
orcid: https://orcid.org/0000-0001-6018-425X
- family-names: Langevin
given-names: Christian D.
orcid: https://orcid.org/0000-0001-5610-9759
- family-names: Hughes
given-names: Joseph D.
orcid: https://orcid.org/0000-0003-1311-2354
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
prune .idea
prune .git
prune .github
prune autotest
prune autotest_exs
prune bin
prune ci
prune doc
prune evaluation
prune examples
prune prms_src
prune reference
prune resources
prune test_data
include pyproject.toml
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[![codecov-badge](https://codecov.io/gh/ec-usgs/pywatershed/branch/main/graph/badge.svg)](https://codecov.io/gh/ec-usgs/pywatershed)
[![Documentation Status](https://readthedocs.org/projects/pywatershed/badge/?version=latest)](https://pywatershed.readthedocs.io/en/latest/?badge=latest)

[![PyPI Version](https://img.shields.io/pypi/v/pywatershed.png)](https://pypi.python.org/pypi/pywatershed)
[![PyPI Status](https://img.shields.io/pypi/status/pywatershed.png)](https://pypi.python.org/pypi/pywatershed)
[![PyPI Versions](https://img.shields.io/pypi/pyversions/pywatershed.png)](https://pypi.python.org/pypi/pywatershed)

[//]: # (<img src="https://raw.githubusercontent.com/ec-usgs/pywatershed/main/resources/images/prms_flow.png" alt="prms_flow" style="width:50;height:20">)

Purpose
Expand Down
99 changes: 92 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,101 @@
[build-system]
# Minimum requirements for the build system to execute
requires = [
"setuptools >=61",
"numpy",
"setuptools>=45",
"setuptools_scm[toml]>=6.2",
"wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "pywatershed"
description = "pywatershed is a Python package for hydrologic modeling"
authors = [
{name = "USGS Enterprise Capacity Team", email = "modflow@usgs.gov"},
]
maintainers = [
{ name = "James L. McCreight", email = "jmccreight@usgs.gov" },
{ name = "Joseph D. Hughes", email = "jdhughes@usgs.gov" },
]
keywords = ["hydrology", "PRMS"]
license = { text = "CC0" }
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering :: Hydrology",
]
requires-python = ">=3.8,<3.11"
dependencies = [
"numpy >=1.15.0",
"matplotlib >=1.4.0",
"epiweeks",
"netCDF4",
"networkx",
"numpy",
"numba",
"pandas",
"pint",
"xarray@git+https://github.com/pydata/xarray.git",
"xmltodict",
"pyyaml",
]
dynamic = ["version", "readme"]

[project.optional-dependencies]
lint = [
"cffconvert",
"black",
"click",
"isort",
"flake8",
"pylint",
"flynt",
]
test = [
"pywatershed[lint]",
"coverage",
"flaky",
"modflow-devtools",
"pytest",
"pytest-cov",
"pytest-env",
"pytest-order",
"pytest-xdist",
]
optional = [
"pydot",
"geos",
"cartopy",
"geopandas",
"hvplot",
"shapely <2.0.0",
"ipython",
"jupyter",
"jupyterlab",
]

[project.urls]
Documentation = "https://pywatershed.readthedocs.io"
"Bug Tracker" = "https://github.com/EC-USGS/pywatershed/issues"
"Source Code" = "https://github.com/EC-USGS/pywatershed"

[tool.setuptools]
include-package-data = true
zip-safe = false

[tool.setuptools.dynamic]
version = { attr = "pywatershed.version.__version__" }
readme = { file = ["README.md"], content-type = "text/markdown" }

[tool.setuptools.packages.find]
include = ["pywatershed", "pywatershed.*"]

[tool.setuptools.package-data]
"pywatershed.static.metadata" = ["*.yaml"]

[tool.black]
line-length = 79
target_version = ["py39"]
Expand All @@ -20,6 +108,3 @@ verbose = true
profile = "black"
src_paths = ["pywatershed", "autotest", "test_data"]
line_length = 79

[tool.setuptools_scm]
fallback_version = "999"
2 changes: 1 addition & 1 deletion pywatershed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Soltab,
)
from .utils.csv_utils import CsvFile
from .version import __author__, __author_email__, __version__
from .version import __version__

__all__ = [
"analysis",
Expand Down
34 changes: 9 additions & 25 deletions pywatershed/analysis/model_graph.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import pathlib as pl
import tempfile
import warnings

from ..base.model import Model

try:
import pydot

has_pydot = True
except ModuleNotFoundError:
has_pydot = False

try:
from IPython.display import SVG, display

has_ipython = True
except ModuleNotFoundError:
has_ipython = False
from ..utils import import_optional_dependency


class ModelGraph:
Expand All @@ -31,9 +17,7 @@ def __init__(
node_spacing: float = 2.75,
hide_variables: bool = True,
):
if not has_pydot:
warnings.warn("pydot not available")

self.pydot = import_optional_dependency("pydot")
self.model = model
self.show_params = show_params
self.process_colors = process_colors
Expand Down Expand Up @@ -98,7 +82,7 @@ def build_graph(self):
self.file_node = self._file_node(files)

# build the graph
self.graph = pydot.Dot(
self.graph = self.pydot.Dot(
graph_type="digraph",
layout="neato",
splines="polyline",
Expand All @@ -110,23 +94,23 @@ def build_graph(self):
self.graph.add_node(self.process_nodes[process])

for con in connections:
self.graph.add_edge(pydot.Edge(con[0], con[1], color=con[2]))
self.graph.add_edge(self.pydot.Edge(con[0], con[1], color=con[2]))

return

def SVG(self, verbose: bool = False):
"""Display an SVG in jupyter notebook (via tempfile)."""

if not has_ipython:
warnings.warn("IPython is not available")
ipdisplay = import_optional_dependency("IPython.display")

tmp_file = pl.Path(tempfile.NamedTemporaryFile().name)
if self.graph is None:
self.build_graph()
self.graph.write_svg(tmp_file)
if verbose:
print(f"Displaying SVG written to temp file: {tmp_file}")

display(SVG(tmp_file))
ipdisplay.display(ipdisplay.SVG(tmp_file))
return

def _process_node(self, process, show_params: bool = False):
Expand Down Expand Up @@ -193,7 +177,7 @@ def _process_node(self, process, show_params: bool = False):
if self.process_colors:
color_str = f'"{self.process_colors[cls]}"'

node = pydot.Node(
node = self.pydot.Node(
cls,
label=label,
pos=f'"{self._current_pos},0!"',
Expand All @@ -220,7 +204,7 @@ def _file_node(self, files):

label += f"</TABLE>>\n"
label = label
node = pydot.Node(
node = self.pydot.Node(
"Files",
label=label,
pos=f'"{self._current_pos},0!"',
Expand Down
Loading

0 comments on commit c82b98a

Please sign in to comment.