1
|
|
|
""" |
2
|
|
|
Module that generates Conda recipes and environment files. |
3
|
|
|
|
4
|
|
|
Original source: https://github.com/dmyersturnbull/tyrannosaurus |
5
|
|
|
Copyright 2020–2021 Douglas Myers-Turnbull |
6
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
you may not use this file except in compliance with the License. |
8
|
|
|
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
""" |
10
|
|
|
|
11
|
|
|
from __future__ import annotations |
12
|
|
|
|
13
|
|
|
import logging |
14
|
|
|
from pathlib import Path |
15
|
|
|
from typing import Optional, Sequence |
16
|
|
|
|
17
|
|
|
from grayskull.base.factory import GrayskullFactory |
18
|
|
|
from grayskull.config import Configuration |
19
|
|
|
|
20
|
|
|
from tyrannosaurus.context import Context |
21
|
|
|
from tyrannosaurus.sync import Sync |
22
|
|
|
|
23
|
|
|
logger = logging.getLogger(__package__) |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class Recipe: |
27
|
|
|
def __init__(self, context: Context): |
28
|
|
|
self.context = context |
29
|
|
|
|
30
|
|
|
def create(self, output_dir: Optional[Path]) -> Sequence[str]: |
31
|
|
|
""" |
32
|
|
|
Creates the recipe file. |
33
|
|
|
|
34
|
|
|
Args: |
35
|
|
|
output_dir: Probably called "recipes" |
36
|
|
|
""" |
37
|
|
|
context = self.context |
38
|
|
|
wt = output_dir / context.project |
39
|
|
|
yaml_path = wt / "meta.yaml" |
40
|
|
|
# ex: yaml_path = "tyrannosaurus/meta.yaml" |
41
|
|
|
if yaml_path.exists(): |
42
|
|
|
context.delete_exact_path(yaml_path, False) |
43
|
|
|
wt.mkdir(parents=True, exist_ok=True) |
44
|
|
|
config = Configuration( |
45
|
|
|
name=context.poetry("name"), |
46
|
|
|
version=context.poetry("version"), |
47
|
|
|
) |
48
|
|
|
skull = GrayskullFactory.create_recipe("pypi", config, context.poetry("name")) |
49
|
|
|
# skull.generate_recipe(str(output_dir), mantainers=context.source("maintainers").split(",")) |
50
|
|
|
# TODO: maintainers |
51
|
|
|
skull.save(yaml_path) |
52
|
|
|
logger.debug(f"Generated a new recipe at {output_dir}/meta.yaml") |
53
|
|
|
helper = Sync(context) |
54
|
|
|
lines = helper.fix_recipe_internal(yaml_path) |
55
|
|
|
logger.debug(f"Fixed recipe at {yaml_path}/meta.yaml") |
56
|
|
|
return lines |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
__all__ = ["Recipe"] |
60
|
|
|
|