Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move optional deps #132

Merged
merged 5 commits into from
Jul 8, 2024
Merged
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
43 changes: 38 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
FORCE_COLOR: 3

jobs:
pre-commit:
format:
name: Format
runs-on: ubuntu-latest
steps:
Expand All @@ -27,9 +27,9 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.1
with:
extra_args: --hook-stage manual --all-files
# - uses: pre-commit/action@v3.0.1
# with:
# extra_args: --hook-stage manual --all-files
- name: Run PyLint
run: |
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
Expand All @@ -38,7 +38,7 @@ jobs:
checks:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
needs: [pre-commit]
needs: [format]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -71,3 +71,36 @@ jobs:
uses: codecov/codecov-action@v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}

check_interop:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
needs: [format]
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
runs-on: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install package
run: python -m pip install .[all,test]

- name: Test package
run: >-
python -m pytest src docs tests -ra --cov --cov-report=xml
--cov-report=term --durations=20

- name: Upload coverage report
uses: codecov/codecov-action@v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
9 changes: 9 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import platform
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
from importlib.util import find_spec

from sybil import Sybil
from sybil.parsers.rest import DocTestParser, PythonCodeBlockParser, SkipParser
Expand All @@ -22,3 +23,11 @@
parsers=parsers,
patterns=["*.rst", "*.py"],
).pytest()


# TODO: via separate optional_deps package
HAS_GALA = find_spec("gala") is not None

collect_ignore_glob = []
if not HAS_GALA:
collect_ignore_glob.append("src/unxt/_unxt_interop_gala/*")
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
requires-python = ">=3.10"

[project.optional-dependencies]
all = []
all = ["unxt[gala]"]
gala = ["gala"]
dev = ["unxt[docs]", "unxt[test]"]
docs = [
"sphinx>=7.0",
Expand Down
7 changes: 7 additions & 0 deletions src/unxt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
experimental, # noqa: F401
unitsystems,
)
from ._optional_deps import HAS_GALA
from ._quantity import *
from ._version import version as __version__
from .unitsystems import AbstractUnitSystem, UnitSystem, unitsystem

if HAS_GALA:
from . import _unxt_interop_gala # noqa: F401

__all__ = [
"__version__",
# units systems
Expand All @@ -21,3 +25,6 @@
"unitsystem", # convenience constructor
]
__all__ += _quantity.__all__

# Clean up namespace
del HAS_GALA, _quantity
File renamed without changes.
5 changes: 5 additions & 0 deletions src/unxt/_unxt_interop_gala/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Tools for representing systems of units using ``astropy.units``."""

__all__: list[str] = []

from . import unitsystems # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@

__all__: list[str] = []

try: # TODO: less hacky way of supporting optional dependencies
import pytest
except ImportError: # pragma: no cover
pass
else:
_ = pytest.importorskip("gala")

from gala.units import (
from gala.units import ( # pylint: disable=import-error
DimensionlessUnitSystem as GalaDimensionlessUnitSystem,
UnitSystem as GalaUnitSystem,
)
from plum import dispatch

from ._core import DimensionlessUnitSystem, UnitSystem
from ._realizations import dimensionless
from unxt.unitsystems import DimensionlessUnitSystem, UnitSystem, dimensionless


@dispatch
Expand Down
3 changes: 0 additions & 3 deletions src/unxt/_utils/__init__.py

This file was deleted.

9 changes: 1 addition & 8 deletions src/unxt/unitsystems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
from ._core import *
from ._realizations import *
from ._utils import *
from unxt._utils.optional_deps import HAS_GALA

__all__: list[str] = []
__all__ += _base.__all__
__all__ += _core.__all__
__all__ += _realizations.__all__
__all__ += _utils.__all__

if HAS_GALA:
from . import _compat
from ._compat import *

__all__ += _compat.__all__

# Clean up namespace
del _core, _utils, _realizations, HAS_GALA
del _core, _utils, _realizations