diff --git a/fileio/SUMMARY.md b/fileio/SUMMARY.md new file mode 100644 index 0000000..362240e --- /dev/null +++ b/fileio/SUMMARY.md @@ -0,0 +1,7 @@ +# fileio +Perform file system operations. + +## Files +- [file_Read](docs/read.md) +- [file_Write](docs/write.md) + diff --git a/fileio/docs/read.md b/fileio/docs/read.md new file mode 100644 index 0000000..600ea90 --- /dev/null +++ b/fileio/docs/read.md @@ -0,0 +1,17 @@ +# file_Read +Open a file and return the contents in `r` mode. + +## Arguments +- path (string): Path to the file you want to read + +## Returns +- content (string): Contents of the file + +## Raises +- `FileError`: Raised if the file doesn't exist or there was an error allocating memory for the file + +## Example +```python +call !file_Read "my_file.txt" &contents +println $contents +``` diff --git a/fileio/docs/write.md b/fileio/docs/write.md new file mode 100644 index 0000000..f74ad32 --- /dev/null +++ b/fileio/docs/write.md @@ -0,0 +1,17 @@ +# file_Write +Open a file and overwrite its contents with the provided string in `w` mode. + +## Arguments +- path (string): Path to the file you want to write to + +## Returns +- success (boolean): Whether writing to the file succeeded or not + +## Raises +- `FileError`: Raised if the file doesn't exist + +## Example +```python +call !file_Read "my_file.txt" &contents +println $contents +``` diff --git a/fileio/mineral.ini b/fileio/mineral.ini new file mode 100644 index 0000000..ce5e55b --- /dev/null +++ b/fileio/mineral.ini @@ -0,0 +1,5 @@ +[package] +description=Provides file I/O support for Ground +version=1.2.0 + +[dependencies] diff --git a/mineral.tar b/mineral.tar new file mode 100644 index 0000000..185da08 Binary files /dev/null and b/mineral.tar differ diff --git a/src/build.py b/src/build.py index ed0defc..7ed687b 100644 --- a/src/build.py +++ b/src/build.py @@ -17,7 +17,7 @@ def find_c_files(path: str): for entry in os.listdir(path): full_path = os.path.join(path, entry) if os.path.isdir(full_path): - list_files_recursive(full_path) + find_c_files(full_path) else: if full_path.endswith(".c"): paths.append(full_path) @@ -29,6 +29,9 @@ def build_mineral(args): if not os.path.isdir(args.folder_path): console.print("[b red]digpkg: failed to build mineral: specified folder doesn't exist![/]") 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"): console.print("[b red]digpkg: failed to build mineral: gcc was not found![/]") sys.exit(1) @@ -36,6 +39,11 @@ def build_mineral(args): # use gcc to compile the mineral with console.status("Compiling", spinner="bouncingBall", spinner_style="green") as status: c_files = find_c_files(args.folder_path) + + print(len(c_files)) + 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([ "gcc", @@ -102,7 +110,10 @@ def build(args): 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("## 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!") diff --git a/src/main.py b/src/main.py index 7c7f8c7..27f8090 100644 --- a/src/main.py +++ b/src/main.py @@ -29,7 +29,7 @@ def parse_arguments(): # publish command 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") # remove command diff --git a/src/publish.py b/src/publish.py index 1683fd4..276b88d 100644 --- a/src/publish.py +++ b/src/publish.py @@ -1,3 +1,4 @@ +import configparser import tarfile import tempfile import os, sys @@ -13,14 +14,8 @@ console = Console() def publish(args): - if not "@" in args.name: - 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] - + mineral_name = os.path.basename(args.folder_path) + # sanity checks 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") @@ -31,6 +26,10 @@ def publish(args): 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.[/]") + 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 console.print("[b]Please authenticate.\n[/]") try: diff --git a/stdlib/SUMMARY.md b/stdlib/SUMMARY.md new file mode 100644 index 0000000..d8f5cdc --- /dev/null +++ b/stdlib/SUMMARY.md @@ -0,0 +1,4 @@ +# stdlib +The standard library for Ground. + +This mineral has no functions because it is intended to just be a collection of minerals needed to do anything useful in Ground. diff --git a/stdlib/mineral.ini b/stdlib/mineral.ini new file mode 100644 index 0000000..9abce85 --- /dev/null +++ b/stdlib/mineral.ini @@ -0,0 +1,10 @@ +[package] +description = Standard library for Ground. +version = 1.2.0 +config_version = 1 + +[dependencies] +math=1.2.0 +request=1.2.0 +fileio=1.2.0 +