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

Addresses #28, #37 moved main files to src folder. Testing and sphinx… #49

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
with:
python-version: 3.9
cache: 'pip'
cache-dependency-path: '**/setup.py'
cache-dependency-path: '**/setup.cfg'
- name: Install package with dependencies
run: pip install -e ".[dev]"
if: steps.python-cache.outputs.cache-hit != 'true'
- name: Run black
run: black undate --check --diff
run: black src --check --diff
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
with:
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: '**/setup.py'
cache-dependency-path: '**/setup.cfg'
- name: Install package with dependencies
run: pip install -e ".[dev]"
if: steps.python-cache.outputs.cache-hit != 'true'
- name: Run unit tests
run: pytest
run: tox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ColeDCrawford I don't know how to reconcile tox with the python version test matrix, do you ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tox-gh-actions worked!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now do we need to specify the python versions in more places? would be nice if we could avoid that duplication somehow (seems redundant to have it in the tox config and also the build matrix). We should put it on the readme at some point, too, but hoping we can use a badge to pull from pypi once we publish.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it would be nice to pull the build matrix from tox.ini tox.envlist or setup.cfg, but not sure how to set that up.

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
```

ColeDCrawford marked this conversation as resolved.
Show resolved Hide resolved
### 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
52 changes: 3 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
import os
from setuptools import setup
import setuptools

from undate import __version__

# load the readme contents and use for package long description
with open(os.path.join(os.path.dirname(__file__), "README.md")) as readme:
README = readme.read()

REQUIREMENTS = ["python-dateutil"]
TEST_REQUIREMENTS = ["pytest>=7.2"]
DEV_REQUIREMENTS = [
"black>=22.10.0",
"pre-commit>=2.20.0",
]

setup(
name="undate",
version=__version__,
description="library for working with uncertain, fuzzy, or "
+ "partially unknown dates and date intervals",
long_description=README,
url="https://github.com/dh-tech/hackathon-2022",
author="DHTech",
author_email="dhtech.community@gmail.com",
license="Apache License, Version 2.0",
packages=["undate"],
install_requires=REQUIREMENTS,
tests_require=TEST_REQUIREMENTS,
extras_require={
"test": TEST_REQUIREMENTS,
"dev": TEST_REQUIREMENTS + DEV_REQUIREMENTS,
},
classifiers=[
# any relevant environment classifiers ?
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"Typing :: Typed",
],
)
if __name__ == "__main__":
setuptools.setup()
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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought () wasn't needed anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just old school, I guess. We can remove them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am too, trying to train myself not to do this style class Undate(Object): any more

"""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
Loading