Skip to content

Commit 80b0ea9

Browse files
authored
Merge pull request #45 from InvestmentSystems/44/new-package-structure
Reorganized package structure for pyi, typed inclusion
2 parents 2ee49d9 + 0b03548 commit 80b0ea9

File tree

10 files changed

+43
-32
lines changed

10 files changed

+43
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
CIBW_BUILD: cp${{ matrix.major }}${{ matrix.minor }}-*
5353
CIBW_BUILD_VERBOSITY: 1
5454
CIBW_BEFORE_TEST: pip install -r {project}/requirements-test.txt
55-
CIBW_TEST_COMMAND: pytest {project}
55+
CIBW_TEST_COMMAND: pytest {project}/test
5656
- uses: actions/upload-artifact@master
5757
with:
5858
name: dist

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include arraykit.pyi py.typed
1+
include arraykit/__init__.pyi arraykit/py.typed

performance/main.py renamed to performance/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,3 @@ def main():
298298

299299
if __name__ == '__main__':
300300
main()
301-

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ def get_long_description() -> str:
3939
'Programming Language :: Python :: 3.8',
4040
],
4141
keywords='numpy array',
42-
packages=[''],
43-
package_data={'': ['arraykit.pyi', 'py.typed']},
42+
packages=['arraykit'],
43+
package_dir={'arraykit': 'src'},
44+
package_data={'arraykit': ['__init__.pyi', 'py.typed']},
4445
include_package_data=True,
4546
ext_modules=[
4647
Extension(
47-
name='arraykit',
48-
sources=['arraykit.c'],
48+
name='arraykit._arraykit', # build into module
49+
sources=['src/_arraykit.c'],
4950
include_dirs=[np.get_include()],
50-
define_macros=[("AK_VERSION", AK_VERSION)],
51+
define_macros=[('AK_VERSION', AK_VERSION)],
5152
),
5253
],
5354
)

src/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from ._arraykit import *
2+
from ._arraykit import __version__

arraykit.pyi renamed to src/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import numpy as np # type: ignore
44

55
_T = tp.TypeVar('_T')
66

7+
__version__: str
8+
79
class ArrayGO:
810

911
values: np.array

arraykit.c renamed to src/_arraykit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,11 @@ static PyMethodDef arraykit_methods[] = {
630630
};
631631

632632
static struct PyModuleDef arraykit_module = {
633-
PyModuleDef_HEAD_INIT, "arraykit", NULL, -1, arraykit_methods,
633+
PyModuleDef_HEAD_INIT, "_arraykit", NULL, -1, arraykit_methods,
634634
};
635635

636636
PyObject *
637-
PyInit_arraykit(void)
637+
PyInit__arraykit(void)
638638
{
639639
import_array();
640640
PyObject *m = PyModule_Create(&arraykit_module);
File renamed without changes.

tasks.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
import sys
2-
import os
3-
import typing as tp
42

53
import invoke
64

5+
6+
ARTIFACTS = (
7+
'*.egg-info',
8+
'.hypothesis',
9+
'build',
10+
'dist',
11+
'src/*.so'
12+
)
13+
14+
715
@invoke.task
816
def clean(context):
917
'''Clean doc and build artifacts
1018
'''
11-
context.run(f"{sys.executable} setup.py develop --uninstall", echo=True)
19+
cmd = f'{sys.executable} -m pip uninstall --yes arraykit'
20+
context.run(cmd, echo=True, pty=True)
1221

13-
for artifact in ("*.egg-info", "*.so", "build", "dist", ".hypothesis"):
14-
context.run(f"rm -rf {artifact}", echo=True)
22+
for artifact in sorted(ARTIFACTS):
23+
context.run(f'rm -rf {artifact}', echo=True, pty=True)
1524

16-
# context.run("black .", echo=True)@task(clean)
1725

18-
@invoke.task
26+
@invoke.task(clean)
1927
def build(context):
20-
context.run(f"pip install -r requirements.txt", echo=True)
21-
context.run(f"{sys.executable} setup.py develop", echo=True)
28+
context.run('pip install -r requirements.txt', echo=True, pty=True)
29+
context.run(f'{sys.executable} -m pip install .', echo=True, pty=True)
30+
2231

23-
@invoke.task(pre=(clean, build))
32+
@invoke.task(build)
2433
def test(context):
2534
cmd = 'pytest -s --color no --disable-pytest-warnings --tb=native'
26-
context.run(cmd)
35+
context.run(cmd, echo=True, pty=True)
2736

28-
@invoke.task(pre=(clean, build))
37+
38+
@invoke.task(build)
2939
def performance(context):
30-
context.run(f"{sys.executable} performance/main.py", echo=True)
40+
context.run(f'{sys.executable} -m performance', echo=True, pty=True)
41+
3142

32-
@invoke.task(pre=(clean, build))
43+
@invoke.task
3344
def lint(context):
3445
'''Run pylint static analysis.
3546
'''
36-
context.run('pylint -f colorized test performance')
37-
47+
cmd = 'pylint -f colorized *.py performance src test'
48+
context.run(cmd, echo=True, pty=True)

test/test_pyi.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def from_module(cls, module):
4545

4646
class TestUnit(unittest.TestCase):
4747

48-
@unittest.skip('not sure if pyi is in right location')
48+
# @unittest.skip('not sure if pyi is in right location')
4949
def test_interface(self) -> None:
5050

51-
fp = os.path.join(os.path.dirname(ak.__file__), 'arraykit.pyi')
51+
fp = os.path.join(os.path.dirname(ak.__file__), '__init__.pyi')
5252

5353
with open(fp) as f:
5454
msg = f.read()
@@ -64,7 +64,3 @@ def test_interface(self) -> None:
6464

6565
if __name__ == '__main__':
6666
unittest.main()
67-
68-
69-
70-

0 commit comments

Comments
 (0)