Skip to content

Commit

Permalink
refactor: use uv and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
centaurialpha committed Sep 22, 2024
1 parent 2afddc4 commit 62c9042
Show file tree
Hide file tree
Showing 14 changed files with 399 additions and 82 deletions.
52 changes: 36 additions & 16 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,54 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10", "3.11"]
python-version: ["3.11", "3.12"]
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version-file: "pyproject.toml"

- name: Prepare Environment
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install .
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
uv sync --frozen
if [ "${{ matrix.os}}" == "ubuntu-latest" ]; then
sudo apt-get update -y
sudo apt-get install -y libgles2-mesa-dev
fi
- name: Lint
if: runner.os == 'Linux'
- name: Run Tests
run: |
make check
uv run pytest -vvx
# - uses: actions/checkout@v4
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}

- name: Unit Tests
run: |
make test-interpreter
make test-unit
# - name: Prepare Environment
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements-dev.txt
# pip install .
# if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
# sudo apt-get update -y
# sudo apt-get install -y libgles2-mesa-dev
# fi

# - name: Lint
# if: runner.os == 'Linux'
# run: |
# make check

# - name: Unit Tests
# run: |
# make test-interpreter
# make test-unit
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Empty file added ola
Empty file.
45 changes: 20 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
[project]
name = "pireal"
dynamic = ["version"]
version = "4.0"
description = "Relational Algebra Interpreter"
readme = "README.md"
requires-python = ">=3.10"
license = {file = "COPYING"}
authors = [
{name = "Gabriel Acosta", email = "[email protected]"}
]
license = { file = "COPYING" }
authors = [{ name = "Gabriel Acosta", email = "[email protected]" }]
maintainers = [
{name = "Gabriel Acosta", email = "[email protected]"}
{ name = "Gabriel Acosta", email = "[email protected]" },
]
classifiers = [
"Environment :: X11 Applications",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Education",
"Topic :: Utilities",
"Environment :: X11 Applications",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Education",
"Topic :: Utilities",
]
dependencies = [
"PyQt6"
"packaging>=24.1",
"pyqt6>=6.7.1",
]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov", "ruff"]
extras = ["rich"]

[project.scripts]
pireal = "pireal.main:run"

[tool.setuptools.packages.find]
where = ["src"]

