Skip to content

Commit

Permalink
Merge pull request #91 from bird-house/skip-conda-in-makefile
Browse files Browse the repository at this point in the history
skip conda in Makefile
  • Loading branch information
cehbrecht committed Sep 10, 2019
2 parents 3264874 + b44fd01 commit 15ae055
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 137 deletions.
3 changes: 2 additions & 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 All @@ -28,6 +28,7 @@ __pycache__
.tox
nosetests.xml
unit_tests/testdata.json
coverage/

# R
*.Rhistory
Expand Down
198 changes: 107 additions & 91 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,139 +1,155 @@
# Application
APP_ROOT := $(CURDIR)
# Configuration
APP_ROOT := $(abspath $(lastword $(MAKEFILE_LIST))/..)
APP_NAME := emu

# 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
# Bumpversion 'dry' config
# if 'dry' is specified as target, any bumpversion call using 'BUMP_XARGS' will not apply changes
BUMP_XARGS ?= --verbose --allow-dirty
ifeq ($(filter dry, $(MAKECMDGOALS)), dry)
BUMP_XARGS := $(BUMP_XARGS) --dry-run
endif
.PHONY: dry
dry: setup.cfg
@-echo > /dev/null

# 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 " restart to restart $(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."
@echo " docs to generate HTML documentation with Sphinx."
@echo "\nDeployment targets:"
@echo " spec to generate Conda spec file."

## Conda 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

.PHONY: spec
spec: check_conda
@echo "Updating conda environment specification file ..."
@-"$(CONDA)" list -n $(CONDA_ENV) --explicit > spec-file.txt
@echo " debug to print variable values employed by this Makefile."
@echo " bump to update the package version."
@echo " dry to only display results (not applied) when combined with 'bump'."
@echo " dist to build source and wheel package."

.PHONY: debug
debug:
@-echo "Following variables are used:"
@-echo " SHELL: $(SHELL)"
@-echo " APP_ROOT: $(APP_ROOT)"
@-echo " BUMP_XARGS: $(BUMP_XARGS)"

## 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) pytest flake8 sphinx gunicorn psycopg2"
@-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
test:
@echo "Running tests (skip slow and online tests) ..."
@bash -c "source $(ANACONDA_HOME)/bin/activate $(CONDA_ENV);pytest -v -m 'not slow and not 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 tests/"
@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: bump
bump:
@-echo "Updating package version ..."
@[ "${VERSION}" ] || ( echo ">> 'VERSION' is not set"; exit 1 )
@-bash -c 'bump2version $(BUMP_XARGS) --new-version "${VERSION}" patch;'

.PHONY: dist
dist: clean
@echo "Builds source and wheel package ..."
@-python setup.py sdist
@-python setup.py bdist_wheel
ls -l dist
19 changes: 14 additions & 5 deletions docs/source/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ First install dependencies for the documentation:

.. code-block:: console
$ make bootstrap_dev
$ make develop
Run the Sphinx docs generator:

.. code-block:: console
$ make docs
.. _testing:
Expand All @@ -31,7 +36,9 @@ First activate the ``emu`` Conda environment and install ``pytest``.
.. code-block:: console
$ source activate emu
$ conda install pytest flake8 # if not already installed
$ pip install -r requirements_dev.txt # if not already installed
OR
$ make develop
Run quick tests (skip slow and online):

Expand Down Expand Up @@ -59,8 +66,8 @@ Do the same as above using the ``Makefile``.
.. code-block:: console
$ make test
$ make testall
$ make pep8
$ make test-all
$ make lint
Prepare a release
-----------------
Expand All @@ -71,9 +78,11 @@ Update the Conda specification file to build identical environments_ on a specif

.. code-block:: console
$ conda env create -f environment.yml
$ source activate emu
$ make clean
$ make install
$ make spec
$ conda list -n emu --explicit > spec-file.txt
.. _`environments`: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments

Expand Down
39 changes: 23 additions & 16 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Install from Conda

Install the ``emu`` Conda package:

.. code-block:: sh
.. code-block:: console
$ conda install -c birdhouse -c conda-forge emu
$ emu --help
Expand All @@ -35,33 +35,40 @@ Install from GitHub

Check out code from the Emu GitHub repo and start the installation:

.. code-block:: sh
.. code-block:: console
$ git clone https://github.com/bird-house/emu.git
$ cd emu
Create Conda environment named `emu`:

.. code-block:: console
$ conda env create -f environment.yml
$ source activate emu
$ python setup.py develop
... or do it the lazy way
+++++++++++++++++++++++++
Install `emu` app:

The previous installation instructions assume you have Anaconda installed.
We provide also a ``Makefile`` to run this installation without additional steps:
.. code-block:: console
.. code-block:: sh
$ pip install -e .
OR
make install
$ git clone https://github.com/bird-house/emu.git
$ cd emu
$ make clean # cleans up a previous Conda environment
$ make install # installs Conda if necessary and runs the above installation steps
For development you can use this command:

.. code-block:: console
$ pip install -e .[dev]
OR
$ make develop
Start Emu PyWPS service
-----------------------

After successful installation you can start the service using the ``emu`` command-line.

.. code-block:: sh
.. code-block:: console
$ emu start --help # show help
$ emu start # start service with default configuration
Expand All @@ -80,13 +87,13 @@ http://localhost:5000/wps?service=WPS&version=1.0.0&request=GetCapabilities.

You can find which process uses a given port using the following command (here for port 5000):

.. code-block:: sh
.. code-block:: console
$ netstat -nlp | grep :5000
Check the log files for errors:

.. code-block:: sh
.. code-block:: console
$ tail -f pywps.log
Expand All @@ -95,7 +102,7 @@ Check the log files for errors:

You can also use the ``Makefile`` to start and stop the service:

.. code-block:: sh
.. code-block:: console
$ make start
$ make status
Expand Down

0 comments on commit 15ae055

Please sign in to comment.