Skip to content

Commit

Permalink
Merge pull request #1 from optuna/introduce-pre-commit-and-add-checks-ci
Browse files Browse the repository at this point in the history
Introduce pre-commit and add checks CI
  • Loading branch information
HideakiImamura authored May 15, 2024
2 parents 1c09dc6 + 3aa58e1 commit 047a2d4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 16 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Checks
on:
push:
branches:
- main
pull_request: {}
workflow_dispatch: {}
jobs:
checks:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
types_or: [python, pyi]
- id: ruff-format
types_or: [python, pyi]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [
"types-toml",
]
4 changes: 3 additions & 1 deletion optunahub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from optunahub.hub import load, load_local
from optunahub.hub import load
from optunahub.hub import load_local
from optunahub.version import __version__


__all__ = ["load", "load_local", "__version__"]
12 changes: 3 additions & 9 deletions optunahub/_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ def config_file() -> str:
"""
if platform.system() == "Windows": # NOTE: unverified
return os.path.join(
os.getenv(
"APPDATA", os.path.join(os.path.expanduser("~"), "AppData", "Roaming")
),
os.getenv("APPDATA", os.path.join(os.path.expanduser("~"), "AppData", "Roaming")),
"optunahub",
"config.toml",
)
else: # UNIX-like
return os.path.join(
os.getenv(
"XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config")
),
os.getenv("XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config")),
"optunahub",
"config.toml",
)
Expand Down Expand Up @@ -103,9 +99,7 @@ def cache_home() -> str:
)
else: # UNIX-like
return os.path.join(
os.getenv(
"XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache")
),
os.getenv("XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache")),
"optunahub",
)

Expand Down
9 changes: 4 additions & 5 deletions optunahub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import types
from urllib.parse import urlparse

import optuna.version
from ga4mp import GtagMP # type: ignore
from github import Auth, Github
from github import Auth
from github import Github
from github.ContentFile import ContentFile
import optuna.version

import optunahub
from optunahub import _conf
Expand Down Expand Up @@ -61,9 +62,7 @@ def _import_github_dir(
hostname = urlparse(base_url).hostname
if hostname is None:
raise ValueError(f"Invalid base URL: {base_url}")
cache_dir_prefix = os.path.join(
_conf.cache_home(), hostname, repo_owner, repo_name, ref
)
cache_dir_prefix = os.path.join(_conf.cache_home(), hostname, repo_owner, repo_name, ref)
package_cache_dir = os.path.join(cache_dir_prefix, dir_path)
use_cache = not force_reload and os.path.exists(package_cache_dir)

Expand Down
43 changes: 42 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies = [

[project.optional-dependencies]
checking = [
"pre-commit",
"mypy",
"ruff",
"types-toml",
Expand All @@ -23,4 +24,44 @@ checking = [
docs = [
"sphinx",
"sphinx_rtd_theme",
]
]

[tool.setuptools.packages.find]
include = ["package*"]

[tool.ruff]
line-length = 99

[tool.ruff.lint]
extend-select = [
"I",
]

[tool.ruff.lint.isort]
known-third-party = ['optuna']
lines-after-imports = 2
force-single-line = true
force-sort-within-sections = true
order-by-type = false

[tool.mypy]
# Options configure mypy's strict mode.
warn_unused_configs = true
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
strict_equality = true
extra_checks = true
no_implicit_reexport = true
ignore_missing_imports = true
explicit_package_bases = true
exclude = [
".venv",
"venv",
"build",
"work",
".*/.ipynb_checkpoints/.*",
]

0 comments on commit 047a2d4

Please sign in to comment.