Skip to content

Commit 6d13c6b

Browse files
committed
feat: add support for windows
1 parent 0d8d97c commit 6d13c6b

File tree

9 files changed

+62
-27
lines changed

9 files changed

+62
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
strategy:
7373
fail-fast: true
7474
matrix:
75-
os: [ "ubuntu-latest", "macos-latest" ]
75+
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
7676
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
7777
runs-on: ${{ matrix.os }}
7878

.somesy.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fair-python-cookiecutter"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
description = "An opinionated cookiecutter template to kickstart a modern best-practice Python project with FAIR metadata. "
55

66
license = "MIT"
@@ -25,5 +25,14 @@ orcid = "https://orcid.org/0000-0002-5077-7497"
2525
author = true
2626
maintainer = true
2727

28+
[[project.people]]
29+
family-names = "Soylu"
30+
given-names = "Mustafa"
31+
32+
orcid = "https://orcid.org/0000-0003-2637-0432"
33+
34+
contribution = "Supported implementation of Windows support and testing the template"
35+
contribution_types = ["code", "test"]
36+
2837
[config]
2938
verbose = true

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Here we provide notes that summarize the most important changes in each released
44

55
Please consult the changelog to inform yourself about breaking changes and security issues.
66

7-
## [v0.2.1](https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter/tree/v0.2.1) <small>(2024-02-13)</small> { id="0.2.1" }
7+
## [v0.3.0](https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter/tree/v0.3.0) <small>(2024-02-27)</small> { id="0.3.0" }
88

9+
* added support for Windows
910
* fixed a bug where instantiation of template fails if no repository URL is provided
1011
* improve usability and description of some CLI fields
1112

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: software
33
message: If you use this software, please cite it using this metadata.
44

55
title: "fair-python-cookiecutter"
6-
version: "0.2.0"
6+
version: "0.3.0"
77
abstract: "An opinionated cookiecutter template to kickstart a modern best-practice
88
Python project with FAIR metadata."
99
repository-code: "https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter"

codemeta.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"name": "fair-python-cookiecutter",
2020
"description": "An opinionated cookiecutter template to kickstart a modern best-practice Python project with FAIR metadata.",
21-
"version": "0.2.0",
21+
"version": "0.3.0",
2222
"keywords": [
2323
"fair",
2424
"metadata",
@@ -47,6 +47,13 @@
4747
"familyName": "Pirogov",
4848
"email": "[email protected]",
4949
"@id": "https://orcid.org/0000-0002-5077-7497"
50+
},
51+
{
52+
"@type": "Person",
53+
"givenName": "Mustafa",
54+
"familyName": "Soylu",
55+
"email": "[email protected]",
56+
"@id": "https://orcid.org/0000-0003-2637-0432"
5057
}
5158
],
5259
"url": "https://materials-data-science-and-informatics.github.io/fair-python-cookiecutter"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
# ---- managed by somesy, see .somesy.toml ----
33
name = "fair-python-cookiecutter"
4-
version = "0.2.0"
4+
version = "0.3.0"
55
description = "An opinionated cookiecutter template to kickstart a modern best-practice Python project with FAIR metadata."
66
authors = ["Anton Pirogov <[email protected]>"]
77
maintainers = ["Anton Pirogov <[email protected]>"]

