Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
e60bd0fb
Commit
e60bd0fb
authored
4 years ago
by
Nathan Hertz
Browse files
Options
Downloads
Patches
Plain Diff
Finished generation of meta.yaml files. Next step is to automate conda build.
parent
32415143
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/setup_to_meta/setup_to_meta.py
+85
-33
85 additions, 33 deletions
src/setup_to_meta/setup_to_meta.py
with
85 additions
and
33 deletions
src/setup_to_meta/setup_to_meta.py
+
85
−
33
View file @
e60bd0fb
import
setuptools
,
importlib
,
subprocess
,
os
,
re
from
Setupdata
import
Setupdata
def
genera
te_metafile
(
s
et
up_dict
):
# Go through each entry in setup_data and pick out what info is needed
# Write to a file (support/conda/{name}/meta.yaml with all given data
for
field
,
value
in
setup_dict
.
items
()
:
def
wri
te_metafile
(
m
et
adata
,
filename
):
try
:
os
.
makedirs
(
filename
[:
-
10
])
except
FileExistsError
:
pass
# package:
# name:
# version:
# build:
# entry points:
# - 1
# script: {{ PYTHON }} setup.py install
# source:
# path:
# requirements:
# build = run:
# test:
# source files:
# requires:
# commands
# about:
# license = license family:
# summary:
pass
with
open
(
filename
,
'
w
'
)
as
f
:
f
.
write
(
metadata
)
def
generate_metafile
(
setup_dict
,
path
):
metadata
=
(
'
{{% set name =
"
{name}
"
%}}
\n
'
'
{{% set version =
"
{version}
"
%}}
\n
'
'
\n
'
'
package:
\n
'
'
name:
"
{{{{ name|lower }}}}
"
\n
'
'
version:
"
{{{{ version }}}}
"
\n
'
'
\n
'
'
build:
\n
'
).
format
(
name
=
setup_dict
[
"
name
"
],
version
=
setup_dict
[
"
version
"
]
)
if
'
entry_points
'
in
setup_dict
.
keys
():
metadata
+=
'
entry_points:
\n
'
for
ep
in
setup_dict
[
'
entry_points
'
]:
metadata
+=
'
- {}
\n
'
.
format
(
ep
)
metadata
+=
(
'
script: {{{{PYTHON}}}} setup.py install
\n
'
'
\n
'
'
source:
\n
'
'
path: {}
\n
'
.
format
(
path
))
metadata
+=
'
\n
'
if
'
install_requires
'
in
setup_dict
.
keys
():
metadata
+=
'
requirements:
\n
'
build_reqs
=
'
build:
\n
'
run_reqs
=
'
run:
\n
'
for
req
in
setup_dict
[
'
install_requires
'
].
split
(
'
,
'
):
build_reqs
+=
'
- {}
\n
'
.
format
(
req
)
run_reqs
+=
'
- {}
\n
'
.
format
(
req
)
metadata
+=
build_reqs
metadata
+=
run_reqs
if
'
tests_require
'
in
setup_dict
.
keys
():
metadata
+=
(
'
test:
\n
'
'
source_files:
\n
'
'
- test/
\n
'
'
requires:
\n
'
)
for
req
in
setup_dict
[
'
tests_require
'
].
split
(
'
,
'
):
metadata
+=
'
- {}
\n
'
.
format
(
req
)
metadata
+=
(
'
commands:
\n
'
'
- pytest -vv --log-level=DEBUG --showlocals
\n
'
)
metadata
+=
(
'
\n
'
'
about:
\n
'
'
license:
"
{0}
"
\n
'
'
license_family:
"
{0}
"
\n
'
'
summary:
"
{1}
"'
.
format
(
setup_dict
[
'
license
'
],
setup_dict
[
'
description
'
]))
return
metadata
def
data_to_dict
(
setup_data
):
data_dict
=
{}
r_entry
=
r
"
([a-z-_]+):
"
r_id
=
r
"
[a-zA-Z0-9-_]
"
r_ep
=
r
"
{{(?:
{0}
+):\s*(?P<values>(?:{0}+\s*=\s*[a-zA-Z0-9-_.]+:{0}+(?:,\s*)?)*)}}
"
.
format
(
r_id
)
r_ep
=
r
"
{{(?:
[a-zA-Z0-9-_.]
+):\s*(?P<values>(?:{0}+\s*=\s*[a-zA-Z0-9-_.]+:{0}+(?:,\s*)?)*)}}
"
.
format
(
r_id
)
for
d
in
setup_data
:
result
=
re
.
match
(
r_entry
,
d
)
...
...
@@ -45,10 +85,17 @@ def data_to_dict(setup_data):
value
=
re
.
match
(
r_ep
,
value
).
group
(
'
values
'
)
value
=
re
.
split
(
'
,\s*
'
,
value
)
data_dict
[
field
]
=
value
print
(
"
{}: {}
"
.
format
(
field
,
value
))
#
print("{}: {}".format(field, value))
return
data_dict
def
get_outputs
(
names
):
outputs
=
[]
for
name
in
names
:
outputs
.
append
(
"
support/conda/{}/meta.yaml
"
.
format
(
name
))
return
outputs
def
get_dirs
():
find
=
subprocess
.
run
([
'
find
'
,
'
.
'
,
'
-name
'
,
'
setup.py
'
],
stdout
=
subprocess
.
PIPE
)
dirs
=
find
.
stdout
.
decode
(
'
utf-8
'
).
split
(
'
\n
'
)
...
...
@@ -65,7 +112,12 @@ def get_names(dirs):
names
=
[]
for
d
in
dirs
:
if
d
!=
''
:
names
.
append
(
d
.
split
(
'
/
'
)[
-
1
])
name
=
d
.
split
(
'
/
'
)[
-
1
]
if
name
==
"
archive
"
:
# Case with ./services/archive having special dir structure
name
=
"
services
"
names
.
append
(
name
)
return
names
...
...
@@ -79,23 +131,23 @@ class Recipe:
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
dirs
=
get_dirs
()
self
.
names
=
get_names
(
self
.
dirs
)
# print(self.dirs)
# TODO: Make list of outputs = support/conda/{name}/meta.yaml
options
[
'
created
'
]
=
""
self
.
outputs
=
get_outputs
(
self
.
names
)
self
.
options
=
options
# TODO: Keep track of path in setup_dict
def
install
(
self
):
self
.
options
.
created
(
self
.
options
[
'
created
'
])
root
=
os
.
getcwd
()
for
d
in
self
.
dirs
:
for
i
,
d
in
enumerate
(
self
.
dirs
)
:
if
d
!=
''
:
os
.
chdir
(
d
)
proc
=
subprocess
.
run
([
'
python3
'
,
'
parse_setup.py
'
],
stdout
=
subprocess
.
PIPE
)
os
.
chdir
(
root
)
setup_data
=
(
proc
.
stdout
.
decode
(
'
utf-8
'
)).
split
(
'
\n
'
)
data_dict
=
data_to_dict
(
setup_data
)
generate_metafile
(
data_dict
)
metadata
=
generate_metafile
(
data_dict
,
d
)
write_metafile
(
metadata
,
self
.
outputs
[
i
])
self
.
options
.
created
(
self
.
outputs
[
i
])
return
self
.
options
.
created
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment