Skip to content
Open
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
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
.idea
__pycache__
result
result-*

__pycache__/
*.py[cod]
*.egg-info/
build/
dist/
.venv/
60 changes: 41 additions & 19 deletions eos/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
"""
Versions helper.

Wrapper on distutils.version to allow more laziness.
Small version wrapper used for Symfony version comparisons.
"""

from distutils.version import LooseVersion
from __future__ import annotations

import re
from functools import total_ordering

class Version(LooseVersion):

@total_ordering
class Version:
"""
EOS Version.

Simple wrapper on distutils.LooseVersion to provide more abstraction on version comparison.
distutils was removed from the stdlib in Python 3.12+, so we keep a tiny
implementation that supports the comparisons EOS needs (e.g. "4.1" <= "4.4").
"""

def _cmp(self, other):
"""
Comparison override to support extra types.

If other is not an Version instance (or LooseVersion by inheritance), cast it to string and Version.
This provides integers support among others.
The base method is then called.

:param other: the other object to compare against
"""

if not isinstance(other, Version):
other = Version(str(other))

return super()._cmp(other)
def __init__(self, value):
self.raw = str(value)

# Extract the first dotted numeric version-like substring.
# Examples:
# - "5.0.1" -> (5, 0, 1)
# - "Symfony 5.0.1" -> (5, 0, 1)
# - "5.0.1-rc1" -> (5, 0, 1)
match = re.search(r"\d+(?:\.\d+)*", self.raw)
if match:
self.parts = tuple(int(p) for p in match.group(0).split("."))
else:
self.parts = (0,)

def _cmp_tuple(self, other: object) -> tuple[tuple[int, ...], tuple[int, ...]]:
other_version = other if isinstance(other, Version) else Version(other)

max_len = max(len(self.parts), len(other_version.parts))
left = self.parts + (0,) * (max_len - len(self.parts))
right = other_version.parts + (0,) * (max_len - len(other_version.parts))
return left, right

def __eq__(self, other: object) -> bool:
left, right = self._cmp_tuple(other)
return left == right

def __lt__(self, other: object) -> bool:
left, right = self._cmp_tuple(other)
return left < right

def __str__(self) -> str:
return self.raw
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
description = "eos - Enemies Of Symfony";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
eos = pkgs.callPackage ./package.nix { };
in
{
packages = {
default = eos;
eos = eos;
};

apps.default = flake-utils.lib.mkApp { drv = eos; };

devShells.default = import ./shell.nix { inherit pkgs; };
});
}

41 changes: 41 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ lib
, python3Packages
}:

python3Packages.buildPythonApplication rec {
pname = "eos";
version = "1.0.0";

src = lib.cleanSource ./.;

# setup.py (setuptools), no pyproject.toml
pyproject = false;

nativeBuildInputs = with python3Packages; [
setuptoolsBuildHook
pypaInstallHook
# setup.py imports `eos`, which imports `requests` (see eos.Dockerfile).
requests
beautifulsoup4
lxml
defusedxml
];

propagatedBuildInputs = with python3Packages; [
requests
beautifulsoup4
lxml
defusedxml
];

pythonImportsCheck = [
"eos"
];

meta = with lib; {
description = "Enemies Of Symfony";
homepage = "https://github.com/synacktiv/eos";
license = licenses.gpl3Only;
mainProgram = "eos";
};
}
11 changes: 11 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> { } }:

let
eos = pkgs.callPackage ./package.nix { };
in
pkgs.mkShell {
packages = [
eos
];
}