Skip to content

Commit 4eaf7b4

Browse files
authored
fix: Fix profile's mechanism and update OSL profile (#189)
1 parent 21fa953 commit 4eaf7b4

18 files changed

+1494
-1240
lines changed

.makim.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
version: 1.0
22
groups:
3-
default:
3+
clean:
44
targets:
5-
clean:
5+
tmp:
66
help: Clean unnecessary temporary files
7+
shell: bash
78
run: |
89
rm -fr build/
910
rm -fr dist/
1011
rm -fr .eggs/
11-
find . -name '*.egg-info' -exec rm -fr {} +
12-
find . -name '*.egg' -exec rm -f {} +
13-
find . -name '*.pyc' -exec rm -f {} +
14-
find . -name
15-
find . -name '__pycache__' -exec rm -fr '*.pyo' -exec rm -f {} +
16-
find . -name '*~' -exec rm -f {} +{} +
1712
rm -f .coverage
1813
rm -fr htmlcov/
1914
rm -fr .pytest_cache
15+
find . -name '*.egg-info' -exec rm -fr {} +
16+
find . -name '*.egg' -exec rm -f {} +
17+
find . -name '*.pyc' -exec rm -f {} +
18+
find . -name '*.pyo' -exec rm -f {} +
19+
find . -name '__pycache__' -exec rm -fr {} +
20+
find . -name '*~' -exec rm -f {} +
2021
2122
docs:
2223
targets:

.pre-commit-config.yaml

+18-11
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ repos:
1010

1111
- repo: local
1212
hooks:
13-
- id: black
14-
entry: black
15-
name: black
16-
language: system
17-
pass_filenames: true
18-
types:
19-
- python
20-
2113
- id: mypy
2214
name: mypy
2315
entry: mypy
@@ -33,9 +25,24 @@ repos:
3325
types:
3426
- python
3527

36-
- id: ruff
37-
name: ruff
38-
entry: ruff --no-cache --fix
28+
- id: ruff format
29+
name: ruff format
30+
entry: ruff format
31+
language: system
32+
pass_filenames: true
33+
files: "./"
34+
# pre-commit + ruff doesn't honor the exclusion defined in the config
35+
exclude: |
36+
(?x)(
37+
src/scicookie/{{cookiecutter.project_slug}}
38+
| src/scicookie/hooks
39+
)
40+
types:
41+
- python
42+
43+
- id: ruff check
44+
name: ruff check
45+
entry: ruff check
3946
language: system
4047
pass_filenames: true
4148
files: "./"

conda/dev.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ channels:
44
- conda-forge
55
dependencies:
66
- git
7-
- python <3.11
8-
- poetry
7+
- python >=3.8.1,<3.12
8+
- poetry >=1.5
99
- nodejs
1010
- compilers
1111
- pip
1212
- pip:
13-
- makim==1.8.2
13+
- makim==1.8.3

poetry.lock

+1,143-1,048
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+15-20
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ name = "scicookie"
33
version = "0.6.2" # semantic-release
44
description = "Cookiecutter template for a Python package"
55
authors = ["Ivan Ogasawara <ivan.ogasawara@gmail.com>"]
6-
license = "BSD"
6+
license = "BSD-3-Clause"
77
include = [
88
{path = "src/scicookie/cookiecutter.json"},
99
{path = "src/scicookie/{{cookiecutter.project_slug}}"},
1010
{path = "src/scicookie/hooks"},
11+
{path = "src/scicookie/profiles"},
1112
]
1213

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

1617
[tool.poetry.dependencies]
17-
python = ">=3.8.1,<4"
18+
python = ">=3.8.1,<3.12"
1819
cookieninja = "1.0.0"
1920
sh = "^2.0.4"
2021
colorama = "^0.4.6"
@@ -23,35 +24,21 @@ pyyaml = ">=6.0.1"
2324

2425
[tool.poetry.group.dev.dependencies]
2526
pytest = ">=7"
26-
black = ">=22"
27-
isort = ">=5"
2827
pre-commit = ">=3"
29-
ruff = ">=0.0.278"
30-
mypy = ">=1"
28+
ruff = ">=0.1.5"
29+
mypy = ">=1.5"
3130
pytest-cov = ">=3"
3231
pytest-cookies = ">=0.6.1"
3332
Sphinx = ">=4.4"
3433
jupyterlab = ">=3.5.1"
3534
jupyter-book = ">=0.12.3"
3635
myst-parser = ">=0.15"
37-
makim = "1.8.2"
36+
makim = "1.8.3"
3837

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

