Skip to content

Commit

Permalink
fix: Fix profile's mechanism and update OSL profile (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Dec 8, 2023
1 parent 21fa953 commit 4eaf7b4
Show file tree
Hide file tree
Showing 18 changed files with 1,494 additions and 1,240 deletions.
17 changes: 9 additions & 8 deletions .makim.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
version: 1.0
groups:
default:
clean:
targets:
clean:
tmp:
help: Clean unnecessary temporary files
shell: bash
run: |
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name
find . -name '__pycache__' -exec rm -fr '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +{} +
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
find . -name '*~' -exec rm -f {} +
docs:
targets:
Expand Down
29 changes: 18 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ repos:

- repo: local
hooks:
- id: black
entry: black
name: black
language: system
pass_filenames: true
types:
- python

- id: mypy
name: mypy
entry: mypy
Expand All @@ -33,9 +25,24 @@ repos:
types:
- python

- id: ruff
name: ruff
entry: ruff --no-cache --fix
- id: ruff format
name: ruff format
entry: ruff format
language: system
pass_filenames: true
files: "./"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python

- id: ruff check
name: ruff check
entry: ruff check
language: system
pass_filenames: true
files: "./"
Expand Down
6 changes: 3 additions & 3 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ channels:
- conda-forge
dependencies:
- git
- python <3.11
- poetry
- python >=3.8.1,<3.12
- poetry >=1.5
- nodejs
- compilers
- pip
- pip:
- makim==1.8.2
- makim==1.8.3
2,191 changes: 1,143 additions & 1,048 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 15 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ name = "scicookie"
version = "0.6.2" # semantic-release
description = "Cookiecutter template for a Python package"
authors = ["Ivan Ogasawara <ivan.ogasawara@gmail.com>"]
license = "BSD"
license = "BSD-3-Clause"
include = [
{path = "src/scicookie/cookiecutter.json"},
{path = "src/scicookie/{{cookiecutter.project_slug}}"},
{path = "src/scicookie/hooks"},
{path = "src/scicookie/profiles"},
]

[tool.poetry.scripts]
"scicookie" = "scicookie.__main__:app"

[tool.poetry.dependencies]
python = ">=3.8.1,<4"
python = ">=3.8.1,<3.12"
cookieninja = "1.0.0"
sh = "^2.0.4"
colorama = "^0.4.6"
Expand All @@ -23,35 +24,21 @@ pyyaml = ">=6.0.1"

[tool.poetry.group.dev.dependencies]
pytest = ">=7"
black = ">=22"
isort = ">=5"
pre-commit = ">=3"
ruff = ">=0.0.278"
mypy = ">=1"
ruff = ">=0.1.5"
mypy = ">=1.5"
pytest-cov = ">=3"
pytest-cookies = ">=0.6.1"
Sphinx = ">=4.4"
jupyterlab = ">=3.5.1"
jupyter-book = ">=0.12.3"
myst-parser = ">=0.15"
makim = "1.8.2"
makim = "1.8.3"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 79
# note: for support "py39", we need to update black using poetry
# currently, it has conflicts with typing-extensions.
target-version = ["py38"]
force-exclude = '''(?x)(
docs/*
| src/scicookie/{{cookiecutter.project_slug}}/*
| src/scicookie/hooks/*
|.*\\.egg-info
)''' # TOML's single-quoted strings do not require escaping backslashes

