Skip to content

Commit 0344dcd

Browse files
committed
Improvements to pagesizes, and added new features
1 parent eab53fe commit 0344dcd

19 files changed

+1021
-643
lines changed

.readthedocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ formats: all
1717
python:
1818
version: 3.6
1919
install:
20+
- requirements: requirements.txt
2021
- requirements: doc-source/requirements.txt

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include __pkginfo__.py
22
include LICENSE
3+
include requirements.txt
34
recursive-exclude **/__pycache__ *

__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
repo_root = pathlib.Path(__file__).parent
4545

4646
# Get info from files; set: long_description
47-
install_requires = []
4847
long_description = (repo_root / "README.rst").read_text() + '\n'
48+
install_requires = (repo_root / "requirements.txt").read_text().split('\n')
4949
extras_require = {"dates": ["pytz>=2019.1"]}
5050

5151
classifiers = [

doc-source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
]
4141

4242
templates_path = ['_templates']
43+
html_static_path = ['_static']
4344
source_suffix = '.rst'
4445
exclude_patterns = []
4546

doc-source/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sphinxcontrib-httpdomain
22
sphinx
3+
pytz >= 2019.1

domdf_python_tools/bases.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# !/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# bases.py
5+
"""
6+
Useful base classes
7+
"""
8+
#
9+
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
10+
#
11+
# This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU Lesser General Public License as published by
13+
# the Free Software Foundation; either version 3 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Lesser General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Lesser General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24+
# MA 02110-1301, USA.
25+
#
26+
27+
28+
29+
# stdlib
30+
from abc import ABC, abstractmethod
31+
from collections import UserList
32+
from pprint import pformat
33+
34+
# 3rd party
35+
import pydash
36+
37+
38+
class Dictable(ABC):
39+
"""
40+
The basic structure of a class than can be converted into a dictionary
41+
"""
42+
43+
@abstractmethod
44+
def __init__(self, *args, **kwargs):
45+
pass
46+
47+
def __str__(self):
48+
return self.__repr__()
49+
50+
def __iter__(self):
51+
for key, value in self.__dict__().items():
52+
yield key, value
53+
54+
def __getstate__(self):
55+
return self.__dict__()
56+
57+
def __setstate__(self, state):
58+
self.__init__(**state)
59+
60+
def __copy__(self):
61+
return self.__class__(**self.__dict__())
62+
63+
def __deepcopy__(self, memodict={}):
64+
return self.__copy__()
65+
66+
@abstractmethod
67+
def __dict__(self):
68+
return dict()
69+
70+
def __eq__(self, other):
71+
if isinstance(other, self.__class__):
72+
return pydash.predicates.is_match(other.__dict__(), self.__dict__())
73+
74+
return NotImplemented
75+
76+
77+
def namedlist(name="NamedList"):
78+
"""
79+
A factory function to return a custom list subclass with a name
80+
81+
:param name:
82+
:type name:
83+
:return:
84+
:rtype:
85+
"""
86+
87+
class NamedList(UserList):
88+
"""
89+
A list with a name
90+
"""
91+
92+
def __repr__(self):
93+
return f"{super().__repr__()}"
94+
95+
def __str__(self):
96+
return f"{self.__class__.__name__}{pformat(list(self))}"
97+
98+
NamedList.__name__ = name
99+
100+
return NamedList

domdf_python_tools/doctools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def append_doctring_from_another(target, original):
8585

8686

8787
def make_sphinx_links(input_string, builtins_list=None):
88-
"""
88+
r"""
8989
Make proper sphinx links out of double-backticked strings in docstring.
9090
9191
i.e. \`\`str\`\` becomes \:class\:\`~python:str\`
@@ -148,7 +148,7 @@ def wrapper(target):
148148

149149

150150
def sphinxify_docstring():
151-
"""
151+
r"""
152152
Make proper sphinx links out of double-backticked strings in docstring.
153153
154154
i.e. \`\`str\`\` becomes \:class\:\`~python:str\`

domdf_python_tools/enums.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# !/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# enums.py
5+
"""
6+
Enum subclasses with some extra features
7+
"""
8+
#
9+
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
10+
#
11+
# This program is free software; you can redistribute it and/or modify
12+
# it under the terms of the GNU Lesser General Public License as published by
13+
# the Free Software Foundation; either version 3 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU Lesser General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU Lesser General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24+
# MA 02110-1301, USA.
25+
#
26+
27+
from enum import Enum
28+
29+
__all__ = ["IntEnum", "StrEnum"]
30+
31+
32+
class IntEnum(Enum):
33+
"""
34+
An Enum that can be converted into an integer
35+
"""
36+
37+
def __int__(self):
38+
return self.value
39+
40+
def __eq__(self, other):
41+
if int(self) == other:
42+
return True
43+
else:
44+
return super().__eq__(other)
45+
46+
47+
class StrEnum(Enum):
48+
"""
49+
An Enum that can be converted into a string
50+
"""
51+
52+
def __str__(self):
53+
return self.value
54+
55+
def __repr__(self):
56+
return self.value
57+
58+
def __eq__(self, other):
59+
if str(self) == other:
60+
return True
61+
else:
62+
return super().__eq__(other)
63+

0 commit comments

Comments
 (0)