Skip to content

Commit 13a1fbf

Browse files
authored
Merge pull request #16 from devinaconley/0.2.0
0.2.0
2 parents 35a7bc0 + 4d14a23 commit 13a1fbf

File tree

17 files changed

+482
-50
lines changed

17 files changed

+482
-50
lines changed

.github/workflows/publish.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
10+
test:
11+
uses: ./.github/workflows/test.yml
12+
secrets: inherit
13+
14+
build:
15+
name: build objectfactory dist
16+
needs: test
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: check out git repository
22+
uses: actions/checkout@v4
23+
24+
- name: setup python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.x'
28+
29+
- name: install python dependencies
30+
run: pip install build
31+
32+
- name: build binary wheel and source tarball
33+
run: python3 -m build
34+
35+
- name: store the dist package
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: distribution
39+
path: dist/
40+
41+
42+
publish:
43+
name: publish objectfactory to pypi
44+
needs: build
45+
46+
runs-on: ubuntu-latest
47+
environment:
48+
name: release
49+
url: https://pypi.org/p/objectfactory
50+
permissions:
51+
id-token: write
52+
53+
steps:
54+
- name: get dist package
55+
uses: actions/download-artifact@v4
56+
with:
57+
name: distribution
58+
path: dist/
59+
60+
- name: publish package to pypi
61+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: test
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_call:
7+
8+
jobs:
9+
10+
test:
11+
name: run objectfactory unit tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: check out git repository
16+
uses: actions/checkout@v4
17+
18+
- name: setup conda env
19+
uses: conda-incubator/setup-miniconda@v2
20+
with:
21+
activate-environment: py-object-factory
22+
environment-file: environment.yml
23+
auto-activate-base: false
24+
25+
- name: pytest
26+
shell: bash -l {0}
27+
run: pytest -v --cov --cov-report term --cov-report xml
28+
29+
- name: upload coverage report
30+
env:
31+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
32+
uses: codecov/codecov-action@v2

.readthedocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# .readthedocs.yml
22

33
version: 2
4+
build:
5+
os: ubuntu-22.04
6+
tools:
7+
python: "miniconda3-4.7"
48
sphinx:
59
configuration: docs/source/conf.py
610
formats:

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# py-object-factory
22