[tool.mypy]
no_strict_optional = false
exclude = '''(?x)(
Expand All @@ -76,6 +63,8 @@ exclude = [
'src/scicookie/\{\{cookiecutter.project_slug\}\}',
'src/scicookie/hooks',
]

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # pyflakes
Expand All @@ -85,11 +74,17 @@ select = [
"RUF", # Ruff-specific rules
"I001", # isort
]
fixable = ["I001"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.ruff.isort]
# Use a single line between direct and from import
lines-between-types = 1

[tool.ruff.format]
quote-style = "double"

[tool.pytest.ini_options]
testpaths = [
"tests",
Expand Down
2 changes: 1 addition & 1 deletion src/scicookie/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""SciCookie is a wrap around cookiecutter/cookieninja with a better TUI."""
"""SciCookie is a wrap around cookiecutter/cookieninja with an improved TUI."""
67 changes: 64 additions & 3 deletions src/scicookie/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Module with CLI functions."""
import argparse
import json
import os
import sys

from pathlib import Path
from typing import Union

Expand All @@ -15,6 +17,31 @@
COOKIECUTTER_FILE_PATH = PACKAGE_PATH / "cookiecutter.json"


class CustomHelpFormatter(argparse.RawTextHelpFormatter):
"""Formatter for generating usage messages and argument help strings.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""

def __init__(
self,
prog,
indent_increment=2,
max_help_position=4,
width=None,
**kwargs,
):
"""Define the parameters for the argparse help text."""
super().__init__(
prog,
indent_increment=indent_increment,
max_help_position=max_help_position,
width=width,
**kwargs,
)


def _get_cookiecutter_default_answer(
answer_definition: Union[str, list]
) -> str:
Expand All @@ -30,7 +57,7 @@ def _get_cookiecutter_default_answer(
return answer_definition[0]


def call_cookiecutter(profile: Profile, answers: dict):
def call_cookiecutter(profile: Profile, answers: dict): # noqa: PLR0912
"""Call cookiecutter/cookieninja with the parameters from the TUI."""
answers_profile = {}
cookie_args = []
Expand All @@ -41,7 +68,13 @@ def call_cookiecutter(profile: Profile, answers: dict):

# fill the answers with default value
for question_id, question in questions.items():
if not question.get("enabled", False) or question.get("control_flow"):
if question.get("control_flow", False):
# "control_flow" is not defined in cookiecutter config
continue

if not question.get("visible", False):
# get the default for non visible questions
answers_profile[question_id] = question.get("default")
continue

if question.get("type") == "multiple-choices":
Expand Down Expand Up @@ -98,7 +131,35 @@ def call_cookiecutter(profile: Profile, answers: dict):
def app():
"""Run SciCookie."""
# note: this parameter should be provided by a CLI argument
profile = Profile("osl")

parser = argparse.ArgumentParser(
prog="SciCookie",
description=(
"SciCookie is a template developed by Open Science Labs that "
"creates projects through different options of profile. "
"It serves as a boilerplate which can be used by beginners as "
"well as full fledged developers to simplify the project creation "
"process and save considerable amount of time. It creates "
"projects with an initial layout that includes recommended "
"tools, workflows, and project structure."
),
epilog=(
"If you have any problem, open an issue at: "
"https://github.com/osl-incubator/scicookie"
),
add_help=True,
formatter_class=CustomHelpFormatter,
)
parser.add_argument(
"--profile",
type=str,
default="base",
help="Select the profile to be used",
)

args = parser.parse_args()

profile = Profile(args.profile)

answers = make_questions(profile.config)

Expand Down
2 changes: 1 addition & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"flat"
],
"command_line_interface": [
"No command-line interface",
"None",
"Click",
"Argparse"
],
Expand Down
64 changes: 43 additions & 21 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
USE_BLUE = {{ cookiecutter.use_blue == "yes" }}
USE_BANDIT = {{ cookiecutter.use_bandit == "yes" }}
USE_CONTAINERS = {{ cookiecutter.use_containers in ['Docker', 'Podman'] }}
USE_CLI = {{ cookiecutter.command_line_interface != "No command-line interface" }}
USE_CLI = {{ cookiecutter.command_line_interface != "None" }}
USE_CONDA = {{ cookiecutter.use_conda == "yes" }}
USE_MAKE = {{ cookiecutter.use_make == "yes" }}
USE_MAKIM = {{ cookiecutter.use_makim == "yes" }}
Expand Down Expand Up @@ -266,48 +266,70 @@ def validation():
)


def prepare_git():
subprocess.call(["git", "init"])

def prepare_git() -> None:
git_https_origin = http2ssh("{{cookiecutter.git_https_origin}}")
git_https_upstream = http2ssh("{{cookiecutter.git_https_upstream}}")
git_main_branch = http2ssh("{{cookiecutter.git_main_branch}}")
unique_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
git_new_branch = f"add-initial-structure-{unique_id}"
git_new_branch = f"initial-from-scicookie-{unique_id}"
git_stash_branch = f"stash-from-scicookie-{unique_id}"

git_author_name = "{{cookiecutter.author_full_name}}"
git_author_email = "{{cookiecutter.author_email}}"

empty_repo = not (git_https_origin or git_https_upstream)

if not empty_repo:
subprocess.call(["git", "stash"])

if git_https_origin != "":
subprocess.call(["git", "remote", "add", "origin", git_https_origin])
subprocess.call(["git", "fetch", "--all"])
subprocess.call(["git", "checkout", f"origin/{git_main_branch}"])
use_remote = git_https_origin != '' or git_https_upstream != ''

if git_https_upstream != "":
if not use_remote:
subprocess.call(["git", "init", "-b", git_main_branch])
subprocess.call(
["git", "remote", "add", "upstream", git_https_upstream]
["git", "config", "user.name", git_author_name]
)
subprocess.call(["git", "fetch", "--all"])
subprocess.call(
["git", "config", "user.email", git_author_email]
)
subprocess.call(["git", "add", "."])
subprocess.call([
"git", "commit", "-m", "Initial commit from SciCookie", "--no-verify"
])
return

subprocess.call(["git", "init", "-b", git_stash_branch])

# config
subprocess.call(
["git", "config", "user.name", git_author_name]
)
subprocess.call(
["git", "config", "user.email", git_author_email]
)
if git_https_origin != "":
subprocess.call(["git", "remote", "add", "origin", git_https_origin])

subprocess.call(["git", "checkout", "-b", git_new_branch])
if git_https_upstream != "":
subprocess.call(
["git", "remote", "add", "upstream", git_https_upstream]
)

if not empty_repo:
subprocess.call(["git", "stash", "pop"])
subprocess.call(["git", "fetch", "--all"])

# prepare the first commit
subprocess.call(["git", "add", "."])
subprocess.call([
"git",
"commit",
"-m",
"A temporary from SciCookie",
"--no-verify"
])

subprocess.call(["git", "checkout", f"origin/{git_main_branch}"])
subprocess.call(["git", "checkout", "-b", git_new_branch])
subprocess.call(["git", "checkout", git_stash_branch, "--", "."])
subprocess.call(["git", "add", "."])
subprocess.call(["git", "commit", "-m", "Initial commit", "--no-verify"])
subprocess.call([
"git", "commit", "-m", "Initial commit from SciCookie", "--no-verify"
])
subprocess.call(["git", "branch", "-D", git_stash_branch])


def add_binding_source_files():
Expand Down
1 change: 1 addition & 0 deletions src/scicookie/logs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module for functions and classes for systen logs."""
import os

from enum import Enum

from colorama import Fore
Expand Down
Loading

0 comments on commit 4eaf7b4

Please sign in to comment.