Skip to content

Commit

Permalink
fix: Improve pyproject.toml output and keep workflow more consistent (#…
Browse files Browse the repository at this point in the history
…277)

* organize build-system files into folders, one folder for each build-system
* add test  to check if the package is importable and if it shows the correct version using `__version__` (not working yet for mesonpy and maturin)
* standardize cpp file names
* fix the structure in the final version of pyproject.toml
* fix some issues with some build system configurations
* fix the end of file in the post generation hook
  • Loading branch information
xmnlab authored May 4, 2024
1 parent 07b60f6 commit b2cc87d
Show file tree
Hide file tree
Showing 46 changed files with 550 additions and 249 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ on:
branches: [main]

jobs:
check-branch:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 2
concurrency:
group: check-pr-${{ github.ref }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check if the PR's branch is updated
uses: osl-incubator/gh-check-pr-is-updated@1.0.0
with:
remote_branch: origin/main
pr_sha: ${{ github.event.pull_request.head.sha }}

test:
runs-on: ubuntu-latest
concurrency:
Expand Down
94 changes: 93 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ colorama = ">=0.4.6"
inquirer = ">=3.1.3"
pyyaml = ">=6.0.1"
nodejs-wheel = ">=20.12"
pre-commit-hooks = ">=0.4.6"


[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -59,6 +60,7 @@ module = [
"inquirer",
"sh",
"yaml",
"pre_commit_hooks",
]
ignore_missing_imports = true

Expand Down
125 changes: 74 additions & 51 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from pathlib import Path

from scicookie.tools import fix_eof

PROJECT_DIRECTORY = Path(os.path.abspath(os.path.curdir)).resolve()

UNUSED_DOCS_DIRS = [
Expand All @@ -28,6 +30,8 @@
else:
PACKAGE_PATH = PROJECT_DIRECTORY / "{{ cookiecutter.package_slug}}"

COMPILE_SOURCE_DIR = PROJECT_DIRECTORY / "src"

USE_BLACK = {{ cookiecutter.use_black == "yes" }}
USE_BANDIT = {{ cookiecutter.use_bandit == "yes" }}
USE_CONTAINERS = {{ cookiecutter.use_containers in ['Docker', 'Podman'] }}
Expand Down Expand Up @@ -194,80 +198,94 @@ def clean_up_cli():


def clean_up_build_system():
build_system_dir = PROJECT_DIRECTORY / "build-system"
build_system_base_dir = PROJECT_DIRECTORY / "build-system"
build_system_dir = build_system_base_dir / BUILD_SYSTEM

if BUILD_SYSTEM == "poetry":
if BUILD_SYSTEM == "flit":
shutil.move(
build_system_dir / "poetry-pyproject.toml",
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "flit":
elif BUILD_SYSTEM == "hatch":
shutil.move(
build_system_dir / "flit-pyproject.toml",
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "mesonpy":
elif BUILD_SYSTEM == "maturin":
shutil.move(
build_system_dir / "mesonpy-pyproject.toml",
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "meson.build",
PROJECT_DIRECTORY / 'meson.build'
build_system_dir / "Cargo.toml",
PROJECT_DIRECTORY / 'Cargo.toml'
)
elif BUILD_SYSTEM == "setuptools":
shutil.move(
build_system_dir / "setuptools-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
build_system_dir / "lib.rs",
COMPILE_SOURCE_DIR / 'lib.rs'
)
elif BUILD_SYSTEM == "pdm":
elif BUILD_SYSTEM == "mesonpy":
os.makedirs(COMPILE_SOURCE_DIR, exist_ok=True)
shutil.move(
build_system_dir / "pdm-pyproject.toml",
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "hatch":
shutil.move(
build_system_dir / "hatch-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
build_system_dir / "meson.build",
PROJECT_DIRECTORY / 'meson.build'
)
elif BUILD_SYSTEM == "maturin":
shutil.move(
build_system_dir / "maturin-pyproject.toml",
build_system_dir / "main.cpp",
COMPILE_SOURCE_DIR / 'main.cpp'
)
elif BUILD_SYSTEM == "pdm":
shutil.move(
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "poetry":
shutil.move(
build_system_dir / "Cargo.toml",
PROJECT_DIRECTORY / 'Cargo.toml'
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "scikit-build-core":
elif BUILD_SYSTEM == "pybind11":
shutil.move(
build_system_dir / "scikit-build-core-pyproject.toml",
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "CMakeLists.txt",
PROJECT_DIRECTORY / 'CMakeLists.txt'
)
shutil.move(
build_system_dir / "skcdemo.cpp",
PROJECT_DIRECTORY / 'skcdemo.cpp'
build_system_dir / "setup.py",
PROJECT_DIRECTORY / 'setup.py'
)
elif BUILD_SYSTEM == "pybind11":
shutil.move(
build_system_dir / "pybind11-pyproject.toml",
build_system_dir / "main.cpp",
COMPILE_SOURCE_DIR / 'main.cpp'
)
elif BUILD_SYSTEM == "scikit-build-core":
shutil.move(
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "CMakeLists.txt",
PROJECT_DIRECTORY / 'CMakeLists.txt'
)
shutil.move(
build_system_dir / "setup.py",
PROJECT_DIRECTORY / 'setup.py'
build_system_dir / "main.cpp",
COMPILE_SOURCE_DIR / 'main.cpp'
)
elif BUILD_SYSTEM == "setuptools":
shutil.move(
build_system_dir / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
build_system_base_dir / "base" / "pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
remove_dir("build-system")
Expand All @@ -284,7 +302,10 @@ def clean_up_linter():
if not USE_PRE_COMMIT:
remove_project_file(".pre-commit-config.yaml")

# Auto format files with prettier
# Auto format tools
# -----------------

# prettier
subprocess.call([
"npx",
"--yes",
Expand All @@ -298,6 +319,9 @@ def clean_up_linter():
remove_project_file(".prettierrc.yaml")
remove_project_file(".prettierignore")

# fix end of file
fix_eof.run(PROJECT_DIRECTORY)


def prepare_git() -> None:
git_https_origin = http2ssh("{{cookiecutter.git_https_origin}}")
Expand Down Expand Up @@ -365,31 +389,30 @@ def prepare_git() -> None:
subprocess.call(["git", "branch", "-D", git_stash_branch])


def add_binding_source_files():
if BUILD_SYSTEM == "maturin":
build_system_dir = PROJECT_DIRECTORY / "build-system"
src_system_dir = PROJECT_DIRECTORY/ "src"
if USE_SRC_LAYOUT :
shutil.move(build_system_dir / "lib.rs", "src")
else:
os.makedir(src_system_dir)
shutil.move(build_system_dir / "lib.rs", src_system_dir)
elif BUILD_SYSTEM == "pybind11" :
build_system_dir = PROJECT_DIRECTORY / "build-system"
src_system_dir = PROJECT_DIRECTORY/ "src"
if USE_SRC_LAYOUT :
shutil.move(build_system_dir / "main.cpp", "src")
else:
os.makedir(src_system_dir)
shutil.move(build_system_dir / "main.cpp", src_system_dir)
else:
pass
# def add_binding_source_files():
# if BUILD_SYSTEM == "maturin":
# build_system_dir = PROJECT_DIRECTORY / "build-system"
# src_system_dir = PROJECT_DIRECTORY/ "src"
# if USE_SRC_LAYOUT :
# shutil.move(build_system_dir / "lib.rs", "src")
# else:
# os.makedir(src_system_dir)
# shutil.move(build_system_dir / "lib.rs", src_system_dir)
# elif BUILD_SYSTEM == "pybind11" :
# build_system_dir = PROJECT_DIRECTORY / "build-system"
# src_system_dir = PROJECT_DIRECTORY/ "src"
# if USE_SRC_LAYOUT :
# shutil.move(build_system_dir / "main.cpp", "src")
# else:
# os.makedir(src_system_dir)
# shutil.move(build_system_dir / "main.cpp", src_system_dir)
# else:
# pass


def post_gen():
# keep this one first, because it changes the package folder
clean_up_project_layout()
add_binding_source_files()
clean_up_automation()
clean_up_cli()
clean_up_code_of_conduct()
Expand Down
1 change: 1 addition & 0 deletions src/scicookie/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Package for a set of useful tools."""
Loading

0 comments on commit b2cc87d

Please sign in to comment.