From cea023daab60e931f53c5a2e08fad6badcbfdaff Mon Sep 17 00:00:00 2001 From: sharktide Date: Sat, 12 Apr 2025 17:11:26 -0400 Subject: [PATCH 1/9] Add support for repyconfig.toml (1.2.0) --- pyproject.toml | 2 +- repyconfig.toml | 3 ++ restructuredpython.egg-info/PKG-INFO | 4 +- restructuredpython/restructuredpython.py | 58 ++++++++++++++++++------ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 repyconfig.toml 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..bd73c0a 100644 --- a/restructuredpython/restructuredpython.py +++ b/restructuredpython/restructuredpython.py @@ -255,23 +255,56 @@ 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) - with open(input_file, 'r') as f: - source_code = f.read() + compile_value = data["config"]["compile"] + exclude_files = data["config"]["exclude"] + 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() - header_code, code_without_includes = process_includes( - source_code, input_file) + header_code_z, code_without_includes_z = process_includes(source_code_z, file_path_z) - python_code = parse_repython(code_without_includes) + python_code_z = parse_repython(code_without_includes_z) - final_code = header_code + python_code + final_code_z = header_code_z + python_code_z - output_file = os.path.splitext(input_file)[0] + '.py' + output_file_z = os.path.splitext(file_path_z)[0] + '.py' - with open(output_file, 'w') as f: - f.write(final_code) + 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() - print(f"Successfully compiled {input_file} to {output_file}") + header_code, code_without_includes = process_includes( + source_code, input_file) + + python_code = parse_repython(code_without_includes) + + final_code = header_code + python_code + + 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 +336,4 @@ def launch(): if __name__ == "__main__": - main(1) - -if __name__ == "__launch__": - main(2) + main() From dd68f77c317913638b1663cccf9b954b86550898 Mon Sep 17 00:00:00 2001 From: Rihaan Meher Date: Sun, 13 Apr 2025 10:41:29 -0400 Subject: [PATCH 2/9] Update restructuredpython.py for error handling --- restructuredpython/restructuredpython.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/restructuredpython/restructuredpython.py b/restructuredpython/restructuredpython.py index bd73c0a..5279c5c 100644 --- a/restructuredpython/restructuredpython.py +++ b/restructuredpython/restructuredpython.py @@ -260,9 +260,16 @@ def main(): import fnmatch with open(input_file, "rb") as file: data = toml.load(file) - - compile_value = data["config"]["compile"] - exclude_files = data["config"]["exclude"] + 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 = [] From bb364a84cd3b0b2cfb4d60e5e5a0224eabdb9687 Mon Sep 17 00:00:00 2001 From: Rihaan Meher Date: Tue, 15 Apr 2025 17:37:10 +0200 Subject: [PATCH 3/9] Update conf.py --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'] From 556ae7bd7d97b29b5a2836277af8cfc7a6d976fc Mon Sep 17 00:00:00 2001 From: Rihaan Meher Date: Tue, 15 Apr 2025 18:16:50 +0200 Subject: [PATCH 4/9] Update index.rst --- docs/source/index.rst | 1 + 1 file changed, 1 insertion(+) 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 ------------- From c7e61c885da1d4811a4f5ef7ffc169ce3098cda0 Mon Sep 17 00:00:00 2001 From: Rihaan Meher Date: Tue, 15 Apr 2025 19:10:17 +0200 Subject: [PATCH 5/9] Create repyconfig.toml.rst (Part 1) --- docs/source/reference/repyconfig.toml.rst | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docs/source/reference/repyconfig.toml.rst diff --git a/docs/source/reference/repyconfig.toml.rst b/docs/source/reference/repyconfig.toml.rst new file mode 100644 index 0000000..a463a34 --- /dev/null +++ b/docs/source/reference/repyconfig.toml.rst @@ -0,0 +1,28 @@ +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): Contains information about what files to compile +* ``"all"`` From cd4c6075e6937fe3a394efb290c35c69f1c82bf5 Mon Sep 17 00:00:00 2001 From: Rihaan Meher Date: Tue, 15 Apr 2025 19:22:11 +0200 Subject: [PATCH 6/9] Update repyconfig.toml.rst --- docs/source/reference/repyconfig.toml.rst | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/source/reference/repyconfig.toml.rst b/docs/source/reference/repyconfig.toml.rst index a463a34..aa17d88 100644 --- a/docs/source/reference/repyconfig.toml.rst +++ b/docs/source/reference/repyconfig.toml.rst @@ -18,11 +18,17 @@ 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 +- ``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): Contains information about what files to compile -* ``"all"`` +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", ...]`` From 65700ab77b54212f62ca52dd78875bf645977e3a Mon Sep 17 00:00:00 2001 From: sharktide Date: Tue, 22 Apr 2025 08:06:27 -0400 Subject: [PATCH 7/9] Add docs for 1.2.0 --- docs/source/reference/repyconfig.toml.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/source/reference/repyconfig.toml.rst b/docs/source/reference/repyconfig.toml.rst index aa17d88..5719f8e 100644 --- a/docs/source/reference/repyconfig.toml.rst +++ b/docs/source/reference/repyconfig.toml.rst @@ -10,11 +10,11 @@ Introduced in 1.2.0, it has a very simple schema but will be expanded on jn futu Example schema: -.. code-block::toml +.. code-block:: toml -[config] -compile = "all" -exclude = ["./tests/*", "./docs/*"] + [config] + compile = "all" + exclude = ["./tests/*", "./docs/*"] Explanation: @@ -32,3 +32,5 @@ Section ``config`` (1/1): Contains main information for the compiler 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. From 7221b6fd7534f5bdd36286e3e10dcc4eafd8e751 Mon Sep 17 00:00:00 2001 From: sharktide Date: Tue, 22 Apr 2025 12:30:02 -0400 Subject: [PATCH 8/9] Rename repyconfig.toml.rst to repyconfig.rst --- docs/source/reference/{repyconfig.toml.rst => repyconfig.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/source/reference/{repyconfig.toml.rst => repyconfig.rst} (100%) diff --git a/docs/source/reference/repyconfig.toml.rst b/docs/source/reference/repyconfig.rst similarity index 100% rename from docs/source/reference/repyconfig.toml.rst rename to docs/source/reference/repyconfig.rst From 16fbf1c5598c2079bf91bc5b8c6518768a859fdb Mon Sep 17 00:00:00 2001 From: sharktide Date: Tue, 22 Apr 2025 12:34:01 -0400 Subject: [PATCH 9/9] Rename repyconfig.rst back to repyconfig.toml.rst and update toctree in index.rst for reference --- docs/source/reference/index.rst | 1 + docs/source/reference/{repyconfig.rst => repyconfig.toml.rst} | 0 2 files changed, 1 insertion(+) rename docs/source/reference/{repyconfig.rst => repyconfig.toml.rst} (100%) 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.rst b/docs/source/reference/repyconfig.toml.rst similarity index 100% rename from docs/source/reference/repyconfig.rst rename to docs/source/reference/repyconfig.toml.rst