From e7f698ac5515c4df0d3fd2b5099c2205a79d65c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E4=B9=9D=E9=BC=8E?= <109224573@qq.com> Date: Thu, 11 Nov 2021 03:25:54 +0800 Subject: [PATCH] move mypyc to console_scripts (#11494) Description See mypyc/mypyc#893 --- scripts/mypyc => mypyc/__main__.py | 3 ++- mypyc/doc/dev-intro.md | 4 ++-- mypyc/test/test_commandline.py | 3 +-- setup.py | 2 +- tox.ini | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename scripts/mypyc => mypyc/__main__.py (98%) mode change 100755 => 100644 diff --git a/scripts/mypyc b/mypyc/__main__.py old mode 100755 new mode 100644 similarity index 98% rename from scripts/mypyc rename to mypyc/__main__.py index 235814042d27..a11426001f77 --- a/scripts/mypyc +++ b/mypyc/__main__.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Mypyc command-line tool. Usage: @@ -27,6 +26,7 @@ ) """ + def main() -> None: build_dir = 'build' # can this be overridden?? try: @@ -49,5 +49,6 @@ def main() -> None: cmd = subprocess.run([sys.executable, setup_file, 'build_ext', '--inplace'], env=env) sys.exit(cmd.returncode) + if __name__ == '__main__': main() diff --git a/mypyc/doc/dev-intro.md b/mypyc/doc/dev-intro.md index 11de9cdc0c8b..bf0c1a836874 100644 --- a/mypyc/doc/dev-intro.md +++ b/mypyc/doc/dev-intro.md @@ -73,11 +73,11 @@ compiled code. For example, you may want to do interactive testing or to run benchmarks. This is also handy if you want to inspect the generated C code (see Inspecting Generated C). -Run `scripts/mypyc` to compile a module to a C extension using your +Run `mypyc` to compile a module to a C extension using your development version of mypyc: ``` -$ scripts/mypyc program.py +$ mypyc program.py ``` This will generate a C extension for `program` in the current working diff --git a/mypyc/test/test_commandline.py b/mypyc/test/test_commandline.py index 5dae26d294ab..5c80d0fddb1d 100644 --- a/mypyc/test/test_commandline.py +++ b/mypyc/test/test_commandline.py @@ -47,8 +47,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None: out = b'' try: # Compile program - cmd = subprocess.run([sys.executable, - os.path.join(base_path, 'scripts', 'mypyc')] + args, + cmd = subprocess.run([sys.executable, '-m', 'mypyc', *args], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd='tmp') if 'ErrorOutput' in testcase.name or cmd.returncode != 0: out += cmd.stdout diff --git a/setup.py b/setup.py index 04cd455070d7..1a43c915d362 100644 --- a/setup.py +++ b/setup.py @@ -181,11 +181,11 @@ def run(self): ext_modules=ext_modules, packages=find_packages(), package_data={'mypy': package_data}, - scripts=['scripts/mypyc'], entry_points={'console_scripts': ['mypy=mypy.__main__:console_entry', 'stubgen=mypy.stubgen:main', 'stubtest=mypy.stubtest:main', 'dmypy=mypy.dmypy.client:console_entry', + 'mypyc=mypyc.__main__:main', ]}, classifiers=classifiers, cmdclass=cmdclass, diff --git a/tox.ini b/tox.ini index ac7cdc72fdb7..44334688b0ad 100644 --- a/tox.ini +++ b/tox.ini @@ -51,7 +51,7 @@ description = type check ourselves basepython = python3.7 commands = python -m mypy --config-file mypy_self_check.ini -p mypy -p mypyc - python -m mypy --config-file mypy_self_check.ini misc/proper_plugin.py scripts/mypyc + python -m mypy --config-file mypy_self_check.ini misc/proper_plugin.py [testenv:docs] description = invoke sphinx-build to build the HTML docs