Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1dbad1

Browse files
authored
Make it possible to package and install mypyc (mypyc/mypyc#521)
There are a couple pieces to this: * Write a setup.py - this is heavily cribbed from mypy's * Move lib-rt and external/mypy underneath the mypyc directory so that they can be mypyc's "package_data" * Have `mypyc/__init__.py` adjust sys.path so that the copy of mypy is found
1 parent e1d3df8 commit a1dbad1

19 files changed

Lines changed: 145 additions & 21 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ test_capi
1313
/dmypy.json
1414
/.dmypy.json
1515
/.mypyc-flake8-cache.json
16+
/build

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "mypy"]
2-
path = external/mypy
1+
[submodule "mypyc/external/mypy"]
2+
path = mypyc/external/mypy
33
url = https://github.com/python/mypy

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ before_install: |
6464
pip install -U pip setuptools wheel
6565
6666
install:
67-
- pip install -r external/mypy/test-requirements.txt
67+
- pip install -r mypyc/external/mypy/test-requirements.txt
6868

6969
script: |
7070
set -e
71-
export PYTHONPATH=`pwd`/external/mypy
7271
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
7372
export PYTHONCONFIG="$PYTHONDIR/bin/python-config"
7473
export LD_LIBRARY_PATH="$PYTHONDIR/lib"

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,13 @@ Optionally create a virtualenv (recommended):
4646

4747
Then install the dependencies:
4848

49-
$ python3 -m pip install -r external/mypy/test-requirements.txt
50-
51-
You need to have the `mypy` subdirectory in your `PYTHONPATH`:
52-
53-
$ export PYTHONPATH=`pwd`/external/mypy
49+
$ python3 -m pip install -r mypyc/external/mypy/test-requirements.txt
5450

5551
Now you can run the tests:
5652

5753
$ pytest mypyc
5854

59-
Look at the [issue tracker](https://github.com/JukkaL/mypyc/issues)
55+
Look at the [issue tracker](https://github.com/mypyc/mypyc/issues)
6056
for things to work on. Please express your interest in working on an
6157
issue by adding a comment before doing any significant work, since
6258
development is currently very active and there is real risk of duplicate

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ environment:
1616
install:
1717
- "git submodule update --init --recursive"
1818
- "%PYTHON%\\python.exe -m pip install -U pip setuptools wheel"
19-
- "%PYTHON%\\python.exe -m pip install -U -r external/mypy/test-requirements.txt"
19+
- "%PYTHON%\\python.exe -m pip install -U -r mypyc/external/mypy/test-requirements.txt"
2020

2121
build: off
2222

2323
test_script:
24-
- "SET PYTHONPATH=%CD%\\external\\mypy"
2524
- "%PYTHON%\\python.exe -m pytest mypyc"
2625

2726
skip_commits:

conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# need to import mypyc to trigger the path shenanigans that cause mypy to be found
2+
import mypyc
3+
14
pytest_plugins = [
25
'mypy.test.data',
36
]

mypyc/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import os.path
3+
4+
# mypyc depends on a copy of mypy installed as package-data that won't
5+
# live in the normal python path (to avoid potential conflicts with an
6+
# installed mypy). In order to make sure we find it, we perform
7+
# sys.path shenanigans here when mypyc is first imported.
8+
base_path = os.path.dirname(__file__)
9+
mypy_path = os.path.abspath(os.path.join(base_path, 'external', 'mypy'))
10+
sys.path.insert(0, mypy_path)
11+
12+
# Make sure that we can find mypy and that it is the *right* mypy. If
13+
# mypy was imported before mypyc was, our path manipulations might
14+
# have been too late, and this assert will catch the problem.
15+
import mypy
16+
assert mypy.__file__ == os.path.join(mypy_path, 'mypy', '__init__.py'), (
17+
"Found a mypy other than the one packaged with mypyc!")

mypyc/build.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
if MYPY:
3434
from typing import NoReturn
3535

36-
base_path = os.path.join(os.path.dirname(__file__), '..')
37-
sys.path.insert(0, os.path.join(base_path, 'external/mypy'))
38-
3936
from mypy.main import process_options
4037
from mypy.errors import CompileError
4138
from mypy.options import Options
@@ -224,7 +221,7 @@ def shared_lib_name(modules: List[str]) -> str:
224221

225222
def include_dir() -> str:
226223
"""Find the path of the lib-rt dir that needs to be included"""
227-
return os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'lib-rt')
224+
return os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib-rt')
228225

229226

230227
def generate_c(sources: List[BuildSource], options: Options,
File renamed without changes.

0 commit comments

Comments
 (0)