Skip to content

Commit

Permalink
🎨 Remove lnschema-core installation (#44)
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson authored Jan 7, 2025
1 parent 9659bc4 commit ad279cf
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8"] # we want to be able to run this on 3.8
python-version: ["3.12"]
timeout-minutes: 10

steps:
Expand Down
79 changes: 33 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,51 @@
fail_fast: false
default_language_version:
python: python3
default_stages:
- commit
- push
minimum_pre_commit_version: 2.12.0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: |
(?x)(
.github/workflows/latest-changes.jinja2
)
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black-jupyter
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.4
hooks:
- id: flake8
additional_dependencies:
- flake8-black==0.3.3
- flake8-typing-imports==1.10.0
language_version: python3
args:
- --max-line-length=88
- --ignore=E203,W503,BLK100,TYP001
- id: prettier
exclude: |
(?x)(
__init__.py
docs/changelog.md
)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
hooks:
- id: prettier
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
rev: 0.6.1
hooks:
- id: nbstripout
exclude: |
(?x)(
docs/examples/|
docs/notes/
)
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
hooks:
- id: forbid-crlf
- id: remove-crlf
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.8.0
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: isort
args: ["--profile", "black"]
- id: detect-private-key
- id: check-ast
- id: end-of-file-fixer
exclude: |
(?x)(
.github/workflows/latest-changes.jinja2
)
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.940
rev: v1.7.1
hooks:
- id: mypy
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
args: # google style + __init__, see http://www.pydocstyle.org/en/stable/error_codes.html
- --ignore=D100,D101,D102,D103,D106,D107,D203,D204,D213,D215,D400,D401,D403,D404,D406,D407,D408,D409,D412,D413
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies: ["types-requests", "types-attrs"]
4 changes: 1 addition & 3 deletions docs/notes/YYYY-MM-DD-my-design-choice.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"id": "97ec6631-8473-4a2d-b488-def921bb83de",
"metadata": {},
"outputs": [],
"source": [
"from nbproject import header"
]
"source": []
}
],
"metadata": {
Expand Down
33 changes: 18 additions & 15 deletions laminci/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import subprocess
from pathlib import Path
from subprocess import PIPE, run
from typing import Union

from packaging.version import Version, parse

Expand All @@ -35,7 +34,7 @@

def update_readme_version(file_path, new_version):
# Read the content of the file
with open(file_path, "r") as file:
with open(file_path) as file:
content = file.read()

# Use regex to find and replace the version
Expand All @@ -49,7 +48,7 @@ def update_readme_version(file_path, new_version):


def get_last_version_from_tags():
proc = run(["git", "tag"], universal_newlines=True, stdout=PIPE)
proc = run(["git", "tag"], text=True, stdout=PIPE)
tags = proc.stdout.splitlines()
newest = "0.0.0"
for tag in tags:
Expand All @@ -64,16 +63,18 @@ def validate_version(version_str: str):
if not len(version.release) == 2:
raise SystemExit(
f"Pre-releases should be of form 0.42a1 or 0.42rc1, yours is {version}"
)
) from None
else:
return None
if len(version.release) != 3:
raise SystemExit(f"Version should be of form 0.1.2, yours is {version}")
raise SystemExit(
f"Version should be of form 0.1.2, yours is {version}"
) from None


def publish_github_release(
repo_name: str,
version: Union[str, Version],
version: str | Version,
release_name: str,
body: str = "",
draft: bool = False,
Expand Down Expand Up @@ -132,12 +133,14 @@ def publish_github_release(
generate_release_notes=generate_release_notes,
)
except GithubException as e:
raise SystemExit(f"Error creating GitHub release using `PyGithub`: {e}")
raise SystemExit(
f"Error creating GitHub release using `PyGithub`: {e}"
) from None
except ImportError:
raise SystemExit(
"Neither the Github CLI ('gh') nor PyGithub were accessible.\n"
"Please install one of the two."
)
) from None


def main():
Expand All @@ -163,23 +166,23 @@ def main():
raise SystemExit(
"Please pass a link to the changelog entry via: --changelog"
" 'your-link'"
)
) from None
if Path("./LICENSE").exists() and not args.pypi:
raise SystemExit(
"ERROR: Did you forget to add the `--pypi` flag? A LICENSE file"
" exists and I assume this is an open-source package."
)
) from None
repo_name = package_name.replace("_", "-")
else:
assert Path.cwd().name == "laminhub"
assert Path.cwd().name == "laminhub" # noqa: S101
repo_name = "laminhub"
if not (Path.cwd().parent / "laminhub-public").exists():
raise ValueError(
"Please clone the laminhub-public repository into the same parent"
" directory as laminhub."
)
is_laminhub = True
with open("ui/package.json", "r") as file:
with open("ui/package.json") as file:
version = json.load(file)["version"]

print(f"INFO: You will add this changelog link: {args.changelog}")
Expand All @@ -203,7 +206,7 @@ def main():
]
for command in commands:
print(f"\nrun: {command}")
run(command, shell=True)
run(command, shell=True) # noqa: S602