3-
[![Build Status](https://app.travis-ci.com/devinaconley/py-object-factory.svg?branch=develop)](https://app.travis-ci.com/devinaconley/py-object-factory)
3+
[![Build Status](https://github.com/devinaconley/py-object-factory/actions/workflows/test.yml/badge.svg)](https://github.com/devinaconley/py-object-factory/actions/workflows/test.yml)
44
[![codecov](https://codecov.io/gh/devinaconley/py-object-factory/branch/develop/graph/badge.svg)](https://codecov.io/gh/devinaconley/py-object-factory)
55
[![Documentation Status](https://readthedocs.org/projects/objectfactory/badge/?version=latest)](https://objectfactory.readthedocs.io/en/latest/?badge=latest)
66

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
# project info
99
project = 'objectfactory'
10-
copyright = '2018-2023, Devin A. Conley'
10+
copyright = '2018-2025, Devin A. Conley'
1111
author = 'Devin A. Conley'
12-
release = '0.1.1'
12+
release = '0.2.0'
1313

1414
# config
1515
extensions = [

environment.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- ncurses
1010
- openssl
1111
- pip
12-
- python>=3.6,<3.8
12+
- python>=3.6,<3.14
1313
- readline
1414
- setuptools
1515
- sqlite
@@ -21,18 +21,18 @@ dependencies:
2121
- atomicwrites
2222
- attrs
2323
- chardet
24-
- codecov~=2.1.7
25-
- coverage~=5.2
24+
- codecov~=2.1.13
25+
- coverage~=7.6.12
2626
- idna
2727
- marshmallow>=3,<4
2828
- more-itertools
2929
- pluggy
3030
- py
31-
- pytest~=5.4.3
31+
- pytest~=7.4.0
3232
- pytest-cov~=2.10.0
3333
- requests
3434
- six
35-
- sphinx~=3.4.0
35+
- sphinx~=7.1.2
3636
- sphinx-rtd-theme
3737
- m2r2
3838
- urllib3

objectfactory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# do imports
77
from .serializable import Serializable
88
from .factory import Factory, register, create
9-
from .field import Field, Nested, List, Integer, String, Boolean, Float
9+
from .field import Field, Nested, List, Integer, String, Boolean, Float, DateTime, Enum
1010

1111
__version__ = '0.1.0'

objectfactory/field.py

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __set__(self, instance, value):
3434
setattr(instance, self._attr_key, value)
3535

3636
def marshmallow(self):
37-
return marshmallow.fields.Field(
37+
return marshmallow.fields.Raw(
3838
data_key=self._key,
3939
required=self._required,
4040
allow_none=self._allow_none
@@ -93,18 +93,86 @@ def marshmallow(self):
9393
)
9494

9595

96+
class DateTime(Field):
97+
"""
98+
serializable field for datetime data
99+
"""
100+
101+
def __init__(
102+
self,
103+
default=None,
104+
key=None,
105+
date_format=None,
106+
required=False,
107+
allow_none=True
108+
):
109+
"""
110+
:param default: default value for field if unset
111+
:param key: dictionary key to use for field serialization
112+
:param date_format: date format to use (defaults to iso)
113+
:param required: whether this field is required to deserialize an object
114+
:param allow_none: whether null should be considered a valid value
115+
"""
116+
super().__init__(default=default, key=key, required=required, allow_none=allow_none)
117+
self._date_format = date_format
118+
119+
def marshmallow(self):
120+
return marshmallow.fields.DateTime(
121+
data_key=self._key,
122+
required=self._required,
123+
allow_none=self._allow_none,
124+
format=self._date_format
125+
)
126+
127+
128+
class Enum(Field):
129+
"""
130+
serializable field for enumerated data
131+
"""
132+
133+
def __init__(
134+
self,
135+
enum,
136+
default=None,
137+
key=None,
138+
required=False,
139+
allow_none=True,
140+
by_value=False,
141+
):
142+
"""
143+
:param enum: enum type for field validation
144+
:param default: default value for field if unset
145+
:param key: dictionary key to use for field serialization
146+
:param required: whether this field is required to deserialize an object
147+
:param allow_none: whether null should be considered a valid value
148+
:param by_value: whether to serialize by value or by symbol
149+
"""
150+
super().__init__(default=default, key=key, required=required, allow_none=allow_none)
151+
self._enum = enum
152+
self._by_value = by_value
153+
154+
def marshmallow(self):
155+
return marshmallow.fields.Enum(
156+
self._enum,
157+
data_key=self._key,
158+
required=self._required,
159+
allow_none=self._allow_none,
160+
by_value=self._by_value
161+
)
162+
163+
96164
class Nested(Field):
97165
"""
98166
field type for nested serializable object
99167
"""
100168

101169
def __init__(
102-
self,
103-
default=None,
104-
key=None,
105-
field_type=None,
106-
required=False,
107-
allow_none=True
170+
self,
171+
default=None,
172+
key=None,
173+
field_type=None,
174+
required=False,
175+
allow_none=True
108176
):
109177
"""
110178
:param default: default value for field if unset
@@ -131,12 +199,12 @@ class List(Field):
131199
"""
132200

133201
def __init__(
134-
self,
135-
default=None,
136-
key=None,
137-
field_type=None,
138-
required=False,
139-
allow_none=True
202+
self,
203+
default=None,
204+
key=None,
205+
field_type=None,
206+
required=False,
207+
allow_none=True
140208
):
141209
"""
142210
:param default: default value for field if unset

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='objectfactory',
8-
version='0.1.1',
8+
version='0.2.0',
99
author='Devin A. Conley',
1010
author_email='devinaconley@gmail.com',
1111
description='objectfactory is a python package to easily implement the factory design pattern for object creation, serialization, and polymorphism',

test/test_boolean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_definition(self):
1919
"""
2020
test definition of class with boolean field
2121
22-
expect field to to be collected, registered, and included
22+
expect field to be collected, registered, and included
2323
in schema creation
2424
"""
2525

0 commit comments

Comments
 (0)