Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions bin/mapry-to

This file was deleted.

8 changes: 8 additions & 0 deletions mapry/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Link to ``mapry.main`` so that you can execute it with ``python`` CLI."""

import sys

import mapry.main

if __name__ == "__main__":
sys.exit(mapry.main.run(prog="mapry"))
20 changes: 18 additions & 2 deletions mapry/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,20 @@ def generate_py(schema: mapry.Schema, outdir: pathlib.Path) -> int:
return 0


def main() -> int:
"""Execute the main routine."""
def run(prog: str) -> int:
"""
Execute the main routine.

:param prog:
name of the program as it will be executed.

This differs between "mapry-to" (as a console script) and
"mapry" (as a Python module executed from ``__main__.py``)

:return: exit code
"""
parser = argparse.ArgumentParser(
prog=prog,
description="Generate the code for de/serialization of object graphs "
"from JSONables.")
subparsers = parser.add_subparsers(
Expand Down Expand Up @@ -261,3 +272,8 @@ def main() -> int:
return generate_py(schema=schema, outdir=outdir)
else:
raise NotImplementedError('command: {}'.format(command))


def entry_point() -> int:
"""Provide the entry point as the console script."""
return run(prog="mapry-to")
5 changes: 5 additions & 0 deletions precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def main() -> int:
str(repo_root / "README.rst")])

for pth in sorted((repo_root / "mapry").glob("**/*.py")):
# ``__main__.py``'s cause doctest to go banana, so we need to skip them;
# see https://stackoverflow.com/questions/58731519/doctest-fails-on-main-py
if pth.name == '__main__.py':
continue

subprocess.check_call([sys.executable, "-m", "doctest", str(pth)])

print("pyicontract-lint'ing...")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@
# yapf: enable
},
py_modules=['mapry', 'mapry_meta'],
scripts=['bin/mapry-to'],
entry_points={"console_scripts": ["mapry-to = mapry.main:entry_point"]},
package_data={"mapry": ["py.typed"]})