changelog_link = (
args.changelog
Expand All @@ -221,7 +224,7 @@ def main():
update_readme_version("../laminhub-public/README.md", version)
for command in commands:
print(f"\nrun: {command}")
run(command, shell=True, cwd="../laminhub-public")
run(command, shell=True, cwd="../laminhub-public") # noqa: S602
publish_github_release(
repo_name="laminlabs/laminhub-public",
version=version,
Expand All @@ -234,7 +237,7 @@ def main():
if args.pypi:
command = "flit publish"
print(f"\nrun: {command}")
run(command, shell=True)
run(command, shell=True) # noqa: S602
elif args.command == "doc-changes":
from ._doc_changes import doc_changes

Expand Down
3 changes: 1 addition & 2 deletions laminci/_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def setup_local_test_postgres(name: str = "pgtest", version: Optional[str] = Non
version = ""
process = run(
f"docker run --name {name} -e POSTGRES_PASSWORD=pwd"
f" -e POSTGRES_DB={name} -d -p 5432:5432 postgres{version}", # noqa
shell=True,
f" -e POSTGRES_DB={name} -d -p 5432:5432 postgres{version}",
)
if process.returncode == 0:
logger.info(
Expand Down
8 changes: 5 additions & 3 deletions laminci/_doc_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
import subprocess
import sys
from pathlib import Path
from typing import TYPE_CHECKING

from github import Github
from github.PullRequest import PullRequest
from jinja2 import Template
from pydantic import BaseModel, SecretStr
from pydantic_settings import BaseSettings

if TYPE_CHECKING:
from github.PullRequest import PullRequest


class Section(BaseModel):
label: str
Expand Down Expand Up @@ -209,8 +212,7 @@ def generate_content(
new_release_content = updated_content

new_content = (
f"{pre_header_content}\n\n{new_release_content}\n\n{post_release_content}"
.strip()
f"{pre_header_content}\n\n{new_release_content}\n\n{post_release_content}".strip()
+ "\n"
)
return new_content
Expand Down
5 changes: 3 additions & 2 deletions laminci/_docs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
from pathlib import Path

from ._env import load_project_yaml

Expand All @@ -9,7 +10,7 @@ def move_built_docs_to_slash_project_slug():
return
yaml = load_project_yaml()
shutil.move("_build/html", "_build/html_tmp")
os.makedirs("_build/html")
Path.mkdir("_build/html", parents=True)
shutil.move("_build/html_tmp", f"_build/html/{yaml['project_slug']}")


Expand All @@ -18,5 +19,5 @@ def move_built_docs_to_docs_slash_project_slug():
return
yaml = load_project_yaml()
shutil.move("_build/html", f"_build/{yaml['project_slug']}")
os.makedirs("_build/html/docs")
Path.mkdir("_build/html/docs", parents=True)
shutil.move(f"_build/{yaml['project_slug']}", "_build/html/docs")
13 changes: 9 additions & 4 deletions laminci/_docs_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def zip_docs_dir(zip_filename: str) -> None:

def zip_docs():
repo_name = Path.cwd().name
assert "." not in repo_name # doesn't have a weird suffix
assert Path(".git/").exists() # is git repo
assert repo_name.lower() == repo_name # is all lower-case
assert "." not in repo_name # doesn't have a weird suffix # noqa: S101
assert Path(".git/").exists() # is git repo # noqa: S101
assert repo_name.lower() == repo_name # is all lower-case # noqa: S101
zip_filename = f"{repo_name}.zip"
zip_docs_dir(zip_filename)
return repo_name, zip_filename


# Ruff seems to ignore any noqa comments in the following and we therefore disable it briefly
# ruff: noqa
def upload_docs_artifact_aws() -> None:
repo_name, zip_filename = zip_docs()
run(
Expand All @@ -35,6 +37,9 @@ def upload_docs_artifact_aws() -> None:
)


# ruff: enable


def upload_docs_artifact_lamindb() -> None:
repo_name, zip_filename = zip_docs()

Expand Down Expand Up @@ -73,5 +78,5 @@ def upload_docs_artifact(aws: bool = False) -> None:
upload_docs_artifact_lamindb()

except ImportError:
warnings.warn("Fall back to AWS")
warnings.warn("Fall back to AWS", stacklevel=2)
upload_docs_artifact_aws()
2 changes: 1 addition & 1 deletion laminci/_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def load_project_yaml(root_directory: Optional[Path] = None) -> dict:
yaml_file = Path("lamin-project.yaml")
if root_directory is None:
root_directory = Path(".")
root_directory = Path()
yaml_file = root_directory / yaml_file
with yaml_file.open() as f:
d = yaml.safe_load(f)
Expand Down
5 changes: 4 additions & 1 deletion laminci/_nox_logger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import logging
from collections.abc import Sequence
from typing import TYPE_CHECKING

import nox
from nox.registry import _REGISTRY, Any, Callable, F, Func, Python, functools

if TYPE_CHECKING:
from collections.abc import Sequence


def session_decorator(
func: F | None = None,
Expand Down
2 changes: 1 addition & 1 deletion laminci/_run_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ def run_notebooks(file_or_folder: str | Path):
import nbproject_test

path = Path(file_or_folder)
assert path.exists()
assert path.exists() # noqa: S101c
nbproject_test.execute_notebooks(path.resolve(), write=True)
Loading

0 comments on commit ad279cf

Please sign in to comment.