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

skip conda environment handling in makefile #70

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 82 additions & 92 deletions {{cookiecutter.project_repo_name}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,139 +1,129 @@
# Application
APP_ROOT := $(CURDIR)
# Configuration
APP_ROOT := $(abspath $(lastword $(MAKEFILE_LIST))/..)
APP_NAME := {{ cookiecutter.project_slug }}

# 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 " 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 " 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) 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'"
@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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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 {{ cookiecutter.project_slug }}
$ vim etc/custom.cfg
Expand All @@ -40,7 +40,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
$ {{ cookiecutter.project_slug }} start -c etc/custom.cfg
Expand Down
23 changes: 16 additions & 7 deletions {{cookiecutter.project_repo_name}}/docs/source/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@ 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:

Running tests
-------------

Run tests using `pytest`_.
Run tests using pytest_.

First activate the ``{{ cookiecutter.project_slug }}`` Conda environment and install ``pytest``.

.. code-block:: console

$ source activate {{ cookiecutter.project_slug }}
$ 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,11 +78,13 @@ Update the Conda specification file to build identical environments_ on a specif

.. code-block:: console

$ conda env create -f environment.yml
$ source activate {{ cookiecutter.project_slug }}
$ make clean
$ make install
$ make spec
$ conda list -n {{ cookiecutter.project_slug }} --explicit > spec-file.txt

.. _`environments`: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments
.. _environments: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments


Bump a new version
Expand Down
37 changes: 22 additions & 15 deletions {{cookiecutter.project_repo_name}}/docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,40 @@ Install from GitHub

Check out code from the {{ cookiecutter.project_name }} GitHub repo and start the installation:

.. code-block:: sh
.. code-block:: console

$ git clone https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_repo_name }}.git
$ cd {{ cookiecutter.project_slug }}

Create Conda environment named `{{ cookiecutter.project_slug }}`:

.. code-block:: console

$ conda env create -f environment.yml
$ source activate {{ cookiecutter.project_slug }}
$ python setup.py develop

... or do it the lazy way
+++++++++++++++++++++++++
Install {{ cookiecutter.project_name }} 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/{{ cookiecutter.github_username }}/{{ cookiecutter.project_repo_name }}.git
$ cd {{ cookiecutter.project_slug }}
$ 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 {{ cookiecutter.project_name }} PyWPS service
-{{ '-' * (cookiecutter.project_name|count + 19) }}

After successful installation you can start the service using the ``{{ cookiecutter.project_slug }}`` command-line.

.. code-block:: sh
.. code-block:: console

$ {{ cookiecutter.project_slug }} --help # show help
$ {{ cookiecutter.project_slug }} start # start service with default configuration
Expand All @@ -64,14 +71,14 @@ http://localhost:{{ cookiecutter.http_port }}/wps?service=WPS&version=1.0.0&requ

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 @@ -80,7 +87,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
2 changes: 1 addition & 1 deletion {{cookiecutter.project_repo_name}}/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pywps>=4.0.0
pywps>=4.2.0
jinja2
click
psutil
4 changes: 2 additions & 2 deletions {{cookiecutter.project_repo_name}}/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
pytest
flake8
pytest-flake8
sphinx>=1.7
bumpversion
bump2version
twine
Loading