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
37 changes: 17 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,47 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.25"
python-version: '3.11'
cache: 'pip'
- run: pip install "pre-commit<4.0.0"
- run: pre-commit --version
- run: pre-commit install
- run: pre-commit run --all-files
- run: uvx pre-commit --version
- run: uvx pre-commit run --all-files

build:
needs: [linting]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.25"
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install base dependencies
run: poetry install

- name: Install the project (no extras)
run: uv sync

- name: Unit tests with Pytest (no extras)
timeout-minutes: 3
run: |
poetry run pytest --benchmark-disable --cov=simple_parsing --cov-report=xml --cov-append

uv run pytest --benchmark-disable --cov=simple_parsing --cov-report=xml --cov-append

- name: Install extra dependencies
run: poetry install --all-extras
run: uv sync --all-extras

- name: Unit tests with Pytest (with extra dependencies)
timeout-minutes: 3
run: |
poetry run pytest --benchmark-disable --cov=simple_parsing --cov-report=xml --cov-append
uv run pytest --benchmark-disable --cov=simple_parsing --cov-report=xml --cov-append

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ jobs:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.25"
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install dependencies
run: |
poetry install
poetry self add "poetry-dynamic-versioning[plugin]"
poetry dynamic-versioning enable
uv sync

- name: Publish package
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish --build
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
uv build
uv publish
16 changes: 5 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
Expand Down Expand Up @@ -32,21 +32,21 @@ repos:
hooks:
# Run the linter.
- id: ruff
args: ['--line-length', '99', "--select", "I,UP", '--fix']
require_serial: true
args: ["--fix"]
# Run the formatter.
- id: ruff-format
args: ['--line-length', '99']
require_serial: true

# python docstring formatting
- repo: https://github.com/myint/docformatter
rev: v1.5.1
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38 # Don't autoupdate until https://github.com/PyCQA/docformatter/issues/293 is fixed
hooks:
- id: docformatter
exclude: ^test/test_docstrings.py
args: [--in-place, --wrap-summaries=99, --wrap-descriptions=99]
require_serial: true
additional_dependencies: [tomli]


# NOTE: Disabling this, since I'm having the glib-c2.29 weird bug.
# # yaml formatting
Expand Down Expand Up @@ -79,12 +79,6 @@ repos:
# - mdformat-black
require_serial: true

- repo: https://github.com/python-poetry/poetry
rev: 1.7.0
hooks:
- id: poetry-check
require_serial: true

# word spelling linter
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
Expand Down
1 change: 1 addition & 0 deletions examples/config_files/one_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example adapted from https://github.com/eladrich/pyrallis#my-first-pyrallis-example-"""

from dataclasses import dataclass

import simple_parsing
Expand Down
7 changes: 3 additions & 4 deletions examples/container_types/lists_example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from dataclasses import dataclass, field
from typing import List

from simple_parsing import ArgumentParser
from simple_parsing.helpers import list_field


