Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from cp4cds/update-template-20190911
Browse files Browse the repository at this point in the history
updated from template
  • Loading branch information
cehbrecht committed Sep 12, 2019
2 parents d5b08e9 + fb06e70 commit f8f3597
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Docker
#Dockerfile

# PyWPS
# PyWPS
custom.cfg
.custom.cfg
*.pid
Expand Down
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
dist: xenial # required for Python >= 3.7
language: python
python:
- "2.7"
- "3.6"
- "3.7"
branches:
only:
- master
os:
- linux
# - osx
Expand All @@ -23,7 +27,7 @@ install:
- source activate c4cds
# Packages for testing
- conda install pytest flake8
# Install Emu WPS
# Install WPS
- python setup.py install
before_script:
# Start WPS service on port 5000 on 0.0.0.0
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN ["/bin/bash", "-c", "source activate wps && python setup.py develop"]
# Start WPS service on port 5000 on 0.0.0.0
EXPOSE 5000
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["source activate wps && exec emu start -b 0.0.0.0 -config /opt/wps/etc/demo.cfg"]
CMD ["source activate wps && exec c4cds start -b 0.0.0.0 -c /opt/wps/etc/demo.cfg"]

# docker build -t cp4cds/c4cds-wps .
# docker run -p 5000:5000 cp4cds/c4cds-wps
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Apache Software License 2.0

Copyright (c) 2018, Carsten Ehbrecht
Copyright (c) 2019, Carsten Ehbrecht

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
174 changes: 88 additions & 86 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,127 +1,129 @@
# Application
APP_ROOT := $(CURDIR)
# Configuration
APP_ROOT := $(abspath $(lastword $(MAKEFILE_LIST))/..)
APP_NAME := c4cds

# Anaconda
CONDA := $(shell command -v conda 2> /dev/null)
ANACONDA_HOME := $(shell conda info --base 2> /dev/null)
CONDA_ENV := $(APP_NAME)

TEMP_FILES := *.egg-info *.log *.sqlite

# end of configuration

.DEFAULT_GOAL := all
.DEFAULT_GOAL := help

.PHONY: all
all: help

.PHONY: help
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " help to print this help message. (Default)"
@echo " install to install $(APP_NAME) by running 'python setup.py develop'."
@echo " start to start $(APP_NAME) service as daemon (background process)."
@echo " stop to stop $(APP_NAME) service."
@echo " status to show status of $(APP_NAME) service."
@echo " clean to remove *all* files that are not controlled by 'git'. WARNING: use it *only* if you know what you do!"
@echo "Please use 'make <target>' where <target> is one of:"
@echo " help to print this help message. (Default)"
@echo " install to install app by running 'pip install -e .'"
@echo " develop to install with additional development requirements."
@echo " start to start $(APP_NAME) service as daemon (background process)."
@echo " stop to stop $(APP_NAME) service."
@echo " restart to restart $(APP_NAME) service."
@echo " status to show status of $(APP_NAME) service."
@echo " clean to remove all files generated by build and tests."
@echo "\nTesting targets:"
@echo " test to run tests (but skip long running tests)."
@echo " testall to run all tests (including long running tests)."
@echo " pep8 to run pep8 code style checks."
@echo " test to run tests (but skip long running tests)."
@echo " test-all to run all tests (including long running tests)."
@echo " lint to run code style checks with flake8."
@echo "\nSphinx targets:"
@echo " docs to generate HTML documentation with Sphinx."

## Anaconda targets

.PHONY: check_conda
check_conda:
ifndef CONDA
$(error "Conda is not available. Please install miniconda: https://conda.io/miniconda.html")
endif

.PHONY: conda_env
conda_env: check_conda
@echo "Updating conda environment $(CONDA_ENV) ..."
"$(CONDA)" env update -n $(CONDA_ENV) -f environment.yml

