Skip to content

Commit

Permalink
Move from poetry to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
breuleux committed Sep 12, 2024
1 parent 2e791ab commit cf2f7df
Show file tree
Hide file tree
Showing 11 changed files with 548 additions and 798 deletions.
78 changes: 48 additions & 30 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,59 @@ on:
branches: [ master ]

jobs:
build:

lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

python-version: ['3.12']
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Check out the code
uses: actions/checkout@v3
- name: Set up uv
uses: hynek/setup-cached-uv@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install -E toml -E yaml
- name: Lint with flake8
if: ${{ matrix.python-version == '3.10' }}
run: poetry run flake8

- name: Check formatting with black
if: ${{ matrix.python-version == '3.10' }}
run: poetry run black --check .

- name: Sort imports
if: ${{ matrix.python-version == '3.10' }}
run: poetry run isort -c --df .
cache-dependency-path: uv.lock
- name: Pin Python version
run: uv python pin ${{ matrix.python-version }}
- name: Sync dependencies
run: uv sync --all-extras
- name: Lint check
run: uvx ruff check
- name: Check formatting
run: uvx ruff format --check

test:
runs-on: ubuntu-latest
strategy:
matrix:
settings:
- python: '3.8'
coverage: false
- python: '3.9'
coverage: false
- python: '3.10'
coverage: false
- python: '3.11'
coverage: false
- python: '3.12'
coverage: true
steps:
- name: Check out the code
uses: actions/checkout@v3
- name: Set up uv
uses: hynek/setup-cached-uv@v2
with:
cache-dependency-path: uv.lock
- name: Pin Python version
run: uv python pin ${{ matrix.settings.python }}
- name: Sync dependencies
run: uv sync
- name: Test with pytest
run: poetry run pytest --cov=coleo --cov-report term-missing

if: ${{ !matrix.settings.coverage }}
run: uv run pytest tests/
- name: Test with pytest and coverage
if: ${{ matrix.settings.coverage }}
run: uv run pytest --cov=src --cov-report term-missing tests/
- name: Verify coverage
run: poetry run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
if: ${{ matrix.settings.coverage }}
run: uv run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
17 changes: 0 additions & 17 deletions coleo/__init__.py

This file was deleted.

646 changes: 0 additions & 646 deletions poetry.lock

This file was deleted.

62 changes: 31 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
[tool.poetry]
[project]
name = "coleo"
version = "0.3.3"
description = "The nicest way to develop a command-line interface"
authors = ["Olivier Breuleux <[email protected]>"]
authors = [
{ name = "Olivier Breuleux", email = "[email protected]" }
]
license = "MIT"
readme = "README.md"
repository = "https://github.com/breuleux/coleo"
requires-python = ">=3.8"
dependencies = [
"ptera~=1.4.1",
]

[tool.poetry.dependencies]
python = "^3.7"
ptera = "^1.4.1"
toml = {version = ">=0.10.0", optional = true}
pyyaml = {version = ">=5.3", optional = true}
[project.urls]
Homepage = "https://github.com/breuleux/coleo"
Repository = "https://github.com/breuleux/coleo"

[tool.poetry.dev-dependencies]
black = ">= 21.5b1"
pytest = ">= 7.2.0"
pytest-cov = ">= 2.8.1"
isort = ">= 5.8.0"
flake8 = ">= 3.9.2"
[project.optional-dependencies]
toml = [
"toml>=0.10.2",
]
yaml = [
"pyyaml>=6.0.2",
]

[tool.poetry.extras]
toml = ["toml"]
yaml = ["pyyaml"]

[tool.black]
line-length = 80
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.isort]
known_first_party = "coleo"
known_third_party = "ptera"
multi_line_output = 3
include_trailing_comma = true
combine_as_imports = true
[tool.uv]
dev-dependencies = [
"pytest>=8.3.3",
"pytest-cov>=5.0.0",
]

[tool.unimport]
exclude = ["**/__init__.py"]
[tool.ruff]
line-length = 90

