Skip to content

Commit

Permalink
Release v2.0.0
Browse files Browse the repository at this point in the history
This commit does quite a bit:
- No more legacy Python (aka Python 2) support!
- Also no more support for Python 3.2, 3.3, 3.4, 3.5 and PyPy2.7
- Type hints!
- Major version bump
- Documentation updates (README, CHANGELOG)
  • Loading branch information
nkantar committed Feb 12, 2018
1 parent 5ae2067 commit 1b20b7b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 54 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev"
- "3.6"
- "3.6-dev"
- "3.7-dev"
- "nightly"
- "pypy"
- "pypy3"
script: python tests.py
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Parsenvy Changelog


## [2.0.0] - 2018-02-11

### Added
- Type hints!

### Removed
- Python 2 support!
- Also support for Python 3.2, 3.3, 3.4, 3.5 and PyPy2.7


## [1.0.2] - 2018-02-11

### Changed
Expand Down Expand Up @@ -51,7 +61,8 @@
- Basic functionality


[Unreleased]: https://github.com/nkantar/Parsenvy/compare/1.0.2...HEAD
[Unreleased]: https://github.com/nkantar/Parsenvy/compare/2.0.0...HEAD
[2.0.0]: https://github.com/nkantar/Parsenvy/compare/1.0.2...2.0.0
[1.0.2]: https://github.com/nkantar/Parsenvy/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/nkantar/Parsenvy/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/nkantar/Parsenvy/compare/0.1.2...1.0.0
Expand Down
12 changes: 5 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ Environment variables are strings by default. This can be *rather* inconvenient
.. image:: https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg
:target: https://saythanks.io/to/nkantar


Features
--------

- Compatible with both Python 2 and 3
- No dependencies aside from Python's core ``os`` and ``builtins``/``__builtin__`` modules
- Compatible with Python 3.6+ only (the last Python 2 compatible version was `1.0.2 <https://github.com/nkantar/Parsenvy/releases/tag/1.0.2>`_)
- No dependencies aside from Python's core ``builtins``, ``os``, and ``typing`` modules
- Fully tested
- BSD (3-Clause) licensed

TODO
----

- Type-annotated
- Thoroughly documented

Examples
--------
Expand All @@ -47,13 +43,15 @@ Examples
>>> parsenvy.dict('DICT_ENV_VAR') # DICT_ENV_VAR=a:1,b:2
{'a': '1', 'b': '2'}
Install
-------

.. code-block:: shell
pip install parsenvy
Contributing
------------

Expand Down
80 changes: 44 additions & 36 deletions parsenvy/parsenvy.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import builtins
import os
from typing import Any, List, Union

# Python 3 isn't just the future - it's the present
try:
import builtins
# but that doesn't mean we can't be *a little* backwards compatible
except ImportError:
import __builtin__ as builtins


def _env_var(key):
def _env_var(key: builtins.str) -> builtins.str:
try:
return os.environ[key]
except KeyError:
return None


def bool(arg, default=None):
var = _env_var(arg)
trues = ['true', '1']
falses = ['false', '0']
def bool(arg: builtins.str, default: builtins.bool=None) -> builtins.bool:
var: builtins.str = _env_var(arg)
trues: List[builtins.str] = ['true', '1']
falses: List[builtins.str] = ['false', '0']

if var is not None:
if builtins.str(var).lower() in trues:
Expand All @@ -31,8 +26,8 @@ def bool(arg, default=None):
return default


def int(arg, default=None):
var = _env_var(arg)
def int(arg: builtins.str, default: builtins.int=None) -> builtins.int:
var: builtins.str = _env_var(arg)

if var is not None:
try:
Expand All @@ -43,8 +38,8 @@ def int(arg, default=None):
return default


def float(arg, default=None):
var = _env_var(arg)
def float(arg: builtins.str, default: builtins.float=None) -> builtins.float:
var: builtins.str = _env_var(arg)

if var is not None:
try:
Expand All @@ -55,54 +50,67 @@ def float(arg, default=None):
return default


def list(arg, default=None):
var = _env_var(arg)
def list(arg: builtins.str,
default: Union[builtins.list,
builtins.tuple,
builtins.set]=None) -> builtins.list:
var: builtins.str = _env_var(arg)

if var is not None and var != '':
return var.split(',')
else:
return default
try:
return builtins.list(default)
except TypeError:
return None


def tuple(arg, default=None):
val_list = list(arg, default=default)
def tuple(arg: builtins.str, default: builtins.tuple=None) -> builtins.tuple:
val_list: List[Any] = list(arg, default=default)

if val_list is not None:
return builtins.tuple(val_list)
else:
return default
try:
return default
except TypeError:
return None


def str(arg, default=None):
var = _env_var(arg)
def str(arg: builtins.str, default: builtins.str=None) -> builtins.str:
var: builtins.str = _env_var(arg)

if var is not None:
return var
else:
return default


def set(arg, default=None):
val_list = list(arg, default=default)
def set(arg: builtins.str, default: builtins.set=None) -> builtins.set:
val_list: builtins.list = list(arg, default=default)

if val_list is not None:
return builtins.set(val_list)
else:
return default
try:
return default
except TypeError:
return None


def dict(arg, default=None):
var = _env_var(arg)
def dict(arg: builtins.str, default: builtins.dict=None) -> builtins.dict:
var: builtins.str = _env_var(arg)

if var is not None:
try:
pair_list = var.split(',')
element_lists = [pair.split(':')
for pair
in pair_list]
all_elements = []
[all_elements.extend(pair) for pair in element_lists]
final_dict = {}
pair_list: builtins.list = var.split(',')
element_lists: builtins.list = [pair.split(':')
for pair
in pair_list]
all_elements: builtins.list = []
for pair in element_lists:
all_elements.extend(pair)
final_dict: builtins.dict = {}
for index, key in enumerate(all_elements):
if index % 2 == 0:
final_dict.update({key: all_elements[index + 1]})
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

setup(name = 'parsenvy',
packages = ['parsenvy'],
version = '1.0.2',
version = '2.0.0',
description = 'Enviously elegant environment variable parsing',
author = 'Nik Kantar',
author_email = '[email protected]',
url = 'https://github.com/nkantar/Parsenvy',
download_url = 'https://github.com/nkantar/Parsenvy/tarball/1.0.2',
download_url = 'https://github.com/nkantar/Parsenvy/tarball/2.0.0',
keywords = ['environment variables'],
classifiers = [],
license = 'BSD-3-Clause',
Expand Down

0 comments on commit 1b20b7b

Please sign in to comment.