Compare commits

...

7 Commits

7 changed files with 83 additions and 14 deletions

View File

@@ -17,7 +17,7 @@ def find_c_files(path: str):
for entry in os.listdir(path): for entry in os.listdir(path):
full_path = os.path.join(path, entry) full_path = os.path.join(path, entry)
if os.path.isdir(full_path): if os.path.isdir(full_path):
list_files_recursive(full_path) find_c_files(full_path)
else: else:
if full_path.endswith(".c"): if full_path.endswith(".c"):
paths.append(full_path) paths.append(full_path)
@@ -29,6 +29,9 @@ def build_mineral(args):
if not os.path.isdir(args.folder_path): if not os.path.isdir(args.folder_path):
console.print("[b red]digpkg: failed to build mineral: specified folder doesn't exist![/]") console.print("[b red]digpkg: failed to build mineral: specified folder doesn't exist![/]")
sys.exit(1) sys.exit(1)
if os.path.isfile(os.path.join(args.folder_path, "main.so")):
console.print("[b red]digpkg: failed to build mineral: attempt to build compiled mineral![/]")
sys.exit(1)
if not shutil.which("gcc"): if not shutil.which("gcc"):
console.print("[b red]digpkg: failed to build mineral: gcc was not found![/]") console.print("[b red]digpkg: failed to build mineral: gcc was not found![/]")
sys.exit(1) sys.exit(1)
@@ -36,6 +39,10 @@ def build_mineral(args):
# use gcc to compile the mineral # use gcc to compile the mineral
with console.status("Compiling", spinner="bouncingBall", spinner_style="green") as status: with console.status("Compiling", spinner="bouncingBall", spinner_style="green") as status:
c_files = find_c_files(args.folder_path) c_files = find_c_files(args.folder_path)
if len(c_files) == 0:
console.print("[b red]digpkg: failed to build mineral: no .c files found in the specified folder, are you sure you're compiling a mineral?[/]")
sys.exit(1)
if subprocess.run([ if subprocess.run([
"gcc", "gcc",
@@ -102,7 +109,10 @@ def build(args):
f.write("# mylib\n") f.write("# mylib\n")
f.write("Introduce your module here!\n\nThis file will serve as an index page for all your docs.\n\n") f.write("Introduce your module here!\n\nThis file will serve as an index page for all your docs.\n\n")
f.write("## Subtitle (use this for categories)\n") f.write("## Subtitle (use this for categories)\n")
f.write("- [mylib_MyFunction](docs/my_function.md)") f.write("- [mylib_MyFunction](docs/my_function.md)\n\n")
f.write("## Changelog\n")
f.write("### v0.0.1 (latest)\n")
f.write("- Initial release.\n")
console.print("[:white_check_mark:] Generated a new package for you!") console.print("[:white_check_mark:] Generated a new package for you!")

View File

@@ -3,7 +3,10 @@ import os, sys
from rich.console import Console from rich.console import Console
from textual.app import App, ComposeResult from textual.app import App, ComposeResult
from textual.widgets import MarkdownViewer, Header, Footer from textual.widgets import MarkdownViewer, Header, Footer, Input, Button
from textual.containers import Horizontal
from textual_autocomplete import PathAutoComplete
from textual import on
console = Console() console = Console()
@@ -13,9 +16,45 @@ class DocsApp(App):
TITLE = "Digpkg Docs" TITLE = "Digpkg Docs"
SUB_TITLE = "made with ❤️ by SpookyDervish" SUB_TITLE = "made with ❤️ by SpookyDervish"
CSS = """
#search {
margin: 1;
width: 1fr;
}
#back {
margin-top: 1;
margin-left: 1;
}
#bottom {
height: 5;
}
"""
def __init__(self, inital_markdown_path: str): def __init__(self, inital_markdown_path: str):
super().__init__() super().__init__()
self.inital_markdown_path = inital_markdown_path self.inital_markdown_path = inital_markdown_path
self.docs_folder = os.path.join(os.path.dirname(self.inital_markdown_path), "docs")
async def on_input_submitted(self, event: Input.Submitted):
if event.input.id == "search":
if not os.path.isdir(self.docs_folder):
return
file_path = os.path.join(self.docs_folder, event.input.value)
if os.path.isfile(file_path):
event.input.clear()
event.input.focus()
await self.query_one(MarkdownViewer).go(file_path)
else:
self.notify("That file wasn't found.", title="Uh oh", severity="error")
async def on_button_pressed(self, event: Button.Pressed):
if event.button.id == "back":
await self.query_one(MarkdownViewer).back()
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
with open(self.inital_markdown_path, "r") as f: with open(self.inital_markdown_path, "r") as f:
@@ -23,6 +62,22 @@ class DocsApp(App):
yield Header() yield Header()
yield MarkdownViewer(markdown) yield MarkdownViewer(markdown)
with Horizontal(id="bottom"):
yield Button(label="Back", id="back", flat=True, variant="error")
search_input = Input(id="search", placeholder="Search . . .")
yield search_input
if os.path.isdir(self.docs_folder):
yield PathAutoComplete(
search_input,
path=self.docs_folder
)
else:
search_input.disabled = True
search_input.tooltip = "This mineral doesn't have a docs folder and can't be searched."
yield Footer() yield Footer()

View File

@@ -29,7 +29,7 @@ def parse_arguments():
# publish command # publish command
publish_command = sub_parsers.add_parser(name="publish", description="publish a package to the repository") publish_command = sub_parsers.add_parser(name="publish", description="publish a package to the repository")
publish_command.add_argument("name", help="name and version of the package") #publish_command.add_argument("name", help="name and version of the package")
publish_command.add_argument("folder_path", help="path to the folder that will be uploaded") publish_command.add_argument("folder_path", help="path to the folder that will be uploaded")
# remove command # remove command

View File

@@ -1,3 +1,4 @@
import configparser
import tarfile import tarfile
import tempfile import tempfile
import os, sys import os, sys
@@ -13,14 +14,8 @@ console = Console()
def publish(args): def publish(args):
if not "@" in args.name: mineral_name = os.path.basename(args.folder_path)
console.print(f"[b red]digpkg: failed to publish mineral: please include the version number in the package name. e.g: request@1.0.0")
sys.exit(1)
split_name = args.name.split("@")
mineral_name = split_name[0]
version = split_name[1]
# sanity checks # sanity checks
if not os.path.isdir(args.folder_path): if not os.path.isdir(args.folder_path):
console.print(f"[b red]digpkg: failed to publish mineral: \"{args.folder_path}\" is not a directory") console.print(f"[b red]digpkg: failed to publish mineral: \"{args.folder_path}\" is not a directory")
@@ -31,6 +26,10 @@ def publish(args):
if os.path.basename(os.path.normpath(args.folder_path)).endswith("_build"): if os.path.basename(os.path.normpath(args.folder_path)).endswith("_build"):
console.print(f"\n[b yellow]You didn't remove the \"_build\" suffix from your mineral's folder name!\n\nIf this is intentional you can ignore this message, however it is bad practice.\nIf this is not intentional, you will be unable to install your package properly using dig.[/]") console.print(f"\n[b yellow]You didn't remove the \"_build\" suffix from your mineral's folder name!\n\nIf this is intentional you can ignore this message, however it is bad practice.\nIf this is not intentional, you will be unable to install your package properly using dig.[/]")
config_parser = configparser.ConfigParser()
config_parser.read(os.path.join(args.folder_path, "mineral.ini"))
version = config_parser["package"]["version"]
# ask for user and pass # ask for user and pass
console.print("[b]Please authenticate.\n[/]") console.print("[b]Please authenticate.\n[/]")
try: try:

BIN
mineral.tar Normal file

Binary file not shown.

View File

@@ -2,11 +2,12 @@ from setuptools import setup, find_packages
setup( setup(
name="digpkg", name="digpkg",
version="1.0", version="1.1",
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
"textual>=7.3.0", "textual>=7.3.0",
"requests>=2.32.5" "requests>=2.32.5",
"textual-autocomplete>=4.0.6"
], ],
entry_points={ entry_points={
"console_scripts": [ "console_scripts": [

4
test.grnd Normal file
View File

@@ -0,0 +1,4 @@
extern "math"
call !math_RandomDouble 1.0 10.0 &var
println $var