[build-system]
requires = ["poetry-core@https://github.com/python-poetry/poetry-core/archive/325312c016d69189ac93c945ba0c1b69296c5e54.zip"]
build-backend = "poetry.core.masonry.api"
[tool.ruff.lint]
extend-select = ["I"]
ignore = ["F821", "F842"]
38 changes: 38 additions & 0 deletions src/coleo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from ptera import ABSENT, tag, tooled

from .cli import (
ArgsExpander,
Argument,
ConflictError,
Option,
auto_cli,
catalogue,
default,
make_cli,
run_cli,
setvars,
with_extras,
)
from .config import ConfigFile, config, register_extension
from .version import version

__all__ = [
"ABSENT",
"tag",
"tooled",
"ArgsExpander",
"Argument",
"ConflictError",
"Option",
"auto_cli",
"catalogue",
"default",
"make_cli",
"run_cli",
"setvars",
"with_extras",
"ConfigFile",
"config",
"register_extension",
"version",
]
29 changes: 8 additions & 21 deletions coleo/cli.py → src/coleo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def _generate_args_from_dict(self, contents):
if not isinstance(value, (list, tuple)):
value = [value]
for other_filename in value:
results.extend(
self._generate_args_from_file(other_filename)
)
results.extend(self._generate_args_from_file(other_filename))

elif key == "#command":
results.insert(0, value)
Expand Down Expand Up @@ -309,9 +307,7 @@ def _analyze_entry(self, name, data):
new_entry.append(line)
opts.doc.append("\n".join(new_entry))

opts.has_default_opt_name = (
(opts.aliases and opts.aliases[0] == default_opt),
)
opts.has_default_opt_name = ((opts.aliases and opts.aliases[0] == default_opt),)

for x in data.values():
x["coleo_options"] = opts
Expand All @@ -320,9 +316,7 @@ def _analyze_entry(self, name, data):
def _fill_argparser(self):
groups = {}

entries = [
self._analyze_entry(name, data) for name, data in self.names.items()
]
entries = [self._analyze_entry(name, data) for name, data in self.names.items()]

positional = list(
sorted(
Expand All @@ -333,17 +327,14 @@ def _fill_argparser(self):
if len(positional) > 1:
if any(entry.loc is None for entry in positional):
raise Exception(
"Positional arguments cannot be defined in multiple"
" functions."
"Positional arguments cannot be defined in multiple" " functions."
)
loc0 = positional[0].loc[:2]
if not all(
entry.loc is not None and entry.loc[:2] == loc0
for entry in positional
entry.loc is not None and entry.loc[:2] == loc0 for entry in positional
):
raise Exception(
"All positional arguments must be defined in the same"
" function."
"All positional arguments must be defined in the same" " function."
)

nonpositional = list(
Expand Down Expand Up @@ -476,9 +467,7 @@ def _make_cli_helper(parser, entry, extras, **kwargs):
_make_cli_helper(subparser, subentry, extras, **kwargs)

elif hasattr(entry, "__coleo_structure__"):
return _make_cli_helper(
parser, entry.__coleo_structure__, extras, **kwargs
)
return _make_cli_helper(parser, entry.__coleo_structure__, extras, **kwargs)

elif inspect.isclass(entry):
structure = {"__doc__": entry.__doc__}
Expand All @@ -487,9 +476,7 @@ def _make_cli_helper(parser, entry, extras, **kwargs):
entry2 = tooled(entry2)
setattr(entry, name, entry2)
structure[name] = entry2
elif is_tooled(through_method(entry2)) or isinstance(
entry2, (dict, type)
):
elif is_tooled(through_method(entry2)) or isinstance(entry2, (dict, type)):
structure[name] = entry2
return _make_cli_helper(parser, structure, extras, **kwargs)

Expand Down
3 changes: 1 addition & 2 deletions coleo/config.py → src/coleo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def _read_cfg(file):
parser.read_string(s)
if parser.sections() != ["default"]:
raise OSError(
"A cfg/ini file containing options must only contain"
" the [default] section"
"A cfg/ini file containing options must only contain" " the [default] section"
)
return dict(parser["default"])

Expand Down
File renamed without changes.
Loading

0 comments on commit cf2f7df

Please sign in to comment.