Skip to content

Commit

Permalink
fix: Fix usage of scicookie for pipx (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab authored May 11, 2024
1 parent f7cc72a commit 41b80b8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 43 deletions.
71 changes: 63 additions & 8 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ jobs:
remote_branch: origin/main
pr_sha: ${{ github.event.pull_request.head.sha }}

test:
runs-on: ubuntu-latest
tests:
strategy:
matrix:
os:
- "ubuntu"
- "macos"
- "windows"

runs-on: ${{ matrix.os }}-latest

concurrency:
group: ci-main-tests-${{ github.ref }}
group: ci-main-tests-${{ matrix.os }}-${{ github.ref }}
cancel-in-progress: true

defaults:
Expand All @@ -39,7 +47,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
- name: Install dependencies with conda for linux/macos
uses: conda-incubator/setup-miniconda@v3
if: ${{ matrix.os != 'windows' }}
with:
miniforge-version: latest
environment-file: conda/dev.yaml
Expand All @@ -48,6 +58,17 @@ jobs:
auto-update-conda: true
conda-solver: libmamba

- name: Install dependencies with conda for windows
uses: conda-incubator/setup-miniconda@v3
if: ${{ matrix.os == 'windows' }}
with:
miniforge-version: latest
environment-file: conda/dev-win.yaml
channels: conda-forge,nodefaults
activate-environment: scicookie
auto-update-conda: true
conda-solver: libmamba

- name: Check poetry.lock
run: poetry check

Expand All @@ -57,19 +78,53 @@ jobs:
poetry install
- name: Run tests
if: ${{ matrix.os != 'windows' }}
run: makim tests.unittest

- name: Run style checks
run: |
pre-commit install
makim tests.lint
- name: Run tests
if: ${{ matrix.os == 'windows' }}
run: pytest -s -vv --template src/scicookie tests

# - name: Semantic Release PR Title Check
# uses: osl-incubator/[email protected]
# if: success() || failure()
# with:
# convention-name: conventionalcommits

linter:
runs-on: ubuntu-latest

concurrency:
group: ci-main-linter-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4

- name: Install dependencies with conda for linux/macos
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
activate-environment: scicookie
auto-update-conda: true
conda-solver: libmamba

- name: Install dependencies
run: |
poetry config virtualenvs.create false
poetry install
- name: Run style checks
run: |
pre-commit install
makim tests.lint
smoke-test:
runs-on: ubuntu-latest
concurrency:
Expand Down
15 changes: 15 additions & 0 deletions conda/dev-win.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: scicookie
channels:
- nodefaults
- conda-forge
dependencies:
- m2-bash
- git
- python >=3.8.1,<3.12
- poetry >=1.5
- nodejs
- compilers
- pip
- pip:
- makim==1.15.1
- paginate
2 changes: 1 addition & 1 deletion poetry.lock

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

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ include = [
[tool.poetry.dependencies]
python = ">=3.8.1,<4"
cookiecutter = "2.6.0"
sh = ">=2.0.4"
colorama = ">=0.4.6"
inquirer = ">=3.1.3"
pyyaml = ">=6.0.1"
nodejs-wheel = ">=20.12"
nodejs-wheel = ">=20.13.0-1"
pre-commit-hooks = ">=0.4.6"


Expand Down Expand Up @@ -58,7 +57,7 @@ exclude = '''(?x)(
module = [
"colorama",
"inquirer",
"sh",
"cookiecutter.main",
"yaml",
"pre_commit_hooks",
]
Expand Down
35 changes: 4 additions & 31 deletions src/scicookie/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import argparse
import json
import os
import sys

from pathlib import Path
from typing import Union

import sh
from cookiecutter.main import cookiecutter

from scicookie.logs import SciCookieErrorType, SciCookieLogs
from scicookie.profile import Profile
Expand Down Expand Up @@ -58,10 +56,9 @@ def _get_cookiecutter_default_answer(
return answer_definition[0]


def call_cookiecutter(profile: Profile, answers: dict): # noqa: PLR0912
def call_cookiecutter(profile: Profile, answers: dict):
"""Call cookiecutter/cookiecutter with the parameters from the TUI."""
answers_profile = {}
cookie_args = []
questions = profile.config

with open(COOKIECUTTER_FILE_PATH) as f:
Expand Down Expand Up @@ -100,32 +97,8 @@ def call_cookiecutter(profile: Profile, answers: dict): # noqa: PLR0912
choice_id = f"use_{choice.replace('-', '_')}"
answers_profile[choice_id] = "yes"

for question_id, answer in answers_profile.items():
cookie_args.append(f"{question_id}={answer}")

sh_extras = {
"_in": sys.stdin,
"_out": sys.stdout,
"_err": sys.stderr,
"_no_err": True,
"_env": os.environ,
"_bg": True,
"_bg_exc": False,
}

p = sh.cookiecutter("--no-input", PACKAGE_PATH, *cookie_args, **sh_extras)

try:
p.wait()
except sh.ErrorReturnCode as e:
SciCookieLogs.raise_error(
str(e), SciCookieErrorType.SH_ERROR_RETURN_CODE
)
except KeyboardInterrupt:
pid = p.pid
p.kill()
SciCookieLogs.raise_error(
f"Process {pid} killed.", SciCookieErrorType.SH_KEYBOARD_INTERRUPT
cookiecutter(
str(PACKAGE_PATH), no_input=True, extra_context=answers_profile
)


Expand Down

0 comments on commit 41b80b8

Please sign in to comment.