diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ced66653965..dc12cea1fbb3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,6 @@ repos: -- repo: https://github.com/psf/black +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.7 hooks: - rev: 22.6.0 - hooks: - - id: black -- repo: https://github.com/pycqa/pylint - rev: v2.14.5 - hooks: - - id: pylint -- repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.0 - hooks: - - id: prettier - \ No newline at end of file + - id: ruff # run the linter + args: [ --fix ] diff --git a/extensions/fortran_playground.py b/extensions/fortran_playground.py index ac76acf47855..404da7539ada 100644 --- a/extensions/fortran_playground.py +++ b/extensions/fortran_playground.py @@ -7,15 +7,14 @@ import os -comp_error = ["","Error","app/main.f90","

Bad Request

"] +comp_error = ["", "Error", "app/main.f90", "

Bad Request

"] class PlayCodeBlock(CodeBlock): - - def compile_and_execute_fortran(self,fortran_code): - code_hash = hashlib.md5(fortran_code.encode('utf-8')).hexdigest() + def compile_and_execute_fortran(self, fortran_code): + code_hash = hashlib.md5(fortran_code.encode("utf-8")).hexdigest() cache_filename = f"build/fortran_output_{code_hash}.txt" - filename=f"build/code_{code_hash}.f90" + filename = f"build/code_{code_hash}.f90" # Check if the output is already cached if os.path.exists(cache_filename): @@ -26,15 +25,22 @@ def compile_and_execute_fortran(self,fortran_code): f.write(fortran_code) compile_command = ["gfortran", filename, "-o", f"./build/{code_hash}.out"] - compile_result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + compile_result = subprocess.run( + compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) with open(cache_filename, "w") as f: - if compile_result.returncode == 0: print("Compilation successful!") - + execute_command = [f"./build/{code_hash}.out"] - execute_result = subprocess.run(execute_command, input="", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + execute_result = subprocess.run( + execute_command, + input="", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) if execute_result.returncode == 0: print("Execution successful!") @@ -54,17 +60,19 @@ def compile_and_execute_fortran(self,fortran_code): def run(self): document = self.state.document - code = '\n'.join(self.content) + code = "\n".join(self.content) location = self.state_machine.get_source_and_line(self.lineno) - linespec = self.options.get('emphasize-lines') + linespec = self.options.get("emphasize-lines") if linespec: try: nlines = len(self.content) hl_lines = parse_line_num_spec(linespec, nlines) if any(i >= nlines for i in hl_lines): - logger.warning(__('line number spec is out of range(1-%d): %r') % - (nlines, self.options['emphasize-lines']), - location=location) + logger.warning( + f"line number spec is out of range(1-{nlines:d}):" + f"{self.options['emphasize-lines']:r}", + location=location, + ) hl_lines = [x + 1 for x in hl_lines if x < nlines] except ValueError as err: @@ -72,31 +80,32 @@ def run(self): else: hl_lines = None - if 'dedent' in self.options: + if "dedent" in self.options: location = self.state_machine.get_source_and_line(self.lineno) lines = code.splitlines(True) - lines = dedent_lines(lines, self.options['dedent'], location=location) - code = ''.join(lines) - - literal: Element = nodes.literal_block(code, code) - if 'linenos' in self.options or 'lineno-start' in self.options: - literal['linenos'] = True - literal['classes'] += self.options.get('class', []) - literal['force'] = 'force' in self.options + lines = dedent_lines(lines, self.options["dedent"], location=location) + code = "".join(lines) + + literal = nodes.literal_block(code, code) + if "linenos" in self.options or "lineno-start" in self.options: + literal["linenos"] = True + literal["classes"] += self.options.get("class", []) + literal["force"] = "force" in self.options if self.arguments: # highlight language specified - literal['language'] = self.arguments[0] + literal["language"] = self.arguments[0] else: # no highlight language specified. Then this directive refers the current # highlight setting via ``highlight`` directive or ``highlight_language`` # configuration. - literal['language'] = self.env.temp_data.get('highlight_language', - self.config.highlight_language) - extra_args = literal['highlight_args'] = {} + literal["language"] = self.env.temp_data.get( + "highlight_language", self.config.highlight_language + ) + extra_args = literal["highlight_args"] = {} if hl_lines is not None: - extra_args['hl_lines'] = hl_lines - if 'lineno-start' in self.options: - extra_args['linenostart'] = self.options['lineno-start'] + extra_args["hl_lines"] = hl_lines + if "lineno-start" in self.options: + extra_args["linenostart"] = self.options["lineno-start"] self.set_source_info(literal) caption = f"Fortran Playground" try: @@ -104,23 +113,21 @@ def run(self): except ValueError as exc: return [document.reporter.warning(exc, line=self.lineno)] if "end program" not in code: - code = code+"\nend program" + code = code + "\nend program" resp = self.compile_and_execute_fortran(code) if any(i in str(resp) for i in comp_error): - #print("original") + # print("original") return [*super().run()] else: - #print("with link") + # print("with link") return [literal] - def setup(app): - app.add_directive('play-code-block', PlayCodeBlock) + app.add_directive("play-code-block", PlayCodeBlock) return { - 'version': '0.1', - 'parallel_read_safe': True, - 'parallel_write_safe': True, + "version": "0.1", + "parallel_read_safe": True, + "parallel_write_safe": True, } - diff --git a/fortran_package.py b/fortran_package.py index e13c6c75aa68..6cc034961ba5 100644 --- a/fortran_package.py +++ b/fortran_package.py @@ -29,7 +29,7 @@ for i in fortran_index: try: fortran_index_tags += i["tags"].split() - except: + except Exception: pass for j in categories: diff --git a/requirements.txt b/requirements.txt index 0d77fab647ef..b6f0689df19a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,12 +3,11 @@ ablog==0.11.12 pydata-sphinx-theme==0.16.1 myst-parser==4.0.1 sphinx_design==0.6.1 -sphinx_copybutton==0.5.2 -sphinx-jinja==2.0.2 -jinja2==3.1.6 +sphinx_copybutton==0.5.2 +sphinx-jinja==2.0.2 +jinja2==3.1.6 +ruff==0.14.9 requests==2.32.5 -black==25.9.0 -pylint==4.0.0 pre-commit==4.3.0 sphinx-sitemap==2.9.0 sphinx-favicon==1.0.1 diff --git a/source/conf.py b/source/conf.py index 1ee573a2ace4..2b4fa23efd0c 100644 --- a/source/conf.py +++ b/source/conf.py @@ -37,7 +37,6 @@ if not all(data.exists() for data in data_files.values()): sys.path.insert(0, str(root.absolute())) # pylint: disable=import-error, unused-import - import fortran_package with open(data_files["fortran-learn"], "r", encoding="utf-8") as f: conf = json.load(f) @@ -72,7 +71,6 @@ "sphinx_jinja", "fortran_playground", "sphinx_favicon", - ] myst_enable_extensions = [ @@ -132,10 +130,10 @@ favicons = [ { - "rel": "icon", - "sizes": "256x256", - "href": "images/favicon.ico", - }, + "rel": "icon", + "sizes": "256x256", + "href": "images/favicon.ico", + }, ] html_theme_options = { @@ -143,14 +141,14 @@ "show_nav_level": 1, "show_toc_level": 0, "navbar_align": "right", - "navbar_start": ["navbar-logo","theme-switcher.html"], + "navbar_start": ["navbar-logo", "theme-switcher.html"], "switcher": { "json_url": "https://fortran-lang.org/_static/data.json", # shifted to custom local switcher "version_match": language, }, "primary_sidebar_end": [], "secondary_sidebar_items": ["inpage_toc.html"], - "navbar_end": ["navbar-icon-links","version-switcher"], + "navbar_end": ["navbar-icon-links", "version-switcher"], "search_bar_text": "Search", "icon_links": [ { @@ -194,7 +192,7 @@ "packages": [], "community": [], "packages/**": [], - "community/governance":[], + "community/governance": [], } html_title = "Fortran Programming Language" html_logo = "_static/images/fortran-logo-256x256.png"