Skip to content

Commit

Permalink
Merge branch 'setuptools'
Browse files Browse the repository at this point in the history
  • Loading branch information
RKrahl committed Aug 11, 2022
2 parents 6288430 + 819db83 commit f06d824
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Changelog
Incompatible changes
--------------------

+ `#4`_, `#5`_: Move from `distutils` to `setuptools`. As a result,
the command classes defined by `distutils-pytest` need to be
explicitly passed in the `cmdclass` keyword argument to `setup()`.

+ `#3`_: Drop support for Python 3.3 and older.

Bug fixes and minor changes
Expand All @@ -15,6 +19,8 @@ Bug fixes and minor changes
+ `#3`_: Use :mod:`setuptools_scm` to manage the version number.

.. _#3: https://github.com/RKrahl/distutils-pytest/pull/3
.. _#4: https://github.com/RKrahl/distutils-pytest/issues/4
.. _#5: https://github.com/RKrahl/distutils-pytest/pull/5


0.1 (2016-04-01)
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Python
Required library packages
.........................

+ `setuptools`_

+ `pytest`_

Optional library packages
Expand Down Expand Up @@ -74,5 +76,6 @@ permissions and limitations under the License.

.. _pytest: http://pytest.org/
.. _PyPI site: https://pypi.org/project/distutils-pytest/
.. _setuptools: https://github.com/pypa/setuptools/
.. _setuptools_scm: https://github.com/pypa/setuptools_scm/
.. _Apache License: https://www.apache.org/licenses/LICENSE-2.0
28 changes: 6 additions & 22 deletions distutils_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,12 @@
import sys
import os
import os.path
from distutils.core import Command
import setuptools
from distutils.spawn import spawn

__version__ = "$VERSION"


def _inject_distutils_command():
"""Inject this module into the distutils.command package.
This is needed because distutils.dist.Distribution searches
commands by trying to import the respective module from this
package.
"""
import distutils.command
mod = sys.modules[__name__]
cmds = ['build_test', 'test']
for c in cmds:
sys.modules['distutils.command.%s' % c] = mod
setattr(distutils.command, c, mod)
i = distutils.command.__all__.index('clean')
distutils.command.__all__[i:i] = cmds

_inject_distutils_command()


class _tmpchdir:
"""Temporarily change the working directory.
"""
Expand All @@ -41,7 +22,7 @@ def __exit__(self, type, value, tb):
os.chdir(self.savedir)


class build_test(Command):
class build_test(setuptools.Command):
"""Dummy. This command is called at the beginning of test after
build. It does nothing, but it can be overridden by custom code
in setup.py to build the test environment.
Expand All @@ -56,7 +37,7 @@ def run(self):
pass


class test(Command):
class test(setuptools.Command):

description = "run the tests"
user_options = [
Expand Down Expand Up @@ -119,3 +100,6 @@ def run(self):
testcmd.append("--collect-only")
with _tmpchdir("tests"):
spawn(testcmd)


cmdclass = dict(build_test=build_test, test=test)
49 changes: 31 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
.. _pytest: http://pytest.org/
"""

import distutils.cmd
import distutils.command.build_py
import setuptools
from setuptools import setup
import setuptools.command.build_py
import distutils.command.sdist
from distutils.core import setup
import distutils.file_util
import distutils.log
from distutils import log
from glob import glob
import os
from pathlib import Path
Expand All @@ -27,11 +27,10 @@
import _meta
version = _meta.__version__
except ImportError:
distutils.log.warn("warning: cannot determine version number")
log.warn("warning: cannot determine version number")
version = "UNKNOWN"

docstring = __doc__
doclines = docstring.strip().split("\n")

class copy_file_mixin:
"""Distutils copy_file() mixin.
Expand All @@ -48,11 +47,11 @@ def copy_file(self, infile, outfile,
infile = Path(infile)
outfile = Path(outfile)
if outfile.name == infile.name:
distutils.log.info("copying (with substitutions) %s -> %s",
infile, outfile.parent)
log.info("copying (with substitutions) %s -> %s",
infile, outfile.parent)
else:
distutils.log.info("copying (with substitutions) %s -> %s",
infile, outfile)
log.info("copying (with substitutions) %s -> %s",
infile, outfile)
if not self.dry_run:
st = infile.stat()
try:
Expand All @@ -72,7 +71,7 @@ def copy_file(self, infile, outfile,
not self.force, link,
dry_run=self.dry_run)

class meta(distutils.cmd.Command):
class meta(setuptools.Command):
description = "generate meta files"
user_options = []
meta_template = '''
Expand All @@ -89,6 +88,9 @@ def run(self):
with Path("_meta.py").open("wt") as f:
print(self.meta_template % values, file=f)

# Note: Do not use setuptools for making the source distribution,
# rather use the good old distutils instead.
# Rationale: https://rhodesmill.org/brandon/2009/eby-magic/
class sdist(copy_file_mixin, distutils.command.sdist.sdist):
def run(self):
self.run_command('meta')
Expand All @@ -104,23 +106,24 @@ def run(self):
with Path(self.dist_dir, spec).open('wt') as outf:
outf.write(string.Template(inf.read()).substitute(subst))

class build_py(copy_file_mixin, distutils.command.build_py.build_py):
class build_py(copy_file_mixin, setuptools.command.build_py.build_py):
def run(self):
self.run_command('meta')
super().run()


with Path("README.rst").open("rt", encoding="utf8") as f:
readme = f.read()

setup(
name = "distutils-pytest",
version = version,
description = doclines[0],
long_description = "\n".join(doclines[2:]),
description = "Call pytest from a setup.py script",
long_description = readme,
url = "https://github.com/RKrahl/distutils-pytest",
author = "Rolf Krahl",
author_email = "rolf@rotkraut.de",
url = "https://github.com/RKrahl/distutils-pytest",
license = "Apache-2.0",
requires = ["pytest"],
py_modules = ["distutils_pytest"],
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -129,7 +132,17 @@ def run(self):
"Programming Language :: Python",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Build Tools",
],
cmdclass = {'build_py': build_py, 'sdist': sdist, 'meta': meta},
py_modules = ["distutils_pytest"],
install_requires = ["pytest"],
python_requires = ">=3.4",
cmdclass = dict(distutils_pytest.cmdclass,
build_py=build_py, sdist=sdist, meta=meta),
)

0 comments on commit f06d824

Please sign in to comment.