-
Notifications
You must be signed in to change notification settings - Fork 1
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
Repo structure #24
Comments
Happy on those first two points. (Happy as in agreed) For testing/linting/type checking - I believe the template we are using from ICL comes with a lot of this in place already - but I will have to defer to @dalonsoa on that |
Nox does not replace what you have, it just streamlines the development. For example, instead of running the linter, type checker, and pytest with different commands, you can setup |
Totally supportive of 1. Agree with 2 if non-python stuff is absolutely necessary (otherwise normal python is totally fine), but will go for I've just used |
Regarding |
My bad: I did not try I've just had a look at In summary: choose one tool and stick to it :) |
IMHO, the biggest advantage of using I have one test env and a base """Nox sessions."""
from __future__ import annotations
import shutil
from pathlib import Path
import nox
try:
import tomllib as tomli
except ImportError:
import tomli
def get_deps() -> list[str]:
"""Get the main deps."""
with Path("pyproject.toml").open("rb") as f:
return tomli.load(f)["project"]["dependencies"]
def get_extras() -> list[str]:
"""Get the extra deps."""
with Path("pyproject.toml").open("rb") as f:
extras = tomli.load(f)["project"]["optional-dependencies"]
return [e for e in extras if e not in ("test", "doc")]
test_version = ["3.9"]
lint_version = ["3.11"]
nox.options.sessions = (
"pre-commit",
"type-check",
"tests",
)
def install_deps(session: nox.Session, extra: str | None = None) -> None:
"""Install package dependencies."""
deps = [f".[{extra}]"] if extra else ["."]
session.install(*deps)
dirs = [".pytest_cache", "build", "dist", ".eggs"]
for d in dirs:
shutil.rmtree(d, ignore_errors=True)
patterns = ["*.egg-info", "*.egg", "*.pyc", "*~", "**/__pycache__"]
for p in patterns:
for f in Path.cwd().rglob(p):
shutil.rmtree(f, ignore_errors=True)
@nox.session(name="pre-commit", python=lint_version)
def pre_commit(session: nox.Session) -> None:
"""Lint using pre-commit."""
session.install("pre-commit")
session.run(
"pre-commit",
"run",
"--all-files",
"--hook-stage=manual",
*session.posargs,
)
@nox.session(name="type-check", python=test_version)
def type_check(session: nox.Session) -> None:
"""Run Pyright."""
extras = get_extras()
install_deps(session, ",".join(extras))
session.install("pyright")
session.run("pyright")
@nox.session(python=test_version)
def tests(session: nox.Session) -> None:
"""Run the test suite."""
install_deps(session, "test")
session.run("pytest", "--doctest-modules", *session.posargs)
session.notify("cover")
@nox.session
def cover(session: nox.Session) -> None:
"""Coverage analysis."""
session.install("coverage[toml]")
session.run("coverage", "report")
session.run("coverage", "erase") |
This is really good stuff. Very powerful and definitely worth a try. Having said that is a tool on top of pytest, pre-commit and coverage (in your particular example), so something else to worry about and that might go wrong. But, as I said, I will try it because it looks pretty nice. |
There's no consensus on what is considered a "good" structure for a python package repo. So, it's subjective, but there are some best practices. The structure of the repo is fine. Here are my main suggestions based on my experience and preference to improve it:
conda
(mamba
, ormicromamba
) is recommended for development and users, too. There are many discussions about this on the internet, but the main reason is that many of the these geospatial packages depend on non-python libraries that can be tricky to install on different platforms. Usingconda
solves this issue sinceconda
packages are pre-compiled and optimized for different platforms. So, it makes managing the dependencies easier and codes may even run faster, too.nox
for testing, linting, and type checking.I can help with setting these up.
The text was updated successfully, but these errors were encountered: