Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Introduce ruff code-format style #934

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/unix_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@
shell: bash -el {0}
run: |
pip install --verbose '.[opt, parallel, test, gui]'
- name: Lint with flake8
- name: Lint with ruff
shell: bash -el {0}
run: |
flake8 --count hnn_core
ruff check --no-fix
- name: Check formatting with ruff
shell: bash -el {0}
run: |
ruff format --check
- name: Test with pytest
shell: bash -el {0}
run: |
python -m pytest ./hnn_core/tests/ --cov=hnn_core --cov-report=xml
- name: Upload coverage to Codecov
shell: bash -el {0}
run: |
bash <(curl -s https://codecov.io/bash) -f ./coverage.xml
bash <(curl -s https://codecov.io/bash) -f ./coverage.xml
26 changes: 12 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@

all: modl

modl:
cd hnn_core/mod/ && nrnivmodl

clean :
rm -rf hnn_core/mod/x86_64/*

check-manifest:
check-manifest

test: flake
pytest .
format:
ruff format

lint:
ruff check

flake:
@if command -v flake8 > /dev/null; then \
echo "Running flake8"; \
flake8 hnn_core --count; \
else \
echo "flake8 not found, please install it!"; \
exit 1; \
fi;
@echo "flake8 passed"
modl:
cd hnn_core/mod/ && nrnivmodl

test:
ruff format --check
ruff check --no-fix
pytest .
46 changes: 24 additions & 22 deletions dev_scripts/convert_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def download_folder_contents(owner, repo, path):
-------
Path to temporary directory or None
"""
url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
url = f'https://api.github.com/repos/{owner}/{repo}/contents/{path}'

try:
response = requests.get(url)
Expand All @@ -47,7 +47,7 @@ def download_folder_contents(owner, repo, path):
file_name = os.path.join(temp_dir, item['name'])
with open(file_name, 'wb') as f:
f.write(requests.get(download_url).content)
print(f"Downloaded: {file_name}")
print(f'Downloaded: {file_name}')
return temp_dir


Expand All @@ -70,36 +70,38 @@ def convert_param_files_from_repo(owner, repo, repo_path, local_path):
# Download param files
temp_dir = download_folder_contents(owner, repo, repo_path)
# Get list of json and param files
file_list = [Path(temp_dir, f)
for f in os.listdir(temp_dir)
if f.endswith('.param') or f.endswith('.json')]
file_list = [
Path(temp_dir, f)
for f in os.listdir(temp_dir)
if f.endswith('.param') or f.endswith('.json')
]
# Assign output location and names
output_dir = Path(local_path)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
output_filenames = [Path(output_dir, f.name.split('.')[0])
for f in file_list]
output_filenames = [Path(output_dir, f.name.split('.')[0]) for f in file_list]

[convert_to_json(file, outfile)
for (file, outfile) in zip(file_list, output_filenames)]
[
convert_to_json(file, outfile)
for (file, outfile) in zip(file_list, output_filenames)
]

# Delete downloads
shutil.rmtree(temp_dir)


if __name__ == '__main__':

# hnn param files
convert_param_files_from_repo(owner='jonescompneurolab',
repo='hnn',
repo_path='param',
local_path=(root_path /
'network_configuration'),
)
convert_param_files_from_repo(
owner='jonescompneurolab',
repo='hnn',
repo_path='param',
local_path=(root_path / 'network_configuration'),
)
# hnn-core json files
convert_param_files_from_repo(owner='jonescompneurolab',
repo='hnn-core',
repo_path='hnn_core/param',
local_path=(root_path /
'network_configuration'),
)
convert_param_files_from_repo(
owner='jonescompneurolab',
repo='hnn-core',
repo_path='hnn_core/param',
local_path=(root_path / 'network_configuration'),
)
80 changes: 39 additions & 41 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
import os
import sys

# sys.path.insert(0, os.path.abspath('.'))
import sphinx_gallery
from sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder

import sphinx_bootstrap_theme
Expand Down Expand Up @@ -57,7 +57,7 @@
'sphinx.ext.intersphinx',
'numpydoc',
'sphinx_copybutton',
'gh_substitutions' # custom extension, see ./sphinxext/gh_substitutions.py
'gh_substitutions', # custom extension, see ./sphinxext/gh_substitutions.py
]

# generate autosummary even if no references
Expand All @@ -68,7 +68,7 @@
default_role = 'autolink' # XXX silently allows bad syntax, someone should fix

# Sphinx-Copybutton configuration
copybutton_prompt_text = r">>> |\.\.\. |\$ "
copybutton_prompt_text = r'>>> |\.\.\. |\$ '
copybutton_prompt_is_regexp = True

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -113,13 +113,13 @@
html_theme_options = {
'navbar_sidebarrel': False,
'navbar_links': [
("Examples", "auto_examples/index"),
("API", "api"),
("Glossary", "glossary"),
("What's new", "whats_new"),
("GitHub", "https://github.com/jonescompneurolab/hnn-core", True)
('Examples', 'auto_examples/index'),
('API', 'api'),
('Glossary', 'glossary'),
("What's new", 'whats_new'),
('GitHub', 'https://github.com/jonescompneurolab/hnn-core', True),
],
'bootswatch_theme': "yeti"
'bootswatch_theme': 'yeti',
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down Expand Up @@ -150,15 +150,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -168,19 +165,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'hnn-core.tex', 'hnn-core Documentation',
'Mainak Jas', 'manual'),
(master_doc, 'hnn-core.tex', 'hnn-core Documentation', 'Mainak Jas', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'hnn-core', 'hnn-core Documentation',
[author], 1)
]
man_pages = [(master_doc, 'hnn-core', 'hnn-core Documentation', [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -189,17 +182,23 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'hnn-core', 'hnn-core Documentation',
author, 'hnn-core', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
'hnn-core',
'hnn-core Documentation',
author,
'hnn-core',
'One line description of project.',
'Miscellaneous',
),
]

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'mne': ('https://mne.tools/dev', None),
'numpy': ('https://numpy.org/devdocs', None),
'scipy': ('https://scipy.github.io/devdocs', None),
'matplotlib': ('https://matplotlib.org', None)
'matplotlib': ('https://matplotlib.org', None),
}
intersphinx_timeout = 5

Expand All @@ -209,7 +208,7 @@
'https://doi.org/10.1152/jn.00535.2009',
'https://doi.org/10.1152/jn.00122.2010',
'https://doi.org/10.1101/2021.04.16.440210',
'https://groups.google.com/g/hnnsolver'
'https://groups.google.com/g/hnnsolver',
]

# Resolve binder filepath_prefix. From the docs:
Expand All @@ -224,29 +223,28 @@
filepath_prefix = 'v{}'.format(version)

sphinx_gallery_conf = {
'first_notebook_cell': ("import pyvista as pv\n"
"from mne.viz import set_3d_backend\n"
"set_3d_backend('notebook')\n"
"pv.set_jupyter_backend('client')"
),
'first_notebook_cell': (
'import pyvista as pv\n'
'from mne.viz import set_3d_backend\n'
"set_3d_backend('notebook')\n"
"pv.set_jupyter_backend('client')"
),
'doc_module': 'hnn_core',
# path to your examples scripts
'examples_dirs': '../examples',
# path where to save gallery generated examples
'gallery_dirs': 'auto_examples',
'backreferences_dir': 'generated',
'reference_url': {
'hnn_core': None
},
'reference_url': {'hnn_core': None},
'within_subsection_order': ExampleTitleSortKey,
'subsection_order': ExplicitOrder(['../examples/workflows/',
'../examples/howto/']),
'binder': {'org': 'jonescompneurolab',
'repo': 'hnn-core',
'branch': 'gh-pages',
'binderhub_url': 'https://mybinder.org',
'filepath_prefix': filepath_prefix,
'notebooks_dir': 'notebooks',
'dependencies': 'Dockerfile'
}
'subsection_order': ExplicitOrder(['../examples/workflows/', '../examples/howto/']),
'binder': {
'org': 'jonescompneurolab',
'repo': 'hnn-core',
'branch': 'gh-pages',
'binderhub_url': 'https://mybinder.org',
'filepath_prefix': filepath_prefix,
'notebooks_dir': 'notebooks',
'dependencies': 'Dockerfile',
},
}
1 change: 1 addition & 0 deletions doc/sphinxext/gh_substitutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
https://doughellmann.com/blog/2010/05/09/defining-custom-roles-in-sphinx/

"""

from docutils.nodes import reference
from docutils.parsers.rst.roles import set_classes

Expand Down
Loading
Loading