diff --git a/docs/source/conf.py b/docs/source/conf.py index b8a4c78..dd8b7a7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,7 +10,7 @@ copyright = '2025, Rihaan Meher' author = 'Rihaan Meher' -release = '1.1.0' +release = '1.2.0' html_favicon = "_static/icon.png" # -- General configuration --------------------------------------------------- @@ -25,4 +25,4 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = 'furo' -html_static_path = ['_static'] \ No newline at end of file +html_static_path = ['_static'] diff --git a/docs/source/index.rst b/docs/source/index.rst index c9f1d6f..5a0c034 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -30,6 +30,7 @@ Features * **Header Files** In reStructuredPython, enjoy having the ability to create header files, similar to C++ for easier, and more organized development. View the `syntax `_ guide for more details. * **Seamless Compilation:** reStructuredPython code compiles directly into Python, ensuring compatibility with existing Python libraries and frameworks. * **Enhanced Readability:** The syntax enhancements which include multiline comments aim to improve code readability and reduce verbosity. +* **repyconfig.toml:** Easily control the build of your projects with a repyconfig.toml Documentation ------------- diff --git a/docs/source/reference/index.rst b/docs/source/reference/index.rst index a65c7da..f17384e 100644 --- a/docs/source/reference/index.rst +++ b/docs/source/reference/index.rst @@ -8,3 +8,4 @@ The reference section provides detailed information about the built-in functions Syntax_Guide Builtin_Decorators + repyconfig.toml diff --git a/docs/source/reference/repyconfig.toml.rst b/docs/source/reference/repyconfig.toml.rst new file mode 100644 index 0000000..5719f8e --- /dev/null +++ b/docs/source/reference/repyconfig.toml.rst @@ -0,0 +1,36 @@ +repyconfig.toml Configuration Guide +=================================== + +The repyconfig.toml can be used to alter the default settings of the compiler in the following scenarios: +* If it is called via ``repy path/to/repyconfig.toml`` + +*Note: While the repyconfig.toml does not have to be in the root directory, all paths in the file must be relative to the directory of command execution, and must follow the schema such as for relative paths:* ``./path/to/file.repy``. *No backslashes allowed* + +Introduced in 1.2.0, it has a very simple schema but will be expanded on jn future versions. + +Example schema: + +.. code-block:: toml + + [config] + compile = "all" + exclude = ["./tests/*", "./docs/*"] + +Explanation: + +- ``compile = "all"``: Will compile all files in the root directory except those files/dirs mentioned in ``exclude`` +- ``exclude = ["./tests/*", "./docs/*"]`` Will not compile these files/directories + +Complete reference + +Section ``config`` (1/1): Contains main information for the compiler + + Key ``compile`` (1/2) Type: str: Contains information about what files to compile + + ``"all"``: Compiles all files in the given diretory, except those listed in the key ``exclude`` + + Key ``exclude`` (2/2) Type: List: A list of paths and directories to exclude. + + Written as ``["./path/to/dir/", "./path/to/file.repy", ...]`` + +More items coming soon. diff --git a/pyproject.toml b/pyproject.toml index 6d6221a..7648652 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "restructuredpython" -version = "1.1.0" +version = "1.2.0" description = "A superset of Python with js-like syntax" authors = [{name = "Rihaan Meher", email = "meherrihaan@gmail.com"}] license = {text = "MIT"} diff --git a/repyconfig.toml b/repyconfig.toml new file mode 100644 index 0000000..b44600d --- /dev/null +++ b/repyconfig.toml @@ -0,0 +1,3 @@ +[config] +compile = "all" +exclude = ["./tests/*", "./docs/*"] diff --git a/restructuredpython.egg-info/PKG-INFO b/restructuredpython.egg-info/PKG-INFO index 8b05a45..4dd5c6e 100644 --- a/restructuredpython.egg-info/PKG-INFO +++ b/restructuredpython.egg-info/PKG-INFO @@ -1,11 +1,11 @@ Metadata-Version: 2.4 Name: restructuredpython -Version: 1.1.0 +Version: 1.2.0 Summary: A superset of Python with js-like syntax Author-email: Rihaan Meher License: MIT Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.19 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 diff --git a/restructuredpython/restructuredpython.py b/restructuredpython/restructuredpython.py index 9180048..5279c5c 100644 --- a/restructuredpython/restructuredpython.py +++ b/restructuredpython/restructuredpython.py @@ -255,23 +255,63 @@ def main(): if not os.path.exists(input_file): print(f"Error: The file {input_file} does not exist.") return + if input_file.endswith('repyconfig.toml'): + import tomllib as toml + import fnmatch + with open(input_file, "rb") as file: + data = toml.load(file) + try: + compile_value = data["config"]["compile"] + except: + compile_value = "null" + print("[WARNING] Error reading compile value from config") + try: + exclude_files = data["config"]["exclude"] + except: + exclude_files = [] + print("[WARNING] No excluded files found in config") + if compile_value == 'all': + extension = ".repy" + matching_files = [] + for dirpath, _, filenames in os.walk("."): + for filename in filenames: + if filename.lower().endswith(extension.lower()): + file_path_temp = os.path.join(dirpath, filename) + if any(fnmatch.fnmatch(file_path_temp, pattern) for pattern in exclude_files): + continue + matching_files.append(file_path_temp) + for file_path_z in matching_files: + with open(file_path_z, 'r') as z: + source_code_z = z.read() - with open(input_file, 'r') as f: - source_code = f.read() + header_code_z, code_without_includes_z = process_includes(source_code_z, file_path_z) - header_code, code_without_includes = process_includes( - source_code, input_file) + python_code_z = parse_repython(code_without_includes_z) - python_code = parse_repython(code_without_includes) + final_code_z = header_code_z + python_code_z - final_code = header_code + python_code + output_file_z = os.path.splitext(file_path_z)[0] + '.py' + + with open(output_file_z, 'w') as z: + z.write(final_code_z) + print(f"[DEBUG] Successfully compiled {file_path_z} to {output_file_z}") + else: + with open(input_file, 'r') as f: + source_code = f.read() + + header_code, code_without_includes = process_includes( + source_code, input_file) - output_file = os.path.splitext(input_file)[0] + '.py' + python_code = parse_repython(code_without_includes) - with open(output_file, 'w') as f: - f.write(final_code) + final_code = header_code + python_code - print(f"Successfully compiled {input_file} to {output_file}") + output_file = os.path.splitext(input_file)[0] + '.py' + + with open(output_file, 'w') as f: + f.write(final_code) + + print(f"[DEBUG] Successfully compiled {input_file} to {output_file}") def launch(): @@ -303,7 +343,4 @@ def launch(): if __name__ == "__main__": - main(1) - -if __name__ == "__launch__": - main(2) + main()