@dataclass
class Example:
some_integers: List[int] = field(
some_integers: list[int] = field(
default_factory=list
) # This is a list of integers (empty by default)
"""This list is empty, by default.
Expand All @@ -19,9 +18,9 @@ class Example:
# When using a list attribute, the dataclasses module requires us to use `dataclass.field()`,
# so each instance of this class has a different list, rather than them sharing the same list.
# To simplify this, you can use `MutableField(value)` which is just a shortcut for `field(default_factory=lambda: value)`.
some_floats: List[float] = list_field(3.14, 2.56)
some_floats: list[float] = list_field(3.14, 2.56)

some_list_of_strings: List[str] = list_field("default_1", "default_2")
some_list_of_strings: list[str] = list_field("default_1", "default_2")
"""This list has a default value of ["default_1", "default_2"]."""


Expand Down
3 changes: 1 addition & 2 deletions examples/custom_args/custom_args_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Example of overwriting auto-generated argparse options with custom ones."""

from dataclasses import dataclass
from typing import List

from simple_parsing import ArgumentParser, field
from simple_parsing.helpers import list_field
Expand All @@ -21,7 +20,7 @@ def parse(cls, args: str = ""):
@dataclass
class Example1:
# A list of animals to take on a walk. (can only be passed 'cat' or 'dog')
pets_to_walk: List[str] = list_field(default=["dog"], choices=["cat", "dog"])
pets_to_walk: list[str] = list_field(default=["dog"], choices=["cat", "dog"])


# passing no arguments uses the default values:
Expand Down
4 changes: 2 additions & 2 deletions examples/docstrings/docstrings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class DocStringsExample:

# comment above 42
attribute4: float = 1.0 # inline comment
"""docstring below (this appears in --help)"""
"""Docstring below (this appears in --help)"""

# comment above (this appears in --help) 46
attribute5: float = 1.0 # inline comment

attribute6: float = 1.0 # inline comment (this appears in --help)

attribute7: float = 1.0 # inline comment
"""docstring below (this appears in --help)"""
"""Docstring below (this appears in --help)"""


parser.add_arguments(DocStringsExample, "example")
Expand Down
3 changes: 1 addition & 2 deletions examples/inheritance/ml_inheritance_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass, field
from typing import List

from simple_parsing import ArgumentParser, choice
from simple_parsing.helpers import Serializable, list_field
Expand All @@ -12,7 +11,7 @@ class ConvBlock(Serializable):
"""A Block of Conv Layers."""

n_layers: int = 4 # number of layers
n_filters: List[int] = list_field(16, 32, 64, 64) # filters per layer
n_filters: list[int] = list_field(16, 32, 64, 64) # filters per layer


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion examples/merging/multiple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Config:
run_name: str = "train" # Some parameter for the run name.
some_int: int = 10 # an optional int parameter.
log_dir: str = "logs" # an optional string parameter.
"""the logging directory to use.
"""The logging directory to use.

(This is an attribute docstring for the log_dir attribute, and shows up when using the "--help"
argument!)
Expand Down
5 changes: 2 additions & 3 deletions examples/merging/multiple_lists_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

from dataclasses import dataclass, field
from typing import List, Tuple

from simple_parsing import ArgumentParser, ConflictResolution

Expand All @@ -21,8 +20,8 @@
class CNNStack:
name: str = "stack"
num_layers: int = 3
kernel_sizes: Tuple[int, int, int] = (7, 5, 5)
num_filters: List[int] = field(default_factory=[32, 64, 64].copy)
kernel_sizes: tuple[int, int, int] = (7, 5, 5)
num_filters: list[int] = field(default_factory=[32, 64, 64].copy)


parser = ArgumentParser(conflict_resolution=ConflictResolution.ALWAYS_MERGE)
Expand Down
3 changes: 1 addition & 2 deletions examples/serialization/custom_types_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Cleaning up
import os
from dataclasses import dataclass
from typing import List

import torch
from torch import Tensor
Expand All @@ -26,7 +25,7 @@ class Student(Person):


@encode.register
def encode_tensor(obj: Tensor) -> List:
def encode_tensor(obj: Tensor) -> list:
"""We choose to encode a tensor as a list, for instance."""
return obj.tolist()

Expand Down
14 changes: 7 additions & 7 deletions examples/ugly/ugly_example_after.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# import torch.backends.cudnn as cudnn
# import torch.utils.data
from dataclasses import dataclass, field
from typing import ClassVar, Optional, Tuple
from typing import ClassVar, Optional

import simple_parsing
from simple_parsing import choice
Expand Down Expand Up @@ -147,22 +147,22 @@ class OtherParams:
class CameraParams:
"""Camera Parameters."""

cam_pos: Tuple[float, float, float] = (0.0, 0.0, 0.0) # Camera position.
cam_pos: tuple[float, float, float] = (0.0, 0.0, 0.0) # Camera position.
width: int = 128
height: int = 128
cam_dist: float = 3.0 # Camera distance from the center of the object
nv: int = 10 # Number of views to generate
angle: int = 30 # cam angle
fovy: float = 30 # Field of view in the vertical direction.
focal_length: float = 0.1 # focal length
theta: Tuple[float, float] = (20, 80) # Angle in degrees from the z-axis.
phi: Tuple[float, float] = (20, 70) # Angle in degrees from the x-axis.
axis: Tuple[float, float, float] = (
theta: tuple[float, float] = (20, 80) # Angle in degrees from the z-axis.
phi: tuple[float, float] = (20, 70) # Angle in degrees from the x-axis.
axis: tuple[float, float, float] = (
0.0,
1.0,
0.0,
) # Axis for random camera position.
at: Tuple[float, float, float] = (0.05, 0.0, 0.0) # Camera lookat position.
at: tuple[float, float, float] = (0.05, 0.0, 0.0) # Camera lookat position.
sphere_halfbox: bool = False # Renders demo sphere-halfbox
norm_depth_image_only: bool = False # Render on the normalized depth image.
mesh: bool = False # Render as mesh if enabled.
Expand All @@ -189,7 +189,7 @@ class RenderingParams:

@dataclass
class Parameters:
"""base options."""
"""Base options."""

# Dataset parameters.
dataset: DatasetParams = field(default_factory=DatasetParams)
Expand Down
2 changes: 1 addition & 1 deletion examples/ugly/ugly_example_before.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Parameters:
"""base options."""
"""Base options."""

def __init__(self):
"""Constructor."""
Expand Down
Loading