Skip to content

Commit

Permalink
Make sure click_params works with click 8.X (#3)
Browse files Browse the repository at this point in the history
* fix: fix various issues introduced by click 8.X

* tests(nox): add pypy3 to the list of python versions to run tests against

* ci: removed travis configuration file

* docs: update project version and changelog files

* docs: improved documentation

installed package mkdocs-material to use the material design

Co-authored-by: le_woudar <rollandkev@yahoo.fr>
  • Loading branch information
lewoudar committed May 16, 2021
1 parent 6bfd684 commit 5dcd414
Show file tree
Hide file tree
Showing 18 changed files with 939 additions and 373 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
timeout-minutes: 20
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 6
matrix:
os: [ 'ubuntu-latest', 'macos-latest' ,'windows-latest' ]
python: [ pypy3, 3.6, 3.7, 3.8, 3.9 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install python dependencies
run: python -m pip install -U pip nox
- name: Lint
run: nox -s lint
if: matrix.os == 'ubuntu-latest' && matrix.python == '3.9'
- name: Tests
run: nox -s tests-${{ matrix.python }}
env:
CODECOV_TOKEN: ${{ secrets.codecov_token }}
- name: Build and deploy
run: nox -s deploy
if: >
github.event_name == 'push' && contains(github.ref, 'refs/tags/') &&
matrix.os == 'ubuntu-latest' && matrix.python == '3.9'
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.pypi_token }}
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
.coverage
htmlcov
.nox
coverage.xml

# byte-compiled / optimized
__pycache__
Expand Down
7 changes: 2 additions & 5 deletions .readthedocs.yml
Expand Up @@ -3,9 +3,6 @@ version: 2
mkdocs:
configuration: mkdocs.yml

formats: all # html zip, epub and pdf

python:
# To date mkdocs (0.17.3 used by readthedocs) failed with python3.7, so we tell readthedocs to use python3.6
# for documentation building.
version: 3.6
install:
- requirements: docs/requirements.txt
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

26 changes: 20 additions & 6 deletions CHANGELOG.md
@@ -1,15 +1,29 @@
# Changelog

## Version 0.1.1
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).

Released on 2020-01-06
## [Unreleased]

## [0.1.2] - 2021-05-16

### Changed

- Updated code to be compatible with Click 8.X

## [0.1.1] - 2020-01-06

### Added
- Added usage of nox package for test automation.
- Changed .travis.yml and appveyor.yml to take in account nox.
- Replaced pipenv by poetry to better manage package dependencies.
- Added poetry package to better manage package dependencies

## Version 0.1.0
### Changed
- Changed .travis.yml and appveyor.yml to take in account nox.

### Removed
- Removed pipenv in favor of poetry.

Released on 2019-07-21
## [0.1.0] - 2019-07-21

### Added
- First release of the package.
3 changes: 1 addition & 2 deletions README.md
@@ -1,8 +1,7 @@
# click-params

