Skip to content

Commit

Permalink
Addresses dh-tech#28, dh-tech#37 moved main files to src folder. Test…
Browse files Browse the repository at this point in the history
…ing and sphinx-docs via tox.
  • Loading branch information
maltevogl committed Nov 11, 2022
1 parent c24fd51 commit 1f76e0d
Show file tree
Hide file tree
Showing 23 changed files with 286 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ wheels/
MANIFEST

# Environments
.tox
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
venv.bak/
15 changes: 15 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# File: .readthedocs.yaml

version: 2

build:
os: "ubuntu-20.04"
tools:
python: "3.9"

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
4 changes: 4 additions & 0 deletions Authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
AUTHORS
=======

DHtech Community
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ pre-commit install

### Run unit tests
```
pytest
tox
```

### Create documentation
```
tox -e docs
```

## Contributors
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file added docs/_static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../Authors.rst
63 changes: 63 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# 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('.'))


# -- Project information -----------------------------------------------------

project = 'Undate'
copyright = '2022, DHtech'
author = 'DHtech Community'

# The full version, including alpha/beta/rc tags
release = '0.0.1.dev'

master_doc = 'index'


# -- General configuration ---------------------------------------------------

# 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.autodoc',
'sphinx.ext.intersphinx',
'm2r2'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

source_suffix = [".rst", ".md"]

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# 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_logo = '_static/logo.png'
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Undate documentation
====================

This project ...


.. toctree::
:maxdepth: 3
:caption: Contents:

readme
undate
authors
license

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
3 changes: 3 additions & 0 deletions docs/license.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
License
=======
.. mdinclude:: ../LICENSE.md
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
3 changes: 3 additions & 0 deletions docs/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Introduction
============
.. mdinclude:: ../README.md
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-e .[dev]
sphinx
sphinx_rtd_theme
m2r2
11 changes: 11 additions & 0 deletions docs/undate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Undate
======

.. autoclass:: undate.undate.Undate
:members:
:undoc-members:


.. autoclass:: undate.undate.UndateInterval
:members:
:undoc-members:
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
46 changes: 46 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[metadata]
name = undate
version = attr: undate.__version__
author = 'DHTech'
author_email = 'dhtech.community@gmail.com'
description = "library for working with uncertain, fuzzy, or "
+ "partially unknown dates and date intervals"
long_description = file: README.md
license="Apache License, Version 2.0",
long_description_content_type = text/markdown
url = https://github.com/dh-tech/hackathon-2022
project_urls =
Project Home = https://dh-tech.github.io
Bug Tracker = https://github.com/dh-tech/hackathon-2022/-/issues
classifiers =
Development Status :: 2 - Pre-Alpha
Programming Language :: Python :: 3
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Utilities
Typing :: Typed

[options]
package_dir =
= src
packages = find:
python_requires = >=3.8
install_requires =
python-dateutil
[options.extras_require]
all =
%(dev)s
%(test)s
dev =
black>=22.10.0
pre-commit>=2.20.0
tox
sphinx
twine
test =
pytest>=7.2

[options.packages.find]
where = src
50 changes: 0 additions & 50 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 14 additions & 2 deletions undate/undate.py → src/undate/undate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ONE_DAY = datetime.timedelta(days=1)


class Undate:
class Undate():
"""Simple object for representing uncertain, fuzzy or partially unknown dates"""

DEFAULT_FORMAT = "ISO8601"
Expand Down Expand Up @@ -88,7 +88,14 @@ def duration(self) -> datetime.timedelta:
return self.latest - self.earliest + ONE_DAY


class UndateInterval:
class UndateInterval():
"""A date range between two uncertain dates.
:param earliest: Earliest undate
:type earliest: `undate.Undate`
:param latest: Latest undate
:type latest: `undate.Undate`
"""
# date range between two uncertain dates

def __init__(
Expand All @@ -107,6 +114,11 @@ def __eq__(self, other) -> bool:
return self.earliest == other.earliest and self.latest == other.latest

def duration(self) -> datetime.timedelta:
"""Calculate the duration between two undates.
:returns: A duration
:rtype: timedelta
"""
# what is the duration of this date range?

# if both years are known, subtract end of range from beginning of start
Expand Down
32 changes: 32 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tox]
envlist = py310
isolated_build = True

[pytest]
minversion = 6.0
addopts = -ra -q
testpaths =
tests

[testenv]
deps =
pytest
-e ./[test]
commands = pytest {posargs}

[testenv:flake8]
deps =
flake8
commands =
flake8 --ignore=E501,E402,F401 src/undate/ tests/

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
basepython = python3.10
deps =
-e ./[docs]
sphinx
sphinx_rtd_theme
m2r2
commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs "{toxworkdir}/docs_out" --color -W -bhtml {posargs}
python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'

0 comments on commit 1f76e0d

Please sign in to comment.