.PHONY: envclean
envclean: check_conda
@echo "Removing conda env $(CONDA_ENV)"
@-"$(CONDA)" remove -n $(CONDA_ENV) --yes --all
@echo " docs to generate HTML documentation with Sphinx."
@echo "\nDeployment targets:"
@echo " dist to build source and wheel package."

## Build targets

.PHONY: bootstrap
bootstrap: check_conda conda_env bootstrap_dev
@echo "Bootstrap ..."

.PHONY: bootstrap_dev
bootstrap_dev:
@echo "Installing development requirements for tests and docs ..."
@-bash -c "$(CONDA) install -y -n $(CONDA_ENV) -c conda-forge pytest flake8 sphinx bumpversion"
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && pip install -r requirements_dev.txt"

.PHONY: install
install: bootstrap
install:
@echo "Installing application ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && python setup.py develop"
@-bash -c 'pip install -e .'
@echo "\nStart service with \`make start'"

.PHONY: develop
develop:
@echo "Installing development requirements for tests and docs ..."
@-bash -c 'pip install -e ".[dev]"'

.PHONY: start
start: check_conda
start:
@echo "Starting application ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && $(APP_NAME) start -d"
@-bash -c "$(APP_NAME) start -d"

.PHONY: stop
stop: check_conda
stop:
@echo "Stopping application ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && $(APP_NAME) stop"
@-bash -c "$(APP_NAME) stop"

.PHONY: restart
restart: stop start
@echo "Restarting application ..."

.PHONY: status
status: check_conda
status:
@echo "Show status ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && $(APP_NAME) status"
@-bash -c "$(APP_NAME) status"

.PHONY: clean
clean: srcclean envclean
@echo "Cleaning generated files ..."
@-for i in $(TEMP_FILES); do \
test -e $$i && rm -v -rf $$i; \
done

.PHONY: srcclean
srcclean:
@echo "Removing *.pyc files ..."
@-find $(APP_ROOT) -type f -name "*.pyc" -print | xargs rm

.PHONY: distclean
distclean: clean
@echo "Cleaning ..."
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

.PHONY: clean-build
clean-build:
@echo "Remove build artifacts ..."
@-rm -fr build/
@-rm -fr dist/
@-rm -fr .eggs/
@-find . -name '*.egg-info' -exec rm -fr {} +
@-find . -name '*.egg' -exec rm -f {} +
@-find . -name '*.log' -exec rm -fr {} +
@-find . -name '*.sqlite' -exec rm -fr {} +

.PHONY: clean-pyc
clean-pyc:
@echo "Remove Python file artifacts ..."
@-find . -name '*.pyc' -exec rm -f {} +
@-find . -name '*.pyo' -exec rm -f {} +
@-find . -name '*~' -exec rm -f {} +
@-find . -name '__pycache__' -exec rm -fr {} +

.PHONY: clean-test
clean-test:
@echo "Remove test artifacts ..."
@-rm -fr .pytest_cache

.PHONY: clean-dist
clean-dist: clean
@echo "Run 'git clean' ..."
@git diff --quiet HEAD || echo "There are uncommited changes! Not doing 'git clean' ..."
@-git clean -dfx -e *.bak -e custom.cfg
@-git clean -dfx

## Test targets

.PHONY: test
test: check_conda
@echo "Running tests (skip slow, online and data tests) ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV);pytest -v -m 'not slow and not online and not data'"
test:
@echo "Running tests (skip slow and online tests) ..."
@bash -c 'pytest -v -m "not slow and not online" tests/'

.PHONY: testall
testall: check_conda
.PHONY: test-all
test-all:
@echo "Running all tests (including slow and online tests) ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && pytest -v"
@bash -c 'pytest -v tests/'

.PHONY: pep8
pep8: check_conda
@echo "Running pep8 code style checks ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV) && flake8"
.PHONY: lint
lint:
@echo "Running flake8 code style checks ..."
@bash -c 'flake8'

## Sphinx targets
## Sphinx targets