src/fair_python_cookiecutter/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Main functions for controlling the template creation."""
2+
import os
23
from pathlib import Path
34
from shutil import which
45
from typing import Any, Dict
@@ -80,11 +81,23 @@ def download_licenses(
8081
license.write_text((proj_root / "LICENSES" / f"{license_name}.txt").read_text())
8182

8283

83-
def finalize_repository(proj_root: Path, conf: CookiecutterConfig):
84+
def init_git_repo(tmp_root: Path, proj_root: Path):
85+
# NOTE: script is OS-agnostic, .bat extension is for windows, bash does not care
86+
post_gen_script = tmp_root / "post_gen_project.bat"
87+
# rewrite newlines correctly for the OS
88+
post_gen_script.write_text(post_gen_script.read_text(), encoding="utf-8")
89+
if os.name != "nt":
90+
run_cmd(f"bash {post_gen_script}", cwd=proj_root)
91+
else:
92+
run_cmd(f"{post_gen_script}", cwd=proj_root)
93+
94+
95+
def finalize_repository(tmp_root: Path, proj_root: Path, conf: CookiecutterConfig):
8496
"""Finalize instantiated repository based on configuration."""
8597
create_gl_issue_template_from_gh(proj_root)
8698
remove_unneeded_code(proj_root, conf)
8799
download_licenses(proj_root, conf)
100+
init_git_repo(tmp_root, proj_root)
88101

89102

90103
def create_repository(
@@ -110,6 +123,6 @@ def create_repository(
110123
**cc_args,
111124
)
112125
repo_dir = output_dir / cc_json.project_slug
113-
finalize_repository(repo_dir, conf)
126+
finalize_repository(tmp_root, repo_dir, conf)
114127

115128
return repo_dir
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
#!/usr/bin/env bash
21
: # Magic to deactivate current Python venv (if one is enabled) in a cross-platform way
32
: # See https://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash
43
:<<"::CMDLITERAL"
54
: ---- code for cmd.exe ----
6-
ECHO "TODO: cmd.exe code"
5+
for /f "delims=" %%a in ('python -c "import sys; print(sys.prefix if sys.base_prefix != sys.prefix else '')"') do set "VENV_PATH=%%a"
6+
IF NOT "%VENV_PATH%" == "" (
7+
echo INFO: Deactivating currently active virtual environment "%VENV_PATH%"
8+
REM Assuming the virtual environment needs to be activated first to provide the deactivate script
9+
call "%VENV_PATH%\Scripts\activate.bat"
10+
call "%VENV_PATH%\Scripts\deactivate.bat"
11+
)
712
: ----------------------------
813
GOTO :COMMON
914
::CMDLITERAL
1015
# ---- bash-specific code ----
1116
venv=$(python -c "import sys; print(sys.prefix if sys.base_prefix != sys.prefix else '')")
1217
if [[ -n "$venv" ]]; then
13-
echo Deactivating currently active virtual environment "$venv" ...
18+
echo INFO: Deactivating currently active virtual environment "$venv"
1419
source "$venv/bin/activate" # make sure we have 'deactivate' available
1520
deactivate
1621
fi
1722
# ----------------------------
1823
:<<"::CMDLITERAL"
1924
:COMMON
2025
::CMDLITERAL
26+
2127
: #All following code must be hybrid (work for bash and cmd.exe)
2228
: # ------------------------------------------------------------
2329

@@ -27,10 +33,6 @@ git init
2733
poetry install --with docs
2834
poetry run poe init-dev
2935

30-
echo "Downloading required license texts ..."
31-
poetry run pip install pipx
32-
poetry run pipx run reuse download --all
33-
3436
echo "Creating CITATION.cff and codemeta.json using somesy ..."
3537

3638
git add .
@@ -39,21 +41,10 @@ git add .
3941

4042
echo "Creating first commit ..."
4143

42-
poetry run git commit \
43-
-m "generated project using fair-python-cookiecutter {{ cookiecutter._fpc_version }}" \
44-
-m "https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter"
44+
poetry run git commit -m "generated project using fair-python-cookiecutter" -m "https://github.com/Materials-Data-Science-and-Informatics/fair-python-cookiecutter"
4545

4646
echo "Ensuring that the default branch is called 'main' ..."
4747

4848
git branch -M main
4949

5050
echo "--------> All done! Your project repository is ready :) <--------"
51-
52-
53-
: # TODO: only do following in test mode
54-
55-
: # sanity-check that main tasks all work
56-
: # poetry install --with docs
57-
: # poetry run poe lint --all-files
58-
: # poetry run poe test
59-
: # poetry run poe docs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
: # Magic to deactivate current Python venv (if one is enabled) in a cross-platform way
2+
: # See https://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash
3+
# ---- bash-specific code ----
4+
# venv=$(python -c "import sys; print(sys.prefix if sys.base_prefix != sys.prefix else '')")
5+
if [[ -n "$venv" ]]; then
6+
echo INFO: Deactivating currently active virtual environment "$venv"
7+
source "$venv/bin/activate" # make sure we have 'deactivate' available
8+
deactivate
9+
fi
10+
# ----------------------------
11+
12+
13+
echo "--------> All done! Your project repository is ready :) <--------"
14+

0 commit comments

Comments
 (0)