Skip to content

Commit

Permalink
Merge branch 'develop-main' into use-absolute-path-import
Browse files Browse the repository at this point in the history
  • Loading branch information
emuemuJP committed May 1, 2023
2 parents 498aabc + 5fe7d05 commit 2e5c15f
Show file tree
Hide file tree
Showing 124 changed files with 2,107 additions and 1,941 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Python Linters
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'notebooks/**'
- 'frontend/**'
- 'sample_data/**'

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- run: python -m pip install flake8
- uses: liskin/gh-problem-matcher-wrap@d8afa2cfb66dd3f982b1950429e652bc14d0d7d2
with:
linters: flake8
run: flake8
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- run: python -m pip install isort
- uses: liskin/gh-problem-matcher-wrap@d8afa2cfb66dd3f982b1950429e652bc14d0d7d2
with:
linters: isort
run: isort --check --diff optinist
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__
.ipynb_checkpoints
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json
dist
/build
optinist/frontend
Expand Down
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort"
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
"frontend/build/**": true,
"build/**": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"esbonio.sphinx.confDir": ""
}
67 changes: 34 additions & 33 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import os
import sys
from datetime import datetime
sys.path.insert(0, os.path.abspath('../'))
from optinist.version import VERSION, VERSION_SHORT

sys.path.insert(0, os.path.abspath("../"))
from optinist.version import VERSION, VERSION_SHORT # noqa: E402

# -- Path setup --------------------------------------------------------------

Expand All @@ -20,17 +21,17 @@

# -- Project information -----------------------------------------------------

project = 'OptiNiSt'
project = "OptiNiSt"
copyright = f"{datetime.today().year}, OIST"
author = ''
author = ""
version = VERSION_SHORT
release = VERSION

# -- readthedocs -------------------------------------------------------------
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

# -- General configuration ---------------------------------------------------
master_doc = 'index'
master_doc = "index"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -40,15 +41,15 @@
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
'sphinx.ext.napoleon',
'sphinx.ext.coverage',
'sphinxcontrib.apidoc',
'sphinx_autodoc_typehints',
'myst_parser',
'sphinx.ext.autosectionlabel',
'sphinx.ext.autosummary',
'sphinx.ext.extlinks',
'sphinx.ext.autodoc.typehints'
"sphinx.ext.napoleon",
"sphinx.ext.coverage",
"sphinxcontrib.apidoc",
"sphinx_autodoc_typehints",
"myst_parser",
"sphinx.ext.autosectionlabel",
"sphinx.ext.autosummary",
"sphinx.ext.extlinks",
"sphinx.ext.autodoc.typehints",
]

# Tell myst-parser to assign header anchors for h1-h3.
Expand All @@ -57,12 +58,12 @@
suppress_warnings = ["myst.header"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'tests', '*test*']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "tests", "*test*"]

source_suffix = [".rst", ".md"]

Expand All @@ -71,31 +72,31 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# 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,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_logo = '_static/optinist.png'
html_favicon = '_static/favicon.ico'
html_static_path = ["_static"]
html_logo = "_static/optinist.png"
html_favicon = "_static/favicon.ico"

# disable document page source link
html_show_sourcelink = False

autosummary_generate = True

html_theme_options = {
'canonical_url': '',
'logo_only': False,
'display_version': True,
'prev_next_buttons_location': 'top',
'style_external_links': False,
'style_nav_header_background': '#C3EBE1',
"canonical_url": "",
"logo_only": False,
"display_version": True,
"prev_next_buttons_location": "top",
"style_external_links": False,
"style_nav_header_background": "#C3EBE1",
# Toc options
'collapse_navigation': True,
'sticky_navigation': True,
'navigation_depth': 4,
'includehidden': True,
'titles_only': False,
}
"collapse_navigation": True,
"sticky_navigation": True,
"navigation_depth": 4,
"includehidden": True,
"titles_only": False,
}
13 changes: 13 additions & 0 deletions docs/utils/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributing to OptiNiSt
OptiNiSt welcomes your contributions.
See the following guidelines before submitting Pull Requests.