[![Pypi version](https://img.shields.io/pypi/v/click-params.svg)](https://pypi.org/project/click-params/)
[![Build Status](https://travis-ci.com/click-contrib/click_params.svg?branch=master)](https://travis-ci.com/click-contrib/click_params)
[![Windows Build Status](https://img.shields.io/appveyor/ci/lewoudar/click-params/master.svg?label=Windows)](https://ci.appveyor.com/project/lewoudar/click-params)
![](https://github.com/click-contrib/click_params/workflows/CI/badge.svg)
[![Coverage Status](https://codecov.io/gh/click-contrib/click_params/branch/master/graphs/badge.svg?branch=master)](https://codecov.io/gh/click-contrib/click_params)
[![Documentation Status](https://readthedocs.org/projects/click_params/badge/?version=latest)](https://click-params.readthedocs.io/en/latest/?badge=latest)
[![License Apache 2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
Expand Down
23 changes: 0 additions & 23 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion click_params/__init__.py
@@ -1,4 +1,4 @@
__version__ = '0.1.1'
__version__ = '0.1.2'

from .base import BaseParamType, ValidatorParamType, RangeParamType, ListParamType
from .domain import (
Expand Down
15 changes: 10 additions & 5 deletions click_params/base.py
@@ -1,12 +1,17 @@
"""Base classes to implement various parameter types"""
from typing import Union, Tuple, Callable, List, Any
from typing import Union, Tuple, Callable, List, Any, Optional

import click

from .annotations import Min, Max, Error


class BaseParamType(click.ParamType):
class CustomParamType(click.ParamType):
# in click 8, name does not exist, it is just a type annotation, so to not break code, I need this hack
name: Optional[str] = None


class BaseParamType(CustomParamType):
def __init__(self, _type: Any, errors: Union[Error, Tuple[Error]], name: str = None):
self._type = _type
self._errors = errors
Expand All @@ -23,7 +28,7 @@ def __repr__(self):
return self.name.upper()


class ValidatorParamType(click.ParamType):
class ValidatorParamType(CustomParamType):
"""This class is intended to be inherit by classes using validators functions."""

def __init__(self, callback: Callable, name: str = None):
Expand All @@ -40,7 +45,7 @@ def __repr__(self):
return self.name.upper()


class RangeParamType(click.ParamType):
class RangeParamType(CustomParamType):

def __init__(self, param_type: click.ParamType, minimum: Min = None, maximum: Max = None, clamp: bool = False):
self._minimum = minimum
Expand Down Expand Up @@ -76,7 +81,7 @@ def __repr__(self):
return f'{new_name}({repr(self._minimum)}, {repr(self._maximum)})'


class ListParamType(click.ParamType):
class ListParamType(CustomParamType):

def __init__(self, param_type: click.ParamType, separator: str = ',', name: str = None):
if not isinstance(separator, str):
Expand Down
26 changes: 20 additions & 6 deletions docs/changelog.md
@@ -1,15 +1,29 @@
# Changelog

## Version 0.1.1
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).

Released on 2020-01-06
## [Unreleased]

## [0.1.2] - 2021-05-16

### Changed

- Updated code to be compatible with Click 8.X

## [0.1.1] - 2020-01-06

### Added
- Added usage of nox package for test automation.
- Changed .travis.yml and appveyor.yml to take in account nox.
- Replaced pipenv by poetry to better manage package dependencies.
- Added poetry package to better manage package dependencies

## Version 0.1.0
### Changed
- Changed .travis.yml and appveyor.yml to take in account nox.

### Removed
- Removed pipenv in favor of poetry.

Released on 2019-07-21
## [0.1.0] - 2019-07-21

### Added
- First release of the package.
14 changes: 1 addition & 13 deletions docs/index.md
Expand Up @@ -4,7 +4,7 @@ Everything you need to know about click-params.

## Why?

I often find myself wanting to use a click parameter able to handle list of strings, so I decide to put this in a library
I often find myself wanting to use a click parameter able to handle list of strings, so I decide to put this in a library,
and I ended adding more parameter types that can be useful for various scripts including network, mathematics and so on.

## Features
Expand All @@ -15,15 +15,3 @@ With this project you have click parameter types related to:
- network
- domain, url
- json, etc..

## Contents

- [Installation](installation.md)
- Usage
- [domain](usage/domain.md)
- [network](usage/network.md)
- [numeric](usage/numeric.md)
- [miscellaneous](usage/miscellaneous.md)
- [Tests](tests.md)
- [API](api.md)
- [Changelog](changelog.md)
3 changes: 3 additions & 0 deletions docs/requirements.txt
@@ -0,0 +1,3 @@
click==8.0.0
validators==0.18.2
mkdocs-material==7.1.4
9 changes: 6 additions & 3 deletions mkdocs.yml
Expand Up @@ -6,7 +6,10 @@ site_url: https://click-params.readthedocs.io
repo_url: https://github.com/click-contrib/click_params/
edit_uri: tree/master/docs

pages:
theme:
name: material

nav:
- Home: index.md
- Installation: installation.md
- Usage:
Expand All @@ -18,9 +21,9 @@ pages:
- API: api.md
- Changelog: changelog.md

theme: readthedocs

markdown_extensions:
- toc:
permalink: true
- admonition
- codehilite:
css_class: highlight
17 changes: 5 additions & 12 deletions noxfile.py
Expand Up @@ -5,14 +5,15 @@

nox.options.reuse_existing_virtualenvs = True

PYTHON_VERSIONS = ['3.6', '3.7', '3.8']
PYTHON_VERSIONS = ['pypy3', '3.6', '3.7', '3.8', '3.9', 'pypy3']
CI_ENVIRONMENT = 'GITHUB_ACTIONS' in os.environ


@nox.session(python=PYTHON_VERSIONS[-1])
def lint(session):
"""Performs pep8 and security checks."""
source_code = 'click_params'
session.install('flake8==3.7.9', 'bandit==1.6.2')
session.install('flake8==3.9.2', 'bandit==1.7.0')
session.run('flake8', source_code)
session.run('bandit', '-r', source_code)

Expand All @@ -25,16 +26,8 @@ def tests(session):
session.run('pytest')

# we notify codecov when the latest version of python is used
if session.python == PYTHON_VERSIONS[-1] and 'APPVEYOR_URL' not in os.environ:
session.notify('codecov')


@nox.session
def codecov(session):
"""Runs codecov command to share coverage information on codecov.io"""
session.install('codecov==2.0.15')
session.run('coverage', 'xml', '-i')
session.run('codecov', '-f', 'coverage.xml')
if session.python == PYTHON_VERSIONS[-1] and CI_ENVIRONMENT:
session.run('codecov', '-f', 'coverage.xml')


@nox.session(python=PYTHON_VERSIONS[-1])
Expand Down

0 comments on commit 5dcd414

Please sign in to comment.