.PHONY: docs
docs: check_conda
docs:
@echo "Generating docs with Sphinx ..."
@-bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV);$(MAKE) -C $@ clean html"
@echo "open your browser: firefox docs/build/html/index.html"
@-bash -c '$(MAKE) -C $@ clean html'
@echo "open your browser: open file://$(APP_ROOT)/docs/build/html/index.html"

## Deployment targets

.PHONY: dist
dist: clean
@echo "Builds source and wheel package ..."
@-python setup.py sdist
@-python setup.py bdist_wheel
ls -l dist
6 changes: 2 additions & 4 deletions c4cds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

"""Top-level package for c4cds-wps."""

from .wsgi import application
from .__version__ import __author__, __email__, __version__ # noqa: F401

__author__ = """Carsten Ehbrecht"""
__email__ = 'ehbrecht@dkrz.de'
__version__ = '0.2.0'
from .wsgi import application # noqa: F401
9 changes: 9 additions & 0 deletions c4cds/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

# This information is located in its own file so that it can be loaded
# without importing the main package when its dependencies are not installed.
# See: https://packaging.python.org/guides/single-sourcing-package-version

__author__ = """Carsten Ehbrecht"""
__email__ = 'ehbrecht@dkrz.de'
__version__ = '0.2.0'
2 changes: 1 addition & 1 deletion c4cds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pywps import configuration

from . import wsgi
from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

PID_FILE = os.path.abspath(os.path.join(os.path.curdir, "pywps.pid"))

Expand Down
5 changes: 2 additions & 3 deletions c4cds/ncdump.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import six
import os
from subprocess import check_output, CalledProcessError
from subprocess import check_output

import logging
LOGGER = logging.getLogger('PYWPS')
Expand All @@ -15,7 +14,7 @@ def ncdump(dataset):

try:
output = check_output(['ncdump', '-h', dataset])
if not isinstance(output, six.string_types):
if not isinstance(output, str):
output = output.decode('utf-8')
lines = output.split('\n')
# replace the filename for safety
Expand Down
7 changes: 4 additions & 3 deletions c4cds/plotter.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy import config

from netCDF4 import Dataset

from c4cds.util import guess_variable_name

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt # noqa: E402


class Plotter(object):
def __init__(self, output_dir=None):
Expand Down
6 changes: 3 additions & 3 deletions c4cds/regridder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

from c4cds import util

import logging
LOGGER = logging.getLogger('PYWPS')

# domain types
GLOBAL = 'global'
REGIONAL = 'regional'

GRID_FILES_DIR = os.path.join(os.path.dirname(__file__), 'resources', 'grid_files')

import logging
LOGGER = logging.getLogger('PYWPS')


class Regridder(object):
def __init__(self, output_dir=None, archive_base=None):
Expand Down
1 change: 0 additions & 1 deletion c4cds/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import tempfile
import glob

from c4cds import util
Expand Down
1 change: 0 additions & 1 deletion c4cds/subsetter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import tempfile

from cdo import Cdo

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'
services:
emu:
wps:
build: .
image: cp4cds/c4cds-wps
ports:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# General information about the project.
project = u'c4cds-wps'
copyright = u"2018, Carsten Ehbrecht"
copyright = u"2019, Carsten Ehbrecht"
author = u"Carsten Ehbrecht"

# The version info for the project you're documenting, acts as replacement
Expand Down
4 changes: 2 additions & 2 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Use one of the existing ``sample-*.cfg`` files as example and copy them to ``etc

For example change the hostname (*demo.org*) and logging level:

.. code-block:: sh
.. code-block:: console
$ cd c4cds
$ vim etc/custom.cfg
Expand All @@ -51,7 +51,7 @@ For example change the hostname (*demo.org*) and logging level:

Start the service with your custom configuration:

.. code-block:: sh
.. code-block:: console
# start the service with this configuration
$ c4cds start -c etc/custom.cfg
Expand Down

0 comments on commit f8f3597

Please sign in to comment.