## Coding Style
### Python
- Format all files using [black](https://black.readthedocs.io/en/stable/#).
- Check the code for problems using [flake8](https://pypi.org/project/flake8/).
- Some excluded rules are contained in `setup.cfg`.
- These exclusion are to avoid conflicts between black and flake8.
- Sort your import using [isort](https://github.com/PyCQA/isort).
- These guides are checked by workflows on submitting Pull Requests.
- If you are using VSCode, you can follow the above guidelines by installing and activating the extensions in `.vscode/extensions.json`.
3 changes: 2 additions & 1 deletion docs/utils/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ OTHER

add_algorithm
cui_execution
implemented_analysis
implemented_analysis
contributing
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
# run backend main module.
if __name__ == "__main__":
from optinist.__main_unit__ import main
main(develop_mode = True)

main(develop_mode=True)
1 change: 1 addition & 0 deletions optinist/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# run backend main module.
if __name__ == "__main__":
from optinist.__main_unit__ import main

main()
50 changes: 31 additions & 19 deletions optinist/__main_unit__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import argparse
import os

import uvicorn
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates

import os
import argparse
import uvicorn
from starlette.middleware.cors import CORSMiddleware
from optinist.api.dir_path import DIRPATH as OPTINIST_DIRPATH
from optinist.routers import (
files,
run,
params,
outputs,
algolist,
hdf5,
experiment,
)

from optinist.api.config.config_reader import ConfigReader
from optinist.api.dir_path import DIRPATH as OPTINIST_DIRPATH
from optinist.api.utils.filepath_creater import join_filepath
from optinist.routers import algolist, experiment, files, hdf5, outputs, params, run

app = FastAPI(docs_url="/docs", openapi_url="/openapi")
app.include_router(algolist.router)
Expand Down Expand Up @@ -63,14 +56,33 @@ def main(develop_mode: bool = False):
args = parser.parse_args()

# set fastapi@uvicorn logging config.
logging_config_path = join_filepath([OPTINIST_DIRPATH.ROOT_DIR, 'app_config', 'logging.yaml'])
logging_config_path = join_filepath(
[OPTINIST_DIRPATH.ROOT_DIR, "app_config", "logging.yaml"]
)
logging_config = ConfigReader.read(logging_config_path)
fastapi_logging_config = uvicorn.config.LOGGING_CONFIG
fastapi_logging_config["formatters"]["default"]["fmt"] = logging_config["fastapi_logging_config"]["default_fmt"]
fastapi_logging_config["formatters"]["access"]["fmt"] = logging_config["fastapi_logging_config"]["access_fmt"]
fastapi_logging_config["formatters"]["default"]["fmt"] = logging_config[
"fastapi_logging_config"
]["default_fmt"]
fastapi_logging_config["formatters"]["access"]["fmt"] = logging_config[
"fastapi_logging_config"
]["access_fmt"]

if develop_mode:
reload_options = {"reload_dirs": ["optinist"]} if args.reload else {}
uvicorn.run("optinist.__main_unit__:app", host=args.host, port=args.port, log_config=fastapi_logging_config, reload=args.reload, **reload_options)
uvicorn.run(
"optinist.__main_unit__:app",
host=args.host,
port=args.port,
log_config=fastapi_logging_config,
reload=args.reload,
**reload_options,
)
else:
uvicorn.run("optinist.__main_unit__:app", host=args.host, port=args.port, log_config=fastapi_logging_config, reload=False)
uvicorn.run(
"optinist.__main_unit__:app",
host=args.host,
port=args.port,
log_config=fastapi_logging_config,
reload=False,
)
1 change: 1 addition & 0 deletions optinist/api/config/config_reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import yaml


Expand Down
5 changes: 1 addition & 4 deletions optinist/api/config/config_writer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import yaml

from optinist.api.utils.filepath_creater import (
create_directory,
join_filepath
)
from optinist.api.utils.filepath_creater import create_directory, join_filepath


class ConfigWriter:
Expand Down
6 changes: 3 additions & 3 deletions optinist/api/dataclass/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@


class BarData(BaseData):
def __init__(self, data, index=None, file_name='bar'):
def __init__(self, data, index=None, file_name="bar"):
super().__init__(file_name)
data = np.array(data)

assert data.ndim <= 2, 'Bar Dimension Error'
assert data.ndim <= 2, "Bar Dimension Error"

if data.ndim == 1:
data = data[np.newaxis]

assert data.ndim == 2, 'Bar Dimesion is not 2'
assert data.ndim == 2, "Bar Dimesion is not 2"

self.data = data

Expand Down
6 changes: 2 additions & 4 deletions optinist/api/dataclass/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import pandas as pd

from optinist.api.dataclass.base import BaseData

from optinist.api.utils.filepath_creater import create_directory, join_filepath
from optinist.api.utils.json_writer import JsonWriter


class CsvData(BaseData):
def __init__(self, data, params, file_name='csv'):
def __init__(self, data, params, file_name="csv"):
super().__init__(file_name)

if isinstance(data, str):
Expand All @@ -33,6 +32,5 @@ def save_json(self, json_dir):

for i, data in enumerate(self.data):
JsonWriter.write_as_split(
join_filepath([self.json_path, f'{str(i)}.json']),
data
join_filepath([self.json_path, f"{str(i)}.json"]), data
)
Loading

0 comments on commit 2e5c15f

Please sign in to comment.