[build-system]
requires = ["setuptools", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = [ "A", "B", "C90", "D", "E", "EM", "F", "I", "N", "PTH", "RUF", "W",]
ignore = ["D103", "D102", "D101", "D100", "D107", "D104", "D105", "EM101", "N802", "N815", "EM102"]
exclude = ["windows/*", "tests/*"]

[tool.uv]
dev-dependencies = [
"pytest-cov>=5.0.0",
"pytest>=8.3.3",
"ruff>=0.6.7",
]
47 changes: 47 additions & 0 deletions pyproject.toml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[project]
name = "pireal"
dynamic = ["version"]
description = "Relational Algebra Interpreter"
readme = "README.md"
requires-python = ">=3.10"
license = {file = "COPYING"}
authors = [
{name = "Gabriel Acosta", email = "[email protected]"}
]
maintainers = [
{name = "Gabriel Acosta", email = "[email protected]"}
]
classifiers = [
"Environment :: X11 Applications",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Education",
"Topic :: Utilities",
]
dependencies = [
"PyQt6"
]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov", "ruff"]
extras = ["rich"]

[project.scripts]
pireal = "pireal.main:run"

[tool.setuptools.packages.find]
where = ["src"]

[build-system]
requires = ["setuptools", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = [ "A", "B", "C90", "D", "E", "EM", "F", "I", "N", "PTH", "RUF", "W",]
ignore = ["D103", "D102", "D101", "D100", "D107", "D104", "D105", "EM101", "N802", "N815", "EM102"]
exclude = ["windows/*", "tests/*"]
15 changes: 7 additions & 8 deletions src/pireal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
# This necesary for sphinx
from typing import cast

from pkg_resources import DistributionNotFound, get_distribution

try:
__version__ = get_distribution("pireal").version
except DistributionNotFound:
# package is not installed
pass

# from pkg_resources import DistributionNotFound, get_distribution
# try:
# __version__ = get_distribution("pireal").version
# except DistributionNotFound:
# # package is not installed
# pass
__version__ = "4.0.0"
from pireal.gui.main_window import Pireal

instance = None
Expand Down
6 changes: 3 additions & 3 deletions src/pireal/core/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with Pireal; If not, see <http://www.gnu.org/licenses/>.

import os
from pathlib import Path


Expand Down Expand Up @@ -62,5 +61,6 @@ def generate_database(relations):
return content


def get_files_from_folder(path):
return [f.stem for f in os.listdir(path) if (path / f).is_file()]
def get_files_from_folder(path: Path) -> list[Path]:
# return [f.stem for f in os.listdir(path) if (path / f).is_file()]
return [file for file in path.iterdir() if (path / file).is_file()]
18 changes: 9 additions & 9 deletions src/pireal/core/ordered_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def __init__(self, iterable=None):
if iterable is not None:
self |= iterable

def add(self, key):
if key not in self._map:
self._map[key] = len(self._items)
self._items.append(key)
return self._map[key]
def add(self, value):
if value not in self._map:
self._map[value] = len(self._items)
self._items.append(value)
return self._map[value]

def intersection(self, other):
common = (item for item in self if item in other)
Expand Down Expand Up @@ -83,11 +83,11 @@ def __setitem__(self, index, data):
self._items[index] = data
self._map[data] = index

def discard(self, key):
if key in self:
i = self._map[key]
def discard(self, value):
if value in self:
i = self._map[value]
del self._items[i]
del self._map[key]
del self._map[value]
for k, v in self._map.items():
if v >= i:
self._map[k] = v - 1
10 changes: 5 additions & 5 deletions src/pireal/core/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def njoin(self, other_relation):
indexes_or = [other_relation.header.index(i) for i in sharedf]

for i, j in itertools.product(self.content, other_relation.content):
for k, l in itertools.product(indexes_r, indexes_or):
if i[k] == j[l]:
for k, L in itertools.product(indexes_r, indexes_or):
if i[k] == j[L]:
new_relation.insert(i + j)
# Project para eliminar campos repetidos
return new_relation.project(*final_fields)
Expand All @@ -228,14 +228,14 @@ def louter(self, other_relation):
for i in self.content:
added = False
for j in other_relation.content:
for k, l in itertools.product(indexes_r, indexes_or):
if i[k] == j[l]:
for k, L in itertools.product(indexes_r, indexes_or):
if i[k] == j[L]:
# Esto es un producto cartesiano con la
# condición equi-join
new_relation.insert(i + j)
added = True
if not added:
nulls = ["null" for i in range(len(other_relation.header))]
nulls = ["null" for _ in range(len(other_relation.header))]
new_relation.insert(tuple(list(i) + nulls))

return new_relation.project(*final_fields)
Expand Down
6 changes: 3 additions & 3 deletions src/pireal/gui/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from urllib.error import URLError
from urllib.request import urlopen

from pkg_resources import parse_version
from packaging.version import parse
from PyQt6.QtCore import QObject
from PyQt6.QtCore import pyqtSignal as Signal

Expand All @@ -41,8 +41,8 @@ def __init__(self):
def check_updates(self):
logger.info("Checking for updates...")
try:
web_version = parse_version(urlopen(URL).read().decode().strip())
version = parse_version(__version__)
web_version = parse(urlopen(URL).read().decode().strip())
version = parse(__version__)
if version < web_version:
self.version = web_version
logger.info("new version found: %s", self.version)
Expand Down
Empty file added src/pireal/py.typed
Empty file.
2 changes: 1 addition & 1 deletion tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_parser_help(parser):


def test_parser_args_valid(parser):
cmd = ["-d file.pdb", "--database lalala", "-v", "--verbose", "--version"]
cmd = ["-d file.pdb", "--database lalala", "-l DEBUG", "--version"]
for line in cmd:
cmdline = shlex.split(line)
parser.parse_args(cmdline)
Expand Down
25 changes: 13 additions & 12 deletions tests/unit/test_file_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path

import pytest

from pireal.core import file_manager
from pireal.core import relation
from pireal.core import file_manager, relation


@pytest.mark.parametrize(
Expand All @@ -25,29 +26,29 @@ def test_get_extension(filename, expected):
],
)
def test_get_basename(filename, name):
assert file_manager.get_basename(filename) == name
assert str(file_manager.get_basename(filename)) == name


@pytest.mark.parametrize(
"filename, path",
[
("/home/gabo/archivo.py", "/home/gabo"),
("/path/path/blabla/file.extension", "/path/path/blabla"),
("/hola/como/estas/que_onda.qda", "/hola/como/estas"),
(Path("/home/gabo/archivo.py"), Path("/home/gabo")),
(Path("/path/path/blabla/file.extension"), Path("/path/path/blabla")),
(Path("/hola/como/estas/que_onda.qda"), Path("/hola/como/estas")),
],
)
def test_get_path(filename, path):
assert file_manager.get_path(filename) == path


def test_get_files_from_folder(tmpdir):
def test_get_files_from_folder(tmp_path: Path):
files = ("archivo.py", "archivo2.py", "archivo3.py")
assert len(tmpdir.listdir()) == 0
assert len(list(tmp_path.iterdir())) == 0
for f in files:
path = tmpdir.join(f)
path.write("Some content")
assert len(tmpdir.listdir()) == len(files)
_files = file_manager.get_files_from_folder(tmpdir.strpath)
path = tmp_path / f
path.write_text("Some content")
assert len(list(tmp_path.iterdir())) == len(files)
_files = file_manager.get_files_from_folder(tmp_path)
assert len(_files) == len(files)


Expand Down
Loading

0 comments on commit 62c9042

Please sign in to comment.