Skip to content

Commit 1288872

Browse files
authored
Replace packaging dependency with internal version handling (#425)
1 parent 77bf7b1 commit 1288872

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

docs/releasenotes/3.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ Fixes
3939
Other
4040
-----
4141
* Reorganized our imports to better support optional rich dependency (#419)
42+
* Replaced packaging dependency with internal version handling, which makes our installer lighter

robotidy/utils.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
from enum import Enum
6+
from functools import total_ordering
67
from typing import Iterable, List, Optional, Pattern
78

89
import click
@@ -12,14 +13,43 @@
1213
except ImportError: # Fails on vendored-in LSP plugin
1314
escape = None
1415

15-
from packaging import version
1616
from robot.api.parsing import Comment, End, If, IfHeader, ModelVisitor, Token
1717
from robot.parsing.model import Statement
1818
from robot.utils.robotio import file_writer
1919
from robot.version import VERSION as RF_VERSION
2020

21-
ROBOT_VERSION = version.parse(RF_VERSION)
22-
ROBOT_WITH_LANG = version.parse("6.0")
21+
22+
@total_ordering
23+
class Version:
24+
def __init__(self, major: int, minor: int, fix: int):
25+
self.major = major
26+
self.minor = minor
27+
self.fix = fix
28+
29+
@classmethod
30+
def parse(cls, raw_version):
31+
version = re.search(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.?(?P<fix>[0-9]+)*", raw_version)
32+
major = int(version.group("major"))
33+
minor = int(version.group("minor")) if version.group("minor") is not None else 0
34+
fix = int(version.group("fix")) if version.group("fix") is not None else 0
35+
return cls(major, minor, fix)
36+
37+
def __eq__(self, other):
38+
return self.major == other.major and self.minor == other.minor and self.fix == other.fix
39+
40+
def __lt__(self, other):
41+
if self.major != other.major:
42+
return self.major < other.major
43+
if self.minor != other.minor:
44+
return self.minor < other.minor
45+
return self.fix < other.fix
46+
47+
def __str__(self):
48+
return f"{self.major}.{self.minor}.{self.fix}"
49+
50+
51+
ROBOT_VERSION = Version.parse(RF_VERSION)
52+
ROBOT_WITH_LANG = Version(6, 0, 0)
2353

2454

2555
def rf_supports_lang():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"robotframework>=4.0",
4343
"click>=7.1.2",
4444
"colorama>=0.4.3",
45-
"packaging>=21.0",
4645
"pathspec>=0.9.0,<0.10.0",
4746
"tomli>=2.0.0",
4847
"rich_click==1.4",
@@ -52,6 +51,7 @@
5251
"coverage",
5352
"invoke",
5453
"jinja2",
54+
"packaging>=21.0",
5555
"pyflakes==2.4.*", # FIXME https://github.com/klen/pylama/issues/224
5656
"pylama",
5757
"pytest",

tests/atest/transformers/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55

66
import pytest
77
from click.testing import CliRunner
8+
from packaging import version
89
from packaging.specifiers import SpecifierSet
910
from rich.console import Console
11+
from robot.version import VERSION as RF_VERSION
1012

1113
from robotidy.cli import cli
12-
from robotidy.utils import ROBOT_VERSION, decorate_diff_with_color
14+
from robotidy.utils import decorate_diff_with_color
1315

1416
VERSION_MATRIX = {
1517
"ReplaceReturns": 5,
1618
"InlineIf": 5,
1719
"ReplaceBreakContinue": 5,
1820
}
21+
ROBOT_VERSION = version.parse(RF_VERSION)
1922

2023

2124
def display_file_diff(expected, actual):

0 commit comments

Comments
 (0)