Skip to content

Commit

Permalink
Migrating to pyproject.toml, using ruff for QA, and switching to UV f…
Browse files Browse the repository at this point in the history
…or installations (#81)

* Switching from setup.cfg to pyproject.toml -- untested

* Fixing small issues with the pyproject.toml

* Fixing linting errors with Ruff

* Switching over to UV for installation. Fixing the mocking to reflect new calls

* Fixing lower bound based on edgetest testing

* Running ruff

* Using ruff instead of flake8

* Updating the action deployment

* Seeing if upgrading the actions helps

* Trying to fix the Windows issue by making the base directory dynamic.

* Fixing the ruff issue

* Additional logging for command line calls (like uv)

* Adding .exe extension to the Python path for Windows

* Fixing test errors after Windows python path fix

* Switching away from the dask installation since that was causing some issues. Moved to polars so we have fewer transient dependencies to worry about

* Fixing test for Python 3.8 and 3.9

* Updating the pre-commit configuration
  • Loading branch information
ak-gupta authored Jul 30, 2024
1 parent 8ac71cd commit 5ae354b
Show file tree
Hide file tree
Showing 23 changed files with 503 additions and 441 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/edgetest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
- id: run-edgetest
uses: edgetest-dev/[email protected]
with:
edgetest-flags: '-c setup.cfg --export'
edgetest-flags: '-c pyproject.toml --export'
base-branch: 'dev'
skip-pr: 'false'
12 changes: 6 additions & 6 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ jobs:
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install -r requirements.txt .[dev]
- name: Check docstrings
run: python -m pydocstyle edgetest --convention=numpy
- name: Run ruff QA checks
run: python -m ruff check .
- name: Check formatting
run: python -m ruff format . --check
- name: Check static typing
run: python -m mypy edgetest
- name: Run flake8
run: python -m flake8 edgetest
- name: Run unit testing
run: python -m pytest tests --cov=edgetest --cov-fail-under=90
36 changes: 16 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
exclude: ^notebooks/
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: black
types: [file, python]
language_version: python3.9
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
types_or: [ python, jupyter ]
# Mypy: Optional static type checking
# https://github.com/pre-commit/mirrors-mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
files: ^edgetest/
- id: mypy
exclude: ^(docs|tests)\/
language_version: python3.9
- repo: https://github.com/jazzband/pip-tools
rev: 6.6.2
hooks:
- id: pip-compile
args: [--namespace-packages, --explicit-package-bases, --ignore-missing-imports, --non-interactive, --install-types]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: debug-statements
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand Down
1 change: 0 additions & 1 deletion edgetest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Package initialization."""


__version__ = "2024.4.0"

__title__ = "edgetest"
Expand Down
40 changes: 28 additions & 12 deletions edgetest/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from pluggy._hooks import _HookRelay

from .logger import get_logger
from .utils import _isin_case_dashhyphen_ins, _run_command, pushd
from edgetest.logger import get_logger
from edgetest.utils import _isin_case_dashhyphen_ins, _run_command, pushd

LOG = get_logger(__name__)

Expand Down Expand Up @@ -50,8 +50,6 @@ def __init__(
):
"""Init method."""
self.hook = hook
self._basedir = Path(Path.cwd(), ".edgetest")
self._basedir.mkdir(exist_ok=True)
self.envname = envname

if (upgrade is None and lower is None) or (
Expand All @@ -65,6 +63,20 @@ def __init__(
self.setup_status: bool = False
self.status: bool = False

@property
def basedir(self) -> Path:
"""Base directory.
Returns
-------
Path
Base directory for execution.
"""
_basedir = Path.cwd() / ".edgetest"
_basedir.mkdir(exist_ok=True)

return _basedir

@property
def python_path(self) -> str:
"""Get the path to the python executable.
Expand All @@ -74,7 +86,7 @@ def python_path(self) -> str:
str
The path to the python executable.
"""
return self.hook.path_to_python(basedir=self._basedir, envname=self.envname) # type: ignore
return self.hook.path_to_python(basedir=self.basedir, envname=self.envname) # type: ignore

def setup(
self,
Expand Down Expand Up @@ -113,7 +125,7 @@ def setup(
try:
LOG.info(f"Creating the following environment: {self.envname}...")
self.hook.create_environment(
basedir=self._basedir, envname=self.envname, conf=options
basedir=self.basedir, envname=self.envname, conf=options
)
LOG.info(f"Successfully created {self.envname}")
except RuntimeError:
Expand All @@ -137,10 +149,10 @@ def setup(
split = [shlex.split(dep) for dep in deps]
try:
_run_command(
self.python_path,
"-m",
"uv",
"pip",
"install",
f"--python={self.python_path}",
*[itm for lst in split for itm in lst],
)
except RuntimeError:
Expand All @@ -156,7 +168,9 @@ def setup(

LOG.info(f"Installing the local package into {self.envname}...")
try:
_run_command(self.python_path, "-m", "pip", "install", pkg)
_run_command(
"uv", "pip", "install", f"--python={self.python_path}", pkg
)
LOG.info(
f"Successfully installed the local package into {self.envname}..."
)
Expand All @@ -174,7 +188,7 @@ def setup(
)
try:
self.hook.run_update(
basedir=self._basedir,
basedir=self.basedir,
envname=self.envname,
upgrade=self.upgrade,
conf=options,
Expand All @@ -194,7 +208,7 @@ def setup(
)
try:
self.hook.run_install_lower(
basedir=self._basedir,
basedir=self.basedir,
envname=self.envname,
lower=self.lower,
conf=options,
Expand Down Expand Up @@ -226,7 +240,9 @@ def upgraded_packages(self) -> List[Dict[str, str]]:
if self.upgrade is None:
return []
# Get the version for the upgraded package(s)
out, _ = _run_command(self.python_path, "-m", "pip", "list", "--format", "json")
out, _ = _run_command(
"uv", "pip", "list", f"--python={self.python_path}", "--format", "json"
)
outjson = json.loads(out)

upgrade_wo_extras = [pkg.split("[")[0] for pkg in self.upgrade]
Expand Down
2 changes: 1 addition & 1 deletion edgetest/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pluggy

from .schema import Schema
from edgetest.schema import Schema

hookspec = pluggy.HookspecMarker("edgetest")

Expand Down
12 changes: 6 additions & 6 deletions edgetest/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import pluggy
from tomlkit import dumps

from . import hookspecs, lib
from .core import TestPackage
from .logger import get_logger
from .report import gen_report
from .schema import EdgetestValidator, Schema
from .utils import (
from edgetest import hookspecs, lib
from edgetest.core import TestPackage
from edgetest.logger import get_logger
from edgetest.report import gen_report
from edgetest.schema import EdgetestValidator, Schema
from edgetest.utils import (
gen_requirements_config,
parse_cfg,
parse_toml,
Expand Down
33 changes: 11 additions & 22 deletions edgetest/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pluggy

from .utils import _run_command
from edgetest.utils import _run_command

hookimpl = pluggy.HookimplMarker("edgetest")

Expand All @@ -16,7 +16,7 @@
def path_to_python(basedir: str, envname: str) -> str:
"""Return the path to the python executable."""
if platform.system() == "Windows":
return str(Path(basedir) / envname / "Scripts" / "python")
return str(Path(basedir) / envname / "Scripts" / "python.exe")
else:
return str(Path(basedir) / envname / "bin" / "python")

Expand All @@ -41,11 +41,11 @@ def create_environment(basedir: str, envname: str, conf: Dict):
RuntimeError
Error raised if the environment cannot be created.
"""
builder = EnvBuilder(with_pip=True)
builder = EnvBuilder(with_pip=False)
try:
builder.create(env_dir=Path(basedir, envname))
except Exception:
raise RuntimeError(f"Unable to create {envname} in {basedir}")
except Exception as err:
raise RuntimeError(f"Unable to create {envname} in {basedir}") from err


@hookimpl(trylast=True)
Expand All @@ -71,15 +71,10 @@ def run_update(basedir: str, envname: str, upgrade: List, conf: Dict):
python_path = path_to_python(basedir, envname)
try:
_run_command(
python_path,
"-m",
"pip",
"install",
*upgrade,
"--upgrade",
"uv", "pip", "install", f"--python={python_path}", *upgrade, "--upgrade"
)
except Exception:
raise RuntimeError(f"Unable to pip upgrade: {upgrade}")
except Exception as err:
raise RuntimeError(f"Unable to pip upgrade: {upgrade}") from err


@hookimpl(trylast=True)
Expand All @@ -101,12 +96,6 @@ def run_install_lower(basedir: str, envname: str, lower: List[str], conf: Dict):
"""
python_path = path_to_python(basedir, envname)
try:
_run_command(
python_path,
"-m",
"pip",
"install",
*lower,
)
except Exception:
raise RuntimeError(f"Unable to pip install: {lower}")
_run_command("uv", "pip", "install", f"--python={python_path}", *lower)
except Exception as err:
raise RuntimeError(f"Unable to pip install: {lower}") from err
2 changes: 1 addition & 1 deletion edgetest/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# logger levels
DEBUG = logging.DEBUG
INFO = logging.INFO
WARN = logging.WARN
WARN = logging.WARNING
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL

Expand Down
2 changes: 1 addition & 1 deletion edgetest/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tabulate import tabulate

from .core import TestPackage
from edgetest.core import TestPackage

VALID_OUTPUTS = ["rst", "github"]

Expand Down
Loading

0 comments on commit 5ae354b

Please sign in to comment.