1
1
import os
2
- import sys
3
2
4
- from pkg_resources import normalize_path
5
3
from setuptools import find_packages , setup
6
- from setuptools .command .test import test as TestCommand
7
-
8
- # Hack to silence atexit traceback in newer python versions
9
- try :
10
- import multiprocessing # noqa: F401
11
- except ImportError :
12
- pass
13
4
14
5
DESCRIPTION = "MongoEngine is a Python Object-Document Mapper for working with MongoDB."
15
6
@@ -27,62 +18,6 @@ def get_version(version_tuple):
27
18
return "." .join (map (str , version_tuple ))
28
19
29
20
30
- class PyTest (TestCommand ):
31
- """Will force pytest to search for tests inside the build directory
32
- for 2to3 converted code (used by tox), instead of the current directory.
33
- Required as long as we need 2to3
34
-
35
- Known Limitation: https://tox.readthedocs.io/en/latest/example/pytest.html#known-issues-and-limitations
36
- Source: https://www.hackzine.org/python-testing-with-pytest-and-2to3-plus-tox-and-travis-ci.html
37
- """
38
-
39
- # https://pytest.readthedocs.io/en/2.7.3/goodpractises.html#integration-with-setuptools-test-commands
40
- # Allows to provide pytest command argument through the test runner command `python setup.py test`
41
- # e.g: `python setup.py test -a "-k=test"`
42
- # This only works for 1 argument though
43
- user_options = [("pytest-args=" , "a" , "Arguments to pass to py.test" )]
44
-
45
- def initialize_options (self ):
46
- TestCommand .initialize_options (self )
47
- self .pytest_args = ""
48
-
49
- def finalize_options (self ):
50
- TestCommand .finalize_options (self )
51
- self .test_args = ["tests" ]
52
- self .test_suite = True
53
-
54
- def run_tests (self ):
55
- # import here, cause outside the eggs aren't loaded
56
- import pytest
57
- from pkg_resources import _namespace_packages
58
-
59
- # Purge modules under test from sys.modules. The test loader will
60
- # re-import them from the build location. Required when 2to3 is used
61
- # with namespace packages.
62
- if sys .version_info >= (3 ,) and getattr (self .distribution , "use_2to3" , False ):
63
- module = self .test_args [- 1 ].split ("." )[0 ]
64
- if module in _namespace_packages :
65
- del_modules = []
66
- if module in sys .modules :
67
- del_modules .append (module )
68
- module += "."
69
- for name in sys .modules :
70
- if name .startswith (module ):
71
- del_modules .append (name )
72
- map (sys .modules .__delitem__ , del_modules )
73
-
74
- # Run on the build directory for 2to3-built code
75
- # This will prevent the old 2.x code from being found
76
- # by py.test discovery mechanism, that apparently
77
- # ignores sys.path..
78
- ei_cmd = self .get_finalized_command ("egg_info" )
79
- self .test_args = [normalize_path (ei_cmd .egg_base )]
80
-
81
- cmd_args = self .test_args + ([self .pytest_args ] if self .pytest_args else [])
82
- errno = pytest .main (cmd_args )
83
- sys .exit (errno )
84
-
85
-
86
21
# Dirty hack to get version number from monogengine/__init__.py - we can't
87
22
# import it as it depends on PyMongo and PyMongo isn't installed until this
88
23
# file is read
@@ -107,22 +42,14 @@ def run_tests(self):
107
42
"Topic :: Software Development :: Libraries :: Python Modules" ,
108
43
]
109
44
110
- extra_opts = {
111
- "packages" : find_packages (exclude = ["tests" , "tests.*" ]),
112
- "tests_require" : [
113
- "pytest" ,
114
- "pytest-cov" ,
115
- "coverage" ,
116
- "blinker" ,
117
- "Pillow>=7.0.0" ,
118
- ],
119
- }
120
-
121
- if "test" in sys .argv :
122
- extra_opts ["packages" ] = find_packages ()
123
- extra_opts ["package_data" ] = {
124
- "tests" : ["fields/mongoengine.png" , "fields/mongodb_leaf.png" ]
125
- }
45
+ install_require = ["pymongo>=3.4,<5.0" ]
46
+ tests_require = [
47
+ "pytest" ,
48
+ "pytest-cov" ,
49
+ "coverage" ,
50
+ "blinker" ,
51
+ "Pillow>=7.0.0" ,
52
+ ]
126
53
127
54
setup (
128
55
name = "mongoengine" ,
@@ -140,7 +67,9 @@ def run_tests(self):
140
67
platforms = ["any" ],
141
68
classifiers = CLASSIFIERS ,
142
69
python_requires = ">=3.7" ,
143
- install_requires = ["pymongo>=3.4,<5.0" ],
144
- cmdclass = {"test" : PyTest },
145
- ** extra_opts
70
+ install_requires = install_require ,
71
+ extras_require = {
72
+ "test" : tests_require ,
73
+ },
74
+ packages = find_packages (exclude = ["tests" , "tests.*" ]),
146
75
)
0 commit comments