Skip to content

Commit a3612d5

Browse files
Change to ruamel yaml (sagemath#23)
* Modify infra to add ruamel yaml * __main__ small improvements * Refactoring Selectors._parser * Refactoring Selectors * Refactoring RecipeItem * Refactored section base * Refactoring section and part of the base recipe * Renamed base recipe and refactoring * Refactoring pypi class and clean up
1 parent 7a1423d commit a3612d5

19 files changed

+670
-548
lines changed

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[settings]
22
line_length=88
3-
known_third_party=requests,pyyaml,yaml,pytest
3+
known_third_party=requests,ruamel,yaml,pytest
44
multi_line_output=3
55
include_trailing_comma=True
66
force_grid_wrap=0

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ repos:
1717
- id: fix-encoding-pragma
1818
args: [--remove]
1919
- id: check-yaml
20+
exclude: tests
2021
- id: check-toml
2122
- id: check-json
2223
- id: check-merge-conflict

azure-pipelines.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
variables:
22
- group: Codecov
33
- name: grayskull_deps
4-
value: pytest pytest-azurepipelines pytest-xdist pytest-cov requests pyyaml codecov
4+
value: pytest pytest-azurepipelines pytest-xdist pytest-cov requests ruamel.yaml codecov ruamel.yaml.jinja2
55

66
jobs:
77
- job:

grayskull/__main__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def main():
99
parser.add_argument(
1010
"repo_type",
1111
nargs=2,
12-
help="Specify the repository (PyPi, Cran) and the package name.",
12+
help="Specify the repository (pypi, cran) and the package name.",
1313
)
1414
parser.add_argument(
1515
"--heman", "--shera", default=False, action="store_true", dest="grayskull_power"
@@ -21,16 +21,17 @@ def main():
2121
default=".",
2222
help="Path to where the recipe will be created",
2323
)
24-
parser.add_argument("--version", "-v", dest="version", help="Package version ")
24+
parser.add_argument(
25+
"--version", "-v", default="", dest="version", help="Package version "
26+
)
2527

2628
args = parser.parse_args()
2729

2830
if args.grayskull_power:
2931
print("By the power of Grayskull...\nI have the power!")
3032
sys.exit()
3133

32-
options_generator = args.repo_type + [args.version if args.version else ""]
33-
recipe = GrayskullFactory.create_recipe(*options_generator)
34+
recipe = GrayskullFactory.create_recipe(args.repo_type, args.version)
3435
recipe.to_file(args.output)
3536

3637

grayskull/base/__init__.py

-162
Original file line numberDiff line numberDiff line change
@@ -1,162 +0,0 @@
1-
from dataclasses import dataclass, field, make_dataclass
2-
from subprocess import check_output
3-
from typing import List
4-
5-
import requests
6-
import yaml
7-
8-
9-
def get_valid_fields(fields):
10-
return [
11-
(name.replace("-", "_"), "typing.Any", field(default=None)) for name in fields
12-
]
13-
14-
15-
FIELDS = {
16-
"package": {"name", "version"},
17-
"source": {
18-
"fn",
19-
"url",
20-
"md5",
21-
"sha1",
22-
"sha256",
23-
"path",
24-
"path_via_symlink",
25-
"git_url",
26-
"git_tag",
27-
"git_branch",
28-
"git_rev",
29-
"git_depth",
30-
"hg_url",
31-
"hg_tag",
32-
"svn_url",
33-
"svn_rev",
34-
"svn_ignore_externals",
35-
"folder",
36-
"no_hoist",
37-
"patches",
38-
},
39-
"build": {
40-
"number",
41-
"string",
42-
"entry_points",
43-
"osx_is_app",
44-
"disable_pip",
45-
"features",
46-
"track_features",
47-
"preserve_egg_dir",
48-
"no_link",
49-
"binary_relocation",
50-
"script",
51-
"noarch",
52-
"noarch_python",
53-
"has_prefix_files",
54-
"binary_has_prefix_files",
55-
"ignore_prefix_files",
56-
"detect_binary_files_with_prefix",
57-
"skip_compile_pyc",
58-
"rpaths",
59-
"rpaths_patcher",
60-
"script_env",
61-
"always_include_files",
62-
"skip",
63-
"msvc_compiler",
64-
"pin_depends",
65-
"include_recipe", # pin_depends is experimental still
66-
"preferred_env",
67-
"preferred_env_executable_paths",
68-
"run_exports",
69-
"ignore_run_exports",
70-
"requires_features",
71-
"provides_features",
72-
"force_use_keys",
73-
"force_ignore_keys",
74-
"merge_build_host",
75-
},
76-
"outputs": {
77-
"name",
78-
"version",
79-
"number",
80-
"script",
81-
"script_interpreter",
82-
"build",
83-
"requirements",
84-
"test",
85-
"about",
86-
"extra",
87-
"files",
88-
"type",
89-
"run_exports",
90-
},
91-
"requirements": {"build", "host", "run", "conflicts", "run_constrained"},
92-
"app": {"entry", "icon", "summary", "type", "cli_opts", "own_environment"},
93-
"test": {
94-
"requires",
95-
"commands",
96-
"files",
97-
"imports",
98-
"source_files",
99-
"downstreams",
100-
},
101-
"about": {
102-
"home",
103-
"dev_url",
104-
"doc_url",
105-
"doc_source_url",
106-
"license_url", # these are URLs
107-
"license",
108-
"summary",
109-
"description",
110-
"license_family", # text
111-
"identifiers",
112-
"tags",
113-
"keywords", # lists
114-
"license_file",
115-
"readme", # paths in source tree
116-
},
117-
}
118-
119-
120-
Package = make_dataclass("Package", get_valid_fields(FIELDS["package"]))
121-
Source = make_dataclass("Source", get_valid_fields(FIELDS["source"]))
122-
Build = make_dataclass("Build", get_valid_fields(FIELDS["build"]))
123-
Outputs = make_dataclass("Outputs", get_valid_fields(FIELDS["outputs"]))
124-
Requirements = make_dataclass("Requirements", get_valid_fields(FIELDS["requirements"]))
125-
App = make_dataclass("App", get_valid_fields(FIELDS["app"]))
126-
Test = make_dataclass("Test", get_valid_fields(FIELDS["test"]))
127-
About = make_dataclass("About", get_valid_fields(FIELDS["about"]))
128-
129-
130-
@dataclass
131-
class Extra:
132-
recipe_maintainers: List[str] = field(default_factory=list)
133-
134-
def add_maintainer(self, name: str):
135-
self.recipe_maintainers.append(name)
136-
137-
def add_r_group(self):
138-
self.recipe_maintainers.append(r"conda-forge/r")
139-
140-
@staticmethod
141-
def _get_git_current_user_metadata() -> dict:
142-
git_out = check_output(["git", "config", "user.name"])
143-
return requests.get(
144-
url="https://api.github.com/search/users", params={"q": git_out.strip()},
145-
).json()
146-
147-
def add_git_current_user(self) -> str:
148-
try:
149-
github_search = Extra._get_git_current_user_metadata()
150-
if github_search["total_count"] == 1:
151-
github_login = github_search["items"][0]["login"]
152-
self.recipe_maintainers.append(github_login)
153-
return github_login
154-
except Exception:
155-
pass
156-
self.recipe_maintainers.append("AddYourGitHubIdHere")
157-
return "AddYourGitHubIdHere"
158-
159-
160-
class GrayDumper(yaml.Dumper):
161-
def increase_indent(self, flow=False, indentless=False):
162-
return super(GrayDumper, self).increase_indent(flow, False)

0 commit comments

Comments
 (0)