Skip to content

Commit

Permalink
v1.1.4 :octocat:
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Nov 8, 2020
1 parent e1d5cd4 commit d3faba7
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 130 deletions.
115 changes: 72 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Build

on:
release:
types: [published]
push:
branches:
- master
- ci
pull_request:
branches:
- '*'
- "*"

env:
PROJECT_NAME: essentials
Expand All @@ -17,56 +19,83 @@ jobs:
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 9
submodules: false
- uses: actions/checkout@v1
with:
fetch-depth: 9
submodules: false

- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v1
id: depcache
with:
path: deps
key: requirements-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
- uses: actions/cache@v1
id: depcache
with:
path: deps
key: requirements-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}

- name: Download dependencies
if: steps.depcache.outputs.cache-hit != 'true'
run: |
pip download --dest=deps -r requirements.txt
- name: Download dependencies
if: steps.depcache.outputs.cache-hit != 'true'
run: |
pip download --dest=deps -r requirements.txt
- name: Install dependencies
run: |
pip install -U --no-index --find-links=deps deps/*
- name: Install dependencies
run: |
pip install -U --no-index --find-links=deps deps/*
- name: Run tests
run: |
flake8 && pytest --doctest-modules --junitxml=junit/pytest-results-${{ matrix.python-version }}.xml --cov=$PROJECT_NAME --cov-report=xml tests/
- name: Run tests
run: |
flake8 && pytest --doctest-modules --junitxml=junit/pytest-results-${{ matrix.python-version }}.xml --cov=$PROJECT_NAME --cov-report=xml tests/
- name: Upload pytest test results
uses: actions/upload-artifact@master
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/pytest-results-${{ matrix.python-version }}.xml
if: always()
- name: Upload pytest test results
uses: actions/upload-artifact@master
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/pytest-results-${{ matrix.python-version }}.xml
if: always()

- name: Install distribution dependencies
run: pip install --upgrade twine setuptools wheel
if: matrix.python-version == 3.8
- name: Codecov
run: |
bash <(curl -s https://codecov.io/bash)
- name: Create distribution package
run: python setup.py sdist bdist_wheel
if: matrix.python-version == 3.8
- name: Install distribution dependencies
run: pip install --upgrade twine setuptools wheel
if: matrix.python-version == 3.8 || matrix.python-version == 3.9

- name: Upload distribution package
uses: actions/upload-artifact@master
with:
name: dist-package-${{ matrix.python-version }}
path: dist
if: matrix.python-version == 3.8
- name: Create distribution package
run: python setup.py sdist bdist_wheel
if: matrix.python-version == 3.8 || matrix.python-version == 3.9

- name: Upload distribution package
uses: actions/upload-artifact@master
with:
name: dist-package-${{ matrix.python-version }}
path: dist
if: matrix.python-version == 3.8 || matrix.python-version == 3.9

publish:
runs-on: ubuntu-18.04
needs: build
if: github.event_name == 'release'
steps:
- name: Download a distribution artifact
uses: actions/download-artifact@v2
with:
name: dist-package-3.9
path: dist
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
skip_existing: true
user: __token__
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.4] - 2020-11-08 :octocat:
- Completely migrates to GitHub Workflows
- Improves build to test Python 3.6 and 3.9
- Improves the `json.FriendlyEncoder` class to handle built-in `dataclasses`
- Adds a changelog
- Improves badges
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[![Build Status](https://dev.azure.com/robertoprevato/Nest/_apis/build/status/RobertoPrevato.essentials?branchName=master)](https://dev.azure.com/robertoprevato/Nest/_build/latest?definitionId=28&branchName=master) [![pypi](https://img.shields.io/pypi/v/essentials.svg?color=blue)](https://pypi.org/project/essentials/) [![Test coverage](https://img.shields.io/azure-devops/coverage/robertoprevato/Nest/28.svg)](https://dev.azure.com/robertoprevato/Nest/_build?definitionId=28)
![Build](https://github.com/RobertoPrevato/essentials/workflows/Build/badge.svg)
[![pypi](https://img.shields.io/pypi/v/essentials.svg)](https://pypi.python.org/pypi/essentials)
[![versions](https://img.shields.io/pypi/pyversions/essentials.svg)](https://github.com/RobertoPrevato/essentials)
[![license](https://img.shields.io/github/license/RobertoPrevato/essentials.svg)](https://github.com/RobertoPrevato/essentials/blob/master/LICENSE)

# Essentials
Core classes and functions, reusable in any kind of Python application.
Expand Down
47 changes: 0 additions & 47 deletions azure-pipelines.yml

This file was deleted.

12 changes: 5 additions & 7 deletions essentials/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
This module defines a user-friendly json encoder,
supporting time objects, UUID and bytes.
"""
import json
import base64
import dataclasses
import json
from datetime import date, datetime, time
from enum import Enum
from datetime import time, date, datetime
from uuid import UUID


__all__ = ["FriendlyEncoder", "dumps"]


# TODO: use singledispatch to make the friendly encoder expandable


class FriendlyEncoder(json.JSONEncoder):
def default(self, obj):
try:
return json.JSONEncoder.default(self, obj)
except TypeError:

if hasattr(obj, "dict"):
return obj.dict()
if isinstance(obj, time):
Expand All @@ -35,6 +31,8 @@ def default(self, obj):
return str(obj)
if isinstance(obj, Enum):
return obj.value
if dataclasses.is_dataclass(obj):
return dataclasses.asdict(obj)
raise


Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pytest
pytest-cov
pytest-asyncio
flake8
mypy
black
dataclasses==0.7;python_version<'3.7'
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ def readme():

setup(
name="essentials",
version="1.1.3",
version="1.1.4",
description="General purpose classes and functions, "
"reusable in any kind of Python application",
"reusable in any kind of Python application",
long_description=readme(),
long_description_content_type="text/markdown",
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Operating System :: OS Independent",
],
url="https://github.com/RobertoPrevato/essentials",
author="RobertoPrevato",
author_email="roberto.prevato@gmail.com",
keywords="core utilities",
license="MIT",
packages=[
"essentials",
"essentials.typesutils",
"essentials.decorators",
],
install_requires=[],
packages=["essentials", "essentials.typesutils", "essentials.decorators"],
install_requires=["dataclasses==0.7;python_version<'3.7'"],
include_package_data=True,
)
30 changes: 23 additions & 7 deletions tests/test_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from uuid import UUID, uuid4
from dataclasses import dataclass
from datetime import date, datetime, time
from enum import Enum, Flag, IntEnum, IntFlag, auto

Expand All @@ -8,8 +9,13 @@
from essentials.json import dumps


class Fruit(Enum):
@dataclass
class Foo:
id: UUID
name: str


class Fruit(Enum):
ANANAS = "ananas"
BANANA = "banana"
MANGO = "mango"
Expand Down Expand Up @@ -42,7 +48,7 @@ class Permission(IntFlag):
({"value": date(2016, 3, 26)}, '{"value": "2016-03-26"}'),
({"value": datetime(2016, 3, 26, 3, 0, 0)}, '{"value": "2016-03-26T03:00:00"}'),
(
{"value": uuid.UUID("e56fddfc-f85b-4178-869f-a218278a639e")},
{"value": UUID("e56fddfc-f85b-4178-869f-a218278a639e")},
'{"value": "e56fddfc-f85b-4178-869f-a218278a639e"}',
),
(
Expand Down Expand Up @@ -85,7 +91,6 @@ def __init__(self, x, y):


def test_enum_to_json():

value = dumps(
{
"fruit": Fruit.MANGO,
Expand All @@ -98,15 +103,13 @@ def test_enum_to_json():


def test_int_enum_to_json():

value = dumps({"power": Power.GREAT, "powers": [Power.MILD, Power.MODERATE]})

assert '"power": 3' in value
assert '"powers": [1, 2]' in value


def test_intflag_enum_to_json():

value = dumps(
{
"permission_one": Permission.R,
Expand All @@ -119,7 +122,6 @@ def test_intflag_enum_to_json():


def test_flag_enum_to_json():

value = dumps(
{
"color_one": Color.GREEN,
Expand All @@ -129,3 +131,17 @@ def test_flag_enum_to_json():
)

assert '{"color_one": 4, "color_two": 5, "color_three": 7}' == value


def test_serialize_dataclass():
foo_id = uuid4()
value = dumps(Foo(foo_id, "foo"))

assert f'{{"id": "{foo_id}", "name": "foo"}}' == value


def test_serialize_dataclass_no_spaces():
foo_id = uuid4()
value = dumps(Foo(foo_id, "foo"), separators=(",", ":"))

assert f'{{"id":"{foo_id}","name":"foo"}}' == value
3 changes: 1 addition & 2 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pytest import raises

from essentials.exceptions import InvalidArgument
from essentials.registry import (AmbiguousRegistryName, Registry,
TypeNotFoundException)
from essentials.registry import AmbiguousRegistryName, Registry, TypeNotFoundException


def test_registry_type():
Expand Down
Loading

0 comments on commit d3faba7

Please sign in to comment.