-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
134 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ description = "A scalable feature store that makes it easy to align offline and | |
authors = ["Mats E. Mollestad <[email protected]>"] | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
homepage = "https://github.com/otovo/aladdin" | ||
repository = "https://github.com/otovo/aladdin" | ||
homepage = "https://github.com/otovo/aligned" | ||
repository = "https://github.com/otovo/aligned" | ||
keywords = [ | ||
'python', | ||
'typed', | ||
|
@@ -53,7 +53,7 @@ pyarrow = "^8.0.0" | |
Jinja2 = "^3.1.2" | ||
nest-asyncio = "^1.5.5" | ||
asgi-correlation-id = { version = "^3.0.0", optional = true } | ||
pandera = {version = "^0.13.3", optional = true} | ||
pandera = { version = "^0.13.3", optional = true} | ||
httpx = "^0.23.0" | ||
polars = { version = "^0.15.6", extras = ["all"] } | ||
connectorx = { version = "^0.3.1", optional = true } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from dataclasses import asdict, dataclass | ||
from pathlib import Path | ||
|
||
import polars as pl | ||
|
||
from aligned.compiler.repo_reader import find_files | ||
|
||
|
||
def generate_snippets(): | ||
root_path = Path().resolve() | ||
markdown_files = find_files(root_path, file_extension='md') | ||
|
||
source_code_folder = root_path / 'aligned' | ||
source_code_files = find_files(source_code_folder) | ||
|
||
all_snippets: list[Snippet] = [] | ||
for file in markdown_files: | ||
all_snippets.extend(generate_snippet_from_markdown_file(file, root_path)) | ||
|
||
for file in source_code_files: | ||
all_snippets.extend(generate_snippet_from_python_file(file, root_path)) | ||
|
||
df = pl.DataFrame([asdict(snippet) for snippet in all_snippets]).with_row_count(name='id') | ||
df.write_csv('snippets.csv', sep=';') | ||
|
||
|
||
@dataclass | ||
class Snippet: | ||
source_file: Path | ||
version_tag: str | ||
snippet: str | ||
|
||
|
||
def generate_snippet_from_markdown_file(file: Path, root_path: Path) -> list[Snippet]: | ||
file_content = file.read_text() | ||
sections = file_content.split('\n#') | ||
return [ | ||
Snippet(source_file=file.relative_to(root_path).as_posix(), version_tag='beta', snippet=section) | ||
for section in sections | ||
] | ||
|
||
|
||
def generate_snippet_from_python_file(file: Path, root_path: Path) -> list[Snippet]: | ||
file_content = file.read_text() | ||
|
||
dataclass_suffix = '@dataclass\n' | ||
classes = file_content.split('class ') | ||
if len(classes) == 1: | ||
return [] | ||
# The first index will not contain any classes. | ||
# Therefore, we can remove it | ||
classes = classes[1:] | ||
|
||
return [ | ||
Snippet( | ||
source_file=file.relative_to(root_path).as_posix(), | ||
version_tag='beta', | ||
snippet=f'class {snippet.removesuffix(dataclass_suffix).strip()}', | ||
) | ||
for snippet in classes | ||
] | ||
|
||
|
||
if __name__ == '__main__': | ||
generate_snippets() |
Oops, something went wrong.