43-
[tool.black]
44-
line-length = 79
45-
# note: for support "py39", we need to update black using poetry
46-
# currently, it has conflicts with typing-extensions.
47-
target-version = ["py38"]
48-
force-exclude = '''(?x)(
49-
docs/*
50-
| src/scicookie/{{cookiecutter.project_slug}}/*
51-
| src/scicookie/hooks/*
52-
|.*\\.egg-info
53-
)''' # TOML's single-quoted strings do not require escaping backslashes
54-
5542
[tool.mypy]
5643
no_strict_optional = false
5744
exclude = '''(?x)(
@@ -76,6 +63,8 @@ exclude = [
7663
'src/scicookie/\{\{cookiecutter.project_slug\}\}',
7764
'src/scicookie/hooks',
7865
]
66+
67+
[tool.ruff.lint]
7968
select = [
8069
"E", # pycodestyle
8170
"F", # pyflakes
@@ -85,11 +74,17 @@ select = [
8574
"RUF", # Ruff-specific rules
8675
"I001", # isort
8776
]
88-
fixable = ["I001"]
8977

9078
[tool.ruff.pydocstyle]
9179
convention = "numpy"
9280

81+
[tool.ruff.isort]
82+
# Use a single line between direct and from import
83+
lines-between-types = 1
84+
85+
[tool.ruff.format]
86+
quote-style = "double"
87+
9388
[tool.pytest.ini_options]
9489
testpaths = [
9590
"tests",

src/scicookie/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""SciCookie is a wrap around cookiecutter/cookieninja with a better TUI."""
1+
"""SciCookie is a wrap around cookiecutter/cookieninja with an improved TUI."""

src/scicookie/cli.py

+64-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Module with CLI functions."""
2+
import argparse
23
import json
34
import os
45
import sys
6+
57
from pathlib import Path
68
from typing import Union
79

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

1719

20+
class CustomHelpFormatter(argparse.RawTextHelpFormatter):
21+
"""Formatter for generating usage messages and argument help strings.
22+
23+
Only the name of this class is considered a public API. All the methods
24+
provided by the class are considered an implementation detail.
25+
"""
26+
27+
def __init__(
28+
self,
29+
prog,
30+
indent_increment=2,
31+
max_help_position=4,
32+
width=None,
33+
**kwargs,
34+
):
35+
"""Define the parameters for the argparse help text."""
36+
super().__init__(
37+
prog,
38+
indent_increment=indent_increment,
39+
max_help_position=max_help_position,
40+
width=width,
41+
**kwargs,
42+
)
43+
44+
1845
def _get_cookiecutter_default_answer(
1946
answer_definition: Union[str, list]
2047
) -> str:
@@ -30,7 +57,7 @@ def _get_cookiecutter_default_answer(
3057
return answer_definition[0]
3158

3259

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

4269
# fill the answers with default value
4370
for question_id, question in questions.items():
44-
if not question.get("enabled", False) or question.get("control_flow"):
71+
if question.get("control_flow", False):
72+
# "control_flow" is not defined in cookiecutter config
73+
continue
74+
75+
if not question.get("visible", False):
76+
# get the default for non visible questions
77+
answers_profile[question_id] = question.get("default")
4578
continue
4679

4780
if question.get("type") == "multiple-choices":
@@ -98,7 +131,35 @@ def call_cookiecutter(profile: Profile, answers: dict):
98131
def app():
99132
"""Run SciCookie."""
100133
# note: this parameter should be provided by a CLI argument
101-
profile = Profile("osl")
134+
135+
parser = argparse.ArgumentParser(
136+
prog="SciCookie",
137+
description=(
138+
"SciCookie is a template developed by Open Science Labs that "
139+
"creates projects through different options of profile. "
140+
"It serves as a boilerplate which can be used by beginners as "
141+
"well as full fledged developers to simplify the project creation "
142+
"process and save considerable amount of time. It creates "
143+
"projects with an initial layout that includes recommended "
144+
"tools, workflows, and project structure."
145+
),
146+
epilog=(
147+
"If you have any problem, open an issue at: "
148+
"https://github.com/osl-incubator/scicookie"
149+
),
150+
add_help=True,
151+
formatter_class=CustomHelpFormatter,
152+
)
153+
parser.add_argument(
154+
"--profile",
155+
type=str,
156+
default="base",
157+
help="Select the profile to be used",
158+
)
159+
160+
args = parser.parse_args()
161+
162+
profile = Profile(args.profile)
102163

103164
answers = make_questions(profile.config)
104165

src/scicookie/cookiecutter.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"flat"
2121
],
2222
"command_line_interface": [
23-
"No command-line interface",
23+
"None",
2424
"Click",
2525
"Argparse"
2626
],

src/scicookie/hooks/post_gen_project.py

+43-21
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
USE_BLUE = {{ cookiecutter.use_blue == "yes" }}
3232
USE_BANDIT = {{ cookiecutter.use_bandit == "yes" }}
3333
USE_CONTAINERS = {{ cookiecutter.use_containers in ['Docker', 'Podman'] }}
34-
USE_CLI = {{ cookiecutter.command_line_interface != "No command-line interface" }}
34+
USE_CLI = {{ cookiecutter.command_line_interface != "None" }}
3535
USE_CONDA = {{ cookiecutter.use_conda == "yes" }}
3636
USE_MAKE = {{ cookiecutter.use_make == "yes" }}
3737
USE_MAKIM = {{ cookiecutter.use_makim == "yes" }}
@@ -266,48 +266,70 @@ def validation():
266266
)
267267

268268

269-
def prepare_git():
270-
subprocess.call(["git", "init"])
271-
269+
def prepare_git() -> None:
272270
git_https_origin = http2ssh("{{cookiecutter.git_https_origin}}")
273271
git_https_upstream = http2ssh("{{cookiecutter.git_https_upstream}}")
274272
git_main_branch = http2ssh("{{cookiecutter.git_main_branch}}")
275273
unique_id = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
276-
git_new_branch = f"add-initial-structure-{unique_id}"
274+
git_new_branch = f"initial-from-scicookie-{unique_id}"
275+
git_stash_branch = f"stash-from-scicookie-{unique_id}"
277276

278277
git_author_name = "{{cookiecutter.author_full_name}}"
279278
git_author_email = "{{cookiecutter.author_email}}"
280279

281-
empty_repo = not (git_https_origin or git_https_upstream)
282-
283-
if not empty_repo:
284-
subprocess.call(["git", "stash"])
285-
286-
if git_https_origin != "":
287-
subprocess.call(["git", "remote", "add", "origin", git_https_origin])
288-
subprocess.call(["git", "fetch", "--all"])
289-
subprocess.call(["git", "checkout", f"origin/{git_main_branch}"])
280+
use_remote = git_https_origin != '' or git_https_upstream != ''
290281

291-
if git_https_upstream != "":
282+
if not use_remote:
283+
subprocess.call(["git", "init", "-b", git_main_branch])
292284
subprocess.call(
293-
["git", "remote", "add", "upstream", git_https_upstream]
285+
["git", "config", "user.name", git_author_name]
294286
)
295-
subprocess.call(["git", "fetch", "--all"])
287+
subprocess.call(
288+
["git", "config", "user.email", git_author_email]
289+
)
290+
subprocess.call(["git", "add", "."])
291+
subprocess.call([
292+
"git", "commit", "-m", "Initial commit from SciCookie", "--no-verify"
293+
])
294+
return
295+
296+
subprocess.call(["git", "init", "-b", git_stash_branch])
296297

298+
# config
297299
subprocess.call(
298300
["git", "config", "user.name", git_author_name]
299301
)
300302
subprocess.call(
301303
["git", "config", "user.email", git_author_email]
302304
)
305+
if git_https_origin != "":
306+
subprocess.call(["git", "remote", "add", "origin", git_https_origin])
303307

304-
subprocess.call(["git", "checkout", "-b", git_new_branch])
308+
if git_https_upstream != "":
309+
subprocess.call(
310+
["git", "remote", "add", "upstream", git_https_upstream]
311+
)
305312

306-
if not empty_repo:
307-
subprocess.call(["git", "stash", "pop"])
313+
subprocess.call(["git", "fetch", "--all"])
308314

315+
# prepare the first commit
316+
subprocess.call(["git", "add", "."])
317+
subprocess.call([
318+
"git",
319+
"commit",
320+
"-m",
321+
"A temporary from SciCookie",
322+
"--no-verify"
323+
])
324+
325+
subprocess.call(["git", "checkout", f"origin/{git_main_branch}"])
326+
subprocess.call(["git", "checkout", "-b", git_new_branch])
327+
subprocess.call(["git", "checkout", git_stash_branch, "--", "."])
309328
subprocess.call(["git", "add", "."])
310-
subprocess.call(["git", "commit", "-m", "Initial commit", "--no-verify"])
329+
subprocess.call([
330+
"git", "commit", "-m", "Initial commit from SciCookie", "--no-verify"
331+
])
332+
subprocess.call(["git", "branch", "-D", git_stash_branch])
311333

312334

313335
def add_binding_source_files():

src/scicookie/logs.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Module for functions and classes for systen logs."""
22
import os
3+
34
from enum import Enum
45

56
from colorama import Fore

0 commit comments

Comments
 (0)