Skip to content

Commit

Permalink
Merge pull request #148 from NWChemEx/python_formatting
Browse files Browse the repository at this point in the history
Python Formatting
  • Loading branch information
jwaldrop107 authored Feb 13, 2024
2 parents 2185d0d + 95e2169 commit a25f8f5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/common_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
required: false
default: '.licenserc.yaml'
source_dir:
description: "Space seperated list of dirs to apply formatting to"
description: "Space seperated list of dirs to apply clang-format to"
type: string
required: false
default: 'include src tests'
Expand All @@ -55,6 +55,11 @@ on:
type: boolean
required: false
default: true
format_python:
description: "Whether or not to format python files"
type: boolean
required: false
default: true
secrets:
CMAIZE_GITHUB_TOKEN:
description: "Token passed to CMaize"
Expand All @@ -78,6 +83,10 @@ jobs:
token: ${{ secrets.CMAIZE_GITHUB_TOKEN }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-python@v2
if: inputs.format_python == true
with:
python-version: '3.x'
- name: Add license
if: inputs.config_file != ''
uses: apache/[email protected]
Expand All @@ -92,6 +101,12 @@ jobs:
extensions: 'hpp,cpp,ipp,h,c'
clangFormatVersion: 12
inplace: True
- name: Apply python formatting
if: inputs.format_python == true
run: |
pip install yapf
find . -name '*.py' -print0 | xargs -0 yapf -i
shell: bash
- name: Commit any changes
id: commit-changes
uses: EndBug/add-and-commit@v9
Expand Down
28 changes: 8 additions & 20 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.mathjax',
'sphinxcontrib.bibtex'
]
dir_path = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -86,9 +82,7 @@
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'vcs_pageview_mode' : 'edit'
}
html_theme_options = {'vcs_pageview_mode': 'edit'}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -105,21 +99,19 @@
#
# html_sidebars = {}


# Allows the edit on GitHub button to make editing the docs easier.
html_context = {
'display_github': True,
'github_user': 'NWChemEx',
'github_repo': '.github',
'github_version': 'master/docs/source/',
'display_github': True,
'github_user': 'NWChemEx',
'github_repo': '.github',
'github_version': 'master/docs/source/',
}

# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = project + 'doc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
Expand All @@ -140,7 +132,6 @@
# 'figure_align': 'htbp',
}


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------
Expand All @@ -153,11 +144,8 @@
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# -- Options for bibtex --------------------------------------------------------

bibtex_bibfiles = [
'bibliography/software.bib'
]
bibtex_bibfiles = ['bibliography/software.bib']
bibtex_reference_style = 'super'
bibtex_default_style = 'plain'
24 changes: 9 additions & 15 deletions scripts/make_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def strip_newline(block):
break
end -= 1

return block[start: end]
return block[start:end]


def write_code(block, lang):
Expand All @@ -36,7 +36,7 @@ def write_code(block, lang):
:param lang: The language of the code snippet
:return: A string suitable for printing in a reST file
"""
a_tab = " "*4
a_tab = " " * 4

parsed_block = strip_newline(block)

Expand Down Expand Up @@ -138,7 +138,7 @@ def parse_file(cc, filename):
else: # n-th line outside a comment block
if which_first is None:
which_first = False
if len(code) == 0: # If code came first, there's no array yet
if len(code) == 0: # If code came first, there's no array yet
code.append([])
code[-1].append(line)

Expand Down Expand Up @@ -179,9 +179,10 @@ def write_tutorial(name, lang, comments, code, first):

# Write the title of the tutorial
output = name + '\n'
output += '='*len(name) + "\n\n"
output += '=' * len(name) + "\n\n"

for i in range(n_second): # Loop over second because it is possibly shorter
for i in range(
n_second): # Loop over second because it is possibly shorter
if first:
output += write_comment(comments[i])
output += write_code(code[i], lang)
Expand Down Expand Up @@ -229,14 +230,8 @@ def make_tutorials(input_dir, output_dir):
"""

# Define the comment characters and name for each language
comment_chars = {".py": '#',
".hpp": "//",
".cpp" : "//",
".cmake": '#'}
lang = {".py": "python",
".hpp": "c++",
".cpp": "c++",
".cmake": "cmake"}
comment_chars = {".py": '#', ".hpp": "//", ".cpp": "//", ".cmake": '#'}
lang = {".py": "python", ".hpp": "c++", ".cpp": "c++", ".cmake": "cmake"}

# Make output directory if it does not exist
if not os.path.exists(output_dir):
Expand All @@ -250,7 +245,7 @@ def make_tutorials(input_dir, output_dir):

if os.path.isdir(input_file):
make_tutorials(input_file, os.path.join(output_dir, file_name))
file_names.append(os.path.join(file_name,"index"))
file_names.append(os.path.join(file_name, "index"))
continue

if extension not in lang: # Not a file we're supposed to parse
Expand All @@ -272,7 +267,6 @@ def make_tutorials(input_dir, output_dir):
# index_file.write(write_index(file_names))



# def main():
# docs_dir = os.path.dirname(os.path.realpath(__file__))
# root_dir = os.path.dirname(docs_dir)
Expand Down

0 comments on commit a25f8f5

Please sign in to comment.