Commit 76f2d8bc authored by dboe's avatar dboe
Browse files

merged after cookieinvation

parents d8035e59 45a4c127
image: python:latest
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/
stages:
- build
- test
- deploy
before_script:
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
dist:
stage: build
script:
- python setup.py bdist_wheel
# an alternative approach is to install and run:
- pip install dist/*
# run the command here
artifacts:
paths:
- dist/*.whl
expire_in: 1h
only:
- tags
pages:
stage: build
script:
- pip install sphinx sphinx_rtd_theme recommonmark
- cd docs
- make html
- cd ..
- mkdir -p public
- rm -rf public/*
- mv docs/_build/html/* public/ # add it to pages. Pages is exposing public/index.html
only:
- master
cache:
paths:
- public
artifacts:
paths:
- public
- docs
lint:
stage: test
before_script:
- pip install -q flake8
script:
- flake8
test:
stage: test
script:
- pip --version
- pip install tox # you can also use tox
- tox
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
# paths:
# pa- report/unit
reports:
junit:
- report/junit.xml
gitlab-release:
image: inetprocess/gitlab-release
stage: deploy
before_script:
- echo "Starting release"
script:
- gitlab-release --message 'Automatic release' dist/* # Note:
only:
- tags
pypi:
image: docker.km3net.de/base/python:3
stage: deploy
cache: {}
before_script:
- echo "Starting upload to pypi"
script:
# Check if current_version is already uploaded
- VERSION=$((python -c "import configparser; config = configparser.ConfigParser(); config.read('setup.cfg'); print(config['bumpversion']['current_version'])") 2>&1)
- MODULE_NAME=$((python -c "import configparser; config = configparser.ConfigParser(); config.read('setup.cfg'); print(config['metadata']['name'])") 2>&1)
- PACKAGE_JSON_URL="https://pypi.org/pypi/$MODULE_NAME/json"
- apt-get install -qq -y jq
- PYPI_VERSIONS=$(curl -s "$PACKAGE_JSON_URL" | jq -r '.releases | keys | .[]' | sort -V)
- if [[ $PYPI_VERSIONS =~ $VERSION ]]; then echo "Version $VERSION is already uploaded!"; exit 1; fi
# Version not already uploaded so do it now.
- echo "Uploading version $VERSION"
- pip install -U twine
- python setup.py sdist
- twine upload dist/*
rules:
# for debuggin: git commit -am "deb" && git push && bumpversion patch && git tag -l --sort=-v:refname | head -n 1 | git push origin
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
# Required
version: 2
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: docs/requirements.txt
......@@ -15,4 +15,3 @@ Contributors
------------
None yet. Why not be the first?
......@@ -23,6 +23,9 @@ If you are reporting a bug, please include:
* Any details about your local setup that might be helpful in troubleshooting.
* Detailed steps to reproduce the bug.
If you want quick feedback, it is helpful to mention speicific developers
(@devloper_name) or @all. This will trigger a mail to the corresponding developer(s).
Fix Bugs
~~~~~~~~
......@@ -38,14 +41,20 @@ and "help wanted" is open to whoever wants to implement it.
Write Documentation
~~~~~~~~~~~~~~~~~~~
tfields could always use more documentation, whether as part of the
official tfields docs, in docstrings, or even on the web in blog posts,
`tfields` could always use more :ref:`documentation<Documentation>`, whether as part of the
official `tfields` docs, in docstrings, or even on the web in blog posts,
articles, and such.
Write Unittests or Doctests
~~~~~~~~~~~~~~~~~~~~~~~~~~~
`tfields` profits a lot from better :ref:`testing<Testing>`. We encourage you to add unittests
(in the `tests` directory) or doctests (as part of docstrings or in the documentation).
Submit Feedback
~~~~~~~~~~~~~~~
The best way to send feedback is to file an issue at https://gitlab.mpcdf.mpg.de/dboe/tfields/issues.
The best way to send feedback is to file an `Issue <https://gitlab.mpcdf.mpg.de/dboe/tfields/issues>`_.
If you are proposing a feature:
......@@ -62,31 +71,35 @@ Ready to contribute? Here's how to set up `tfields` for local development.
1. Fork the `tfields` repo.
2. Clone your fork locally::
$ git clone git@gitlab.mpcdf.mpg.de:your_name_here/tfields.git
$ git clone git@gitlab.mpcdf.mpg.de:dboe/tfields.git
3. Set up your fork for local development::
$ cd tfields/
$ python setup.py develop
$ pip install .[dev]
4. Create a branch for local development::
4. Step 3. already installed `pre-commit <https://pre-commit.com/>`_. Initialize it by running::
$ pre-commit install
5. Create a branch for local development::
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
5. When you're done making changes, check that your changes pass flake8 and the
6. When you're done making changes, check that your changes pass flake8 and the
tests::
$ make test
6. Commit your changes and push your branch to origin::
7. Commit your changes and push your branch to origin::
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
7. Submit a pull request through the repository website.
8. Submit a pull request through the repository website.
Pull Request Guidelines
-----------------------
......@@ -98,11 +111,15 @@ Before you submit a pull request, check that it meets these guidelines:
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check
https://travis-ci.com/dboe/tfields/pull_requests
https://gitlab.mpcdf.mpg.de/dboe/tfields/-/merge_requests
and make sure that the tests pass for all supported Python versions.
Tips
----
Testing
-------
To run tests, use::
$ make test
To run a subset of tests, you have the following options::
......@@ -114,22 +131,36 @@ To run a subset of tests, you have the following options::
$ pytest --doctest-modules tfields/core.py -k "MyClass.funciton_with_doctest"
Use the '--trace' option to directly jump into a pdb debugger on fails
Use the '--trace' option to directly jump into a pdb debugger on fails. Check out the coverage of your api with::
$ make coverage
Documentation
-------------
To compile the documentation (including automatically generated module api docs), run::
$ make doc
Use doctests as much as possible in order to have tested examples in your documentation.
Styleguide
-----------
Please follow the `google style guide <https://google.github.io/styleguide/pyguide.html>`_ illustrated
by `this example <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html>`_.
Deploying
---------
A reminder for the maintainers on how to deploy.
Make sure all your changes are committed (including an entry in HISTORY.rst if you have one).
Make sure all your changes are committed.
Then run::
$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags
$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags
or without bump2version just do
or use the convenient alias for the above (patch increases only)::
$ make publish
$ make publish
Travis will then deploy to PyPI if tests pass.
The CI will then deploy to PyPI if tests pass.
SHELL := /bin/bash # Use bash syntax
CURRENT_PATH := $(shell pwd)
MODULE := $(shell basename "$(CURRENT_PATH)")
VERSION := $(shell python -c "import sys; import $(MODULE); sys.stdout.write($(MODULE).__version__)")
SOURCES := $(shell find $(MODULE) -name '*.py')
DOCUMENTATION := $(shell find . -name '*.rst')
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SPHINXSOURCEDIR = ./docs
SPHINXBUILDDIR = docs/_build
GITSTATUS = $(shell git status --porcelain)
part ?= patch
test: FORCE
flake8 rna tests
py.test
coverage:
# coverage run $(MODULE) test
py.test --cov=$(MODULE) || true
# coverage report
coverage html
python -m webbrowser htmlcov/index.html
clean:
coverage erase
rm -rf htmlcov
rm -rf docs/_build
rm -rf docs/source
rm -rf dist
rm -rf report
rm -rf .tox
rm -rf .pytest_cache
rm -rf *.egg-info
pre-commit clean
publish:
# call optional with argument: make part=minor publish
bump2version $(part) # possible: major / minor / patch
git push
git push --tags
untag:
# remove last tag. mostly, because publishing failed
git tag -d v$(VERSION)
git push origin :refs/tags/v$(VERSION)
requirements: setup.cfg
# We have all the information in the setup.cfg file. For some reasons (e.g. bug in setuptools or limitations to use setup.cfg in readthedocs) we still need a requirements file
python -c "import configparser; import os; config = configparser.ConfigParser(); config.read('setup.cfg'); deps = config['metadata']['install_requires'].split('\n'); deps = [x for x in deps if x]; head = '# Autogenerated by Makefile from setup.cfg install_requies section. Remove this line if you want to fix this file.'; path = 'requirements.txt'; f = open(path, 'r') if os.path.exists(path) else None; line = f.readline() if f else ''; quit('User defined requirements already existing.') if f and not line.startswith(head[:20]) else None; f = open('requirements.txt', 'w'); f.write('\n'.join([head] + deps))"
doc: Makefile $(SOURCES) $(DOCUMENTATION) docs/conf.py docs/apidoc-template/*
# link apidoc to source and build html documentation with sphinx
python setup.py build_sphinx
# manual version would be
# # link apidoc to source
# sphinx-apidoc -o docs/source/ $(MODULE)
# # build html documentation with sphinx
# # @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(0)
# sphinx-build -M html docs docs/_build
#
# open the html slides
python -m webbrowser docs/_build/html/index.html
update:
# get up to date with the cookiecutter template 'dough'
# first check that no changes are existing
@echo $(GITSTATUS)
@if [ -z $(GITSTATUS) ]; then \
echo "Working directory clean."; \
else \
git status; \
echo "Your status is not clean! I can not update!"; \
exit 1; \
fi
# Uninstall pre-commit
pre-commit uninstall
# Starting upgrade
cookiecutter_project_upgrader
# Install pre-commit again
pre-commit install
FORCE: ;
=======
tfields
=======
=========================
Introduction to `tfields`
=========================
.. pypi
.. image:: https://img.shields.io/pypi/v/tfields.svg
:target: https://pypi.python.org/pypi/tfields
:target: https://pypi.python.org/pypi/tfields
.. image:: https://img.shields.io/travis/dboe/tfields.svg
.. ci
.. image:: https://img.shields.io/travis/dboe/tfields.svg
:target: https://travis-ci.com/dboe/tfields
.. image:: https://gitlab.mpcdf.mpg.de/dboe/tfields/badges/master/pipeline.svg
:target: https://gitlab.mpcdf.mpg.de/dboe/tfields/commits/master
.. coverage
.. image:: https://gitlab.mpcdf.mpg.de/dboe/tfields/badges/master/coverage.svg
:target: https://gitlab.mpcdf.mpg.de/dboe/tfields/commits/master
.. readthedocs
.. image:: https://readthedocs.org/projects/tfields/badge/?version=latest
:target: https://tfields.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
:target: https://tfields.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. pyup crosschecks your dependencies. Github is default, gitlab more complicated: https://pyup.readthedocs.io/en/latest/readme.html#run-your-first-update
.. image:: https://pyup.io/repos/github/dboe/tfields/shield.svg
:target: https://pyup.io/repos/github/dboe/tfields/
:alt: Updates
.. image:: https://pyup.io/repos/github/dboe/tfields/shield.svg
:target: https://pyup.io/repos/github/dboe/tfields/
:alt: Updates
.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
Tensors, tensor fields, graphs, mesh manipulation, CAD and more on the basis of numpy.ndarrays. All objects keep track of their coordinate system. Symbolic math operations work for object manipulation.
* Free software: MIT License
* Documentation: https://tfields.readthedocs.io.
Licensed under the ``MIT License``
Resources
---------
* Source code: https://gitlab.mpcdf.mpg.de/dboe/tfields
* Documentation: https://tfields.readthedocs.io
* Pypi: https://pypi.python.org/pypi/tfields
Features
--------
The following features should be highlighted:
* TODO
# Minimal makefile for Sphinx documentation
#
<<<<<<< HEAD
=======
MODULE_PATH := $(shell cd ..; pwd)
MODULE := $(shell basename "$(MODULE_PATH)")
>>>>>>> cookiecutter-template
# You can set these variables from the command line, and also
# from the environment for the first two.
......@@ -12,6 +17,12 @@ BUILDDIR = _build
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
<<<<<<< HEAD
=======
apidocs: $(MODULEPATH)/$(MODULE)/*.py apidoc-templates/*
sphinx-apidoc -o source/ ../$(MODULE)
>>>>>>> cookiecutter-template
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
......
=================
API Documentation
=================
.. toctree::
:maxdepth: {{ maxdepth }}
{% for docname in docnames %}
{{ docname }}
{%- endfor %}
#####
#!/usr/bin/env python
#
# tfields documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
"""
This file is execfile()d with the current directory set to its
containing dir.
# If extensions (or modules to document with autodoc) are in another
# directory, add these directories to sys.path here. If the directory is
# relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
Note that not all possible configuration values are present in this
autogenerated file.
import tfields
All configuration values have a default; values that are commented out
serve to show the default.
If extensions (or modules to document with autodoc) are in another
directory, add these directories to sys.path here. If the directory is
relative to the documentation root, use os.path.abspath to make it
absolute, like shown here.
"""
import os
import subprocess
import configparser
import datetime
config = configparser.ConfigParser()
script_dir = os.path.dirname(__file__)
path = os.path.join(script_dir, "../setup.cfg")
config.read(path)
__version__ = config["bumpversion"]["current_version"]
name = config["metadata"]["name"]
source_dir = config["build_sphinx"]["source-dir"]
# -- General configuration ---------------------------------------------
......@@ -33,38 +36,71 @@ import tfields
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autosectionlabel', # links
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.autodoc',
'sphinx.ext.viewcode'
"sphinx.ext.autosectionlabel", # links
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.doctest",
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
]
def setup(app):
"""
Automatically run apidoc
see https://github.com/sphinx-doc/sphinx/issues/1861
"""
# distinguish when calling from project root dir and from docs dir
if os.path.basename(os.path.abspath(".")) == source_dir:
subprocess.call(
[
"sphinx-apidoc",
"-o",
"source/",
"../" + name,
"--templatedir",
"apidoc-template",
]
)
else:
subprocess.call(
[
"sphinx-apidoc",
"-o",
source_dir + "/source/",
name,
"--templatedir",
source_dir + "/apidoc-template",
]
)
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# General information about the project.
project = 'tfields'
copyright = "2020, Daniel Böckenhoff"
author = "Daniel Böckenhoff"
project = name
year = datetime.date.today().year
author = config["metadata"]["author"]
copyright = str(year) + ", " + author
# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
# the built documents.
#
# The short X.Y version.
version = tfields.__version__
version = __version__
# The full version, including alpha/beta/rc tags.
release = tfields.__version__
release = __version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
......@@ -76,10 +112,10 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
......@@ -90,7 +126,7 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "classic"
# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
......@@ -101,13 +137,13 @@ html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# html_static_path = ['_static']
# -- Options for HTMLHelp output ---------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'tfieldsdoc'
htmlhelp_basename = name + "doc"
# -- Options for LaTeX output ------------------------------------------
......@@ -116,15 +152,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
......@@ -134,9 +167,7 @@ latex_elements = {
# (source start file, target name, title, author, documentclass