Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
feat: add network types
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeeeT committed Jan 12, 2023
1 parent a60d623 commit d61a69d
Show file tree
Hide file tree
Showing 128 changed files with 1,628 additions and 1,107 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Valtypes",
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"plugins": [
"zsh-autosuggestions zsh-syntax-highlighting"
],
"omzPlugins": [
"https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-syntax-highlighting"
]
},
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.isort",
"bungcip.better-toml",
"ryanluker.vscode-coverage-gutters"
]
}
},
"postCreateCommand": "poetry install"
}
23 changes: 23 additions & 0 deletions .github/workflows/build-dev-container-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build Dev Container image

on:
push:
branches: [ main ]

jobs:
build:
name: Build Dev Container image
runs-on: ubuntu-latest
steps:
- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
uses: devcontainers/ci@v0.2
with:
imageName: ghcr.io/${{ github.repository }}
cacheFrom: ghcr.io/${{ github.repository }}
push: always
195 changes: 30 additions & 165 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,185 +9,50 @@ on:
jobs:
flake8:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.11' ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Restore cache and venv
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache
.venv
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install Poetry
if: steps.cache.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-in-project: true
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install --with dev
- uses: actions/checkout@v3
- name: Run flake8
run: |
source .venv/bin/activate
pre-commit run --all-files flake8
uses: devcontainers/ci@v0.2
with:
cacheFrom: ghcr.io/${{ github.repository }}
runCmd: poetry run pre-commit run --all-files flake8

# mypy:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# python-version: [ '3.11' ]
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Setup Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# - name: Restore cache and venv
# id: cache
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache
# .venv
# key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
# - name: Restore mypy cache
# uses: actions/cache@v3
# with:
# path: .mypy_cache
# key: ${{ matrix.python-version }}
# - name: Install Poetry
# if: steps.cache.outputs.cache-hit != 'true'
# uses: snok/install-poetry@v1.3.3
# with:
# virtualenvs-in-project: true
# - name: Install dependencies
# if: steps.cache.outputs.cache-hit != 'true'
# run: poetry install --with dev
# - name: Run mypy
# run: |
# source .venv/bin/activate
# pre-commit run --all-files mypy
# mypy:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Run mypy
# uses: devcontainers/ci@v0.2
# with:
# cacheFrom: ghcr.io/${{ github.repository }}
# runCmd: poetry run pre-commit run --all-files mypy

pyright:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.11' ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Restore cache and venv
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache
.venv
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install Poetry
if: steps.cache.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-in-project: true
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install --with dev
- uses: actions/checkout@v3
- name: Run pyright
run: |
source .venv/bin/activate
pre-commit run --all-files pyright
uses: devcontainers/ci@v0.2
with:
cacheFrom: ghcr.io/${{ github.repository }}
runCmd: poetry run pre-commit run --all-files pyright

pyright-verify:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.11' ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Restore cache and venv
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache
.venv
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Install Poetry
if: steps.cache.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-in-project: true
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install --with dev
- uses: actions/checkout@v3
- name: Run pyright-verify
run: |
source .venv/bin/activate
pre-commit run --all-files pyright-verify
uses: devcontainers/ci@v0.2
with:
cacheFrom: ghcr.io/${{ github.repository }}
runCmd: poetry run pre-commit run --all-files pyright-verify

pytest:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ '3.11' ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Restore cache and venv
id: cache
uses: actions/cache@v3
with:
path: |
~/.cache
.venv
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Restore pytest cache
uses: actions/cache@v3
with:
path: .pytest_cache
key: pytest-${{ runner.os }}-${{ matrix.python-version }}
- name: Install Poetry
if: steps.cache.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1.3.3
- uses: actions/checkout@v3
- name: Run pytest
uses: devcontainers/ci@v0.2
with:
virtualenvs-in-project: true
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install --with dev
- name: Run pytest on Windows
if: runner.os == 'Windows'
run: |
source .venv/scripts/activate
pre-commit run --all-files pytest
- name: Run pytest on normal OS
if: runner.os != 'Windows'
run: |
source .venv/bin/activate
pre-commit run --all-files pytest
cacheFrom: ghcr.io/${{ github.repository }}
runCmd: poetry run pre-commit run --all-files pytest
16 changes: 5 additions & 11 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ jobs:
name: Publish release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Poetry
uses: snok/install-poetry@v1.3.3
with:
virtualenvs-create: false
- uses: actions/checkout@v3
- name: Build the package
run: poetry build
uses: devcontainers/ci@v0.2
with:
cacheFrom: ghcr.io/${{ github.repository }}
runCmd: poetry build
- name: Publish the package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
53 changes: 24 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,57 @@
ci:
autofix_commit_msg: 'refactor: auto fixes from pre-commit hooks'
autoupdate_commit_msg: 'build(deps): update pre-commit hooks'
skip: [ pyproject-flake8, pyright, pyright-verify, pytest ]

repos:
- repo: https://github.com/pycqa/isort
rev: 5.11.4
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort
language: system
pass_filenames: false
stages: [ commit ]

- repo: https://github.com/aio-libs/sort-all
rev: v1.2.0
hooks:
- id: sort-all
name: sort-all
entry: poetry run sort-all
language: system
stages: [ commit ]

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
name: black
entry: poetry run black .
language: system
pass_filenames: false
stages: [ commit ]

- repo: https://github.com/csachs/pyproject-flake8
rev: v6.0.0.post1
hooks:
- id: pyproject-flake8
- id: flake8
name: flake8
alias: flake8
entry: poetry run pflake8 valtypes tests testing
language: system
pass_filenames: false
stages: [ commit ]

- repo: local
hooks:
# - id: mypy
# name: mypy
# entry: bash -c "pip install poetry && poetry install --with mypy && mypy"
# language: system
# pass_filenames: false
# stages: [ commit ]
# - id: mypy
# name: mypy
# entry: poetry run mypy
# language: system
# pass_filenames: false
# stages: [ commit ]

- id: pyright
name: pyright
entry: bash -c "pip install poetry && poetry install --with pyright && pyright"
entry: poetry run pyright
language: system
pass_filenames: false
stages: [ commit ]

- id: pyright-verify
name: pyright-verify
entry: bash -c "pip install poetry && poetry install --with pyright-verify && pyright --verifytypes valtypes"
entry: poetry run pyright --verifytypes valtypes
language: system
pass_filenames: false
stages: [ commit ]

- id: pytest
name: pytest
entry: bash -c "pip install poetry && poetry install --with pytest && pytest"
entry: poetry run pytest
language: system
pass_filenames: false
stages: [ commit ]
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"terminal.integrated.defaultProfile.linux": "zsh",
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "strict",
"python.linting.enabled": false,
}
2 changes: 1 addition & 1 deletion docs/usage/constrained_types/float.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ from valtypes.type.float import Portion

Portion(0.) # passes
Portion(1.) # passes
Portion(-1.) # raises valtypes.error.parsing.type.numeric.Minimum
Portion(-.1) # raises valtypes.error.parsing.type.numeric.Minimum
Portion(1.1) # raises valtypes.error.parsing.type.numeric.Maximum
```
Loading

0 comments on commit d61a69d

Please sign in to comment.