Skip to content

Commit 13db587

Browse files
fix(mathy_alpha_sm): include model data and readme
1 parent cbee0fb commit 13db587

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

libraries/mathy_alpha_sm/MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

libraries/mathy_alpha_sm/setup.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
# coding: utf8
3-
from __future__ import unicode_literals
3+
from typing import List
44
import io
55
import json
66
from os import path, walk
@@ -13,15 +13,17 @@ def load_meta(fp):
1313
return json.load(f)
1414

1515

16-
def list_files(data_dir):
16+
def list_files(data_dir: str, root: str) -> List[str]:
1717
output = []
18-
for root, _, filenames in walk(data_dir):
18+
package_dir = path.join(root, data_dir)
19+
for folder, _, filenames in walk(package_dir):
20+
if "__pycache__" in folder:
21+
continue
1922
for filename in filenames:
2023
if not filename.startswith("."):
21-
output.append(path.join(root, filename))
22-
output = [path.relpath(p, path.dirname(data_dir)) for p in output]
23-
output.append("model.config.json")
24-
return output
24+
output.append(path.join(folder, filename))
25+
rel_output = [path.relpath(p, package_dir) for p in output]
26+
return rel_output
2527

2628

2729
def list_requirements(meta):
@@ -39,9 +41,7 @@ def setup_package():
3941
meta_path = path.join(root, "model.config.json")
4042
meta = load_meta(meta_path)
4143
model_name = meta["name"]
42-
model_dir = path.join(model_name, model_name)
43-
copy(meta_path, path.join(model_name))
44-
copy(meta_path, model_dir)
44+
model_dir = path.join(model_name)
4545
setup(
4646
name=model_name,
4747
description=meta["description"],
@@ -51,7 +51,7 @@ def setup_package():
5151
version=meta["version"],
5252
license=meta["license"],
5353
packages=[model_name],
54-
package_data={model_name: list_files(model_dir)},
54+
package_data={model_name: list_files(model_dir, root)},
5555
install_requires=list_requirements(meta),
5656
zip_safe=False,
5757
)

libraries/mathy_alpha_sm/tools/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
set -e
33
. .env/bin/activate
44
echo "Replacing package readme with root..."
5-
cp ../../README.md ./
5+
cp ../../README.md ./mathy_alpha_sm/
66
echo "Build python package..."
77
python setup.py sdist bdist_wheel

libraries/mathy_python/mathy/models.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def package(
233233
shutil.copyfile(file_name, main_path / f)
234234
create_file(output_path / "model.config.json", srsly.json_dumps(meta, indent=2))
235235
create_file(output_path / "setup.py", TEMPLATE_SETUP)
236-
create_file(output_path / "MANIFEST.in", TEMPLATE_MANIFEST)
237236
create_file(package_path / "__init__.py", TEMPLATE_INIT)
238237
msg.good("Successfully created package '{}'".format(package_path), main_path)
239238
msg.text("To build the package, run `python setup.py sdist` in this directory.")
@@ -248,7 +247,7 @@ def create_file(file_path: Path, contents: str):
248247
TEMPLATE_SETUP = """
249248
#!/usr/bin/env python
250249
# coding: utf8
251-
from __future__ import unicode_literals
250+
from typing import List
252251
import io
253252
import json
254253
from os import path, walk
@@ -261,15 +260,17 @@ def load_meta(fp):
261260
return json.load(f)
262261
263262
264-
def list_files(data_dir):
263+
def list_files(data_dir: str, root: str) -> List[str]:
265264
output = []
266-
for root, _, filenames in walk(data_dir):
265+
package_dir = path.join(root, data_dir)
266+
for folder, _, filenames in walk(package_dir):
267+
if "__pycache__" in folder:
268+
continue
267269
for filename in filenames:
268270
if not filename.startswith("."):
269-
output.append(path.join(root, filename))
270-
output = [path.relpath(p, path.dirname(data_dir)) for p in output]
271-
output.append("model.config.json")
272-
return output
271+
output.append(path.join(folder, filename))
272+
rel_output = [path.relpath(p, package_dir) for p in output]
273+
return rel_output
273274
274275
275276
def list_requirements(meta):
@@ -287,9 +288,7 @@ def setup_package():
287288
meta_path = path.join(root, "model.config.json")
288289
meta = load_meta(meta_path)
289290
model_name = meta["name"]
290-
model_dir = path.join(model_name, model_name))
291-
copy(meta_path, path.join(model_name))
292-
copy(meta_path, model_dir)
291+
model_dir = path.join(model_name)
293292
setup(
294293
name=model_name,
295294
description=meta["description"],
@@ -299,20 +298,14 @@ def setup_package():
299298
version=meta["version"],
300299
license=meta["license"],
301300
packages=[model_name],
302-
package_data={model_name: list_files(model_dir)},
301+
package_data={model_name: list_files(model_dir, root)},
303302
install_requires=list_requirements(meta),
304303
zip_safe=False,
305304
)
306305
307306
308307
if __name__ == "__main__":
309-
setup_package()
310-
""".strip()
311-
312-
313-
TEMPLATE_MANIFEST = """
314-
include model.config.json
315-
""".strip()
308+
setup_package()""".strip()
316309

317310

318311
TEMPLATE_INIT = """

0 commit comments

Comments
 (0)