Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
61 changes: 61 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: publish

on:
push:
tags:
- '*'

jobs:

test:
uses: ./.github/workflows/test.yml
secrets: inherit

build:
name: build objectfactory dist
needs: test

runs-on: ubuntu-latest

steps:
- name: check out git repository
uses: actions/checkout@v4

- name: setup python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: install python dependencies
run: pip install build

- name: build binary wheel and source tarball
run: python3 -m build

- name: store the dist package
uses: actions/upload-artifact@v4
with:
name: distribution
path: dist/


publish:
name: publish objectfactory to pypi
needs: build

runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/objectfactory
permissions:
id-token: write

steps:
- name: get dist package
uses: actions/download-artifact@v4
with:
name: distribution
path: dist/

- name: publish package to pypi
uses: pypa/gh-action-pypi-publish@release/v1
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: test

on:
push:
pull_request:
workflow_call:

jobs:

test:
name: run objectfactory unit tests
runs-on: ubuntu-latest

steps:
- name: check out git repository
uses: actions/checkout@v4

- name: setup conda env
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: py-object-factory
environment-file: environment.yml
auto-activate-base: false

- name: pytest
shell: bash -l {0}
run: pytest -v --cov --cov-report term --cov-report xml

- name: upload coverage report
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v2
4 changes: 4 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# .readthedocs.yml

version: 2
build:
os: ubuntu-22.04
tools:
python: "miniconda3-4.7"
sphinx:
configuration: docs/source/conf.py
formats:
Expand Down
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# py-object-factory

[![Build Status](https://app.travis-ci.com/devinaconley/py-object-factory.svg?branch=develop)](https://app.travis-ci.com/devinaconley/py-object-factory)
[![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)
[![codecov](https://codecov.io/gh/devinaconley/py-object-factory/branch/develop/graph/badge.svg)](https://codecov.io/gh/devinaconley/py-object-factory)
[![Documentation Status](https://readthedocs.org/projects/objectfactory/badge/?version=latest)](https://objectfactory.readthedocs.io/en/latest/?badge=latest)

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# project info
project = 'objectfactory'
copyright = '2018-2023, Devin A. Conley'
copyright = '2018-2025, Devin A. Conley'
author = 'Devin A. Conley'
release = '0.1.1'
release = '0.2.0'

# config
extensions = [
Expand Down
10 changes: 5 additions & 5 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- ncurses
- openssl
- pip
- python>=3.6,<3.8
- python>=3.6,<3.14
- readline
- setuptools
- sqlite
Expand All @@ -21,18 +21,18 @@ dependencies:
- atomicwrites
- attrs
- chardet
- codecov~=2.1.7
- coverage~=5.2
- codecov~=2.1.13
- coverage~=7.6.12
- idna
- marshmallow>=3,<4
- more-itertools
- pluggy
- py
- pytest~=5.4.3
- pytest~=7.4.0
- pytest-cov~=2.10.0
- requests
- six
- sphinx~=3.4.0
- sphinx~=7.1.2
- sphinx-rtd-theme
- m2r2
- urllib3
Expand Down
2 changes: 1 addition & 1 deletion objectfactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# do imports
from .serializable import Serializable
from .factory import Factory, register, create
from .field import Field, Nested, List, Integer, String, Boolean, Float
from .field import Field, Nested, List, Integer, String, Boolean, Float, DateTime, Enum

__version__ = '0.1.0'
94 changes: 81 additions & 13 deletions objectfactory/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __set__(self, instance, value):
setattr(instance, self._attr_key, value)

def marshmallow(self):
return marshmallow.fields.Field(
return marshmallow.fields.Raw(
data_key=self._key,
required=self._required,
allow_none=self._allow_none
Expand Down Expand Up @@ -93,18 +93,86 @@ def marshmallow(self):
)


class DateTime(Field):
"""
serializable field for datetime data
"""

def __init__(
self,
default=None,
key=None,
date_format=None,
required=False,
allow_none=True
):
"""
:param default: default value for field if unset
:param key: dictionary key to use for field serialization
:param date_format: date format to use (defaults to iso)
:param required: whether this field is required to deserialize an object
:param allow_none: whether null should be considered a valid value
"""
super().__init__(default=default, key=key, required=required, allow_none=allow_none)
self._date_format = date_format

def marshmallow(self):
return marshmallow.fields.DateTime(
data_key=self._key,
required=self._required,
allow_none=self._allow_none,
format=self._date_format
)


class Enum(Field):
"""
serializable field for enumerated data
"""

def __init__(
self,
enum,
default=None,
key=None,
required=False,
allow_none=True,
by_value=False,
):
"""
:param enum: enum type for field validation
:param default: default value for field if unset
:param key: dictionary key to use for field serialization
:param required: whether this field is required to deserialize an object
:param allow_none: whether null should be considered a valid value
:param by_value: whether to serialize by value or by symbol
"""
super().__init__(default=default, key=key, required=required, allow_none=allow_none)
self._enum = enum
self._by_value = by_value

def marshmallow(self):
return marshmallow.fields.Enum(
self._enum,
data_key=self._key,
required=self._required,
allow_none=self._allow_none,
by_value=self._by_value
)


class Nested(Field):
"""
field type for nested serializable object
"""

def __init__(
self,
default=None,
key=None,
field_type=None,
required=False,
allow_none=True
self,
default=None,
key=None,
field_type=None,
required=False,
allow_none=True
):
"""
:param default: default value for field if unset
Expand All @@ -131,12 +199,12 @@ class List(Field):
"""

def __init__(
self,
default=None,
key=None,
field_type=None,
required=False,
allow_none=True
self,
default=None,
key=None,
field_type=None,
required=False,
allow_none=True
):
"""
:param default: default value for field if unset
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='objectfactory',
version='0.1.1',
version='0.2.0',
author='Devin A. Conley',
author_email='[email protected]',
description='objectfactory is a python package to easily implement the factory design pattern for object creation, serialization, and polymorphism',
Expand Down
2 changes: 1 addition & 1 deletion test/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_definition(self):
"""
test definition of class with boolean field

expect field to to be collected, registered, and included
expect field to be collected, registered, and included
in schema creation
"""

Expand Down
Loading