Skip to content

Commit 7c639b7

Browse files
committed
getting the cmdclass from versioneer, adding the custom clean command and then passing it to setup()
1 parent 93493d8 commit 7c639b7

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

setup.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
import os
33
import versioneer
4+
import distutils.command.clean
5+
import shutil
46

57
have_cython = False
68

@@ -82,6 +84,22 @@ def __init__(self, *args, **kwargs):
8284
raise RuntimeError('default binary dir {} does not exist, you may need to build the C library in release mode'.format(default_bin_dir))
8385
library_dirs += [default_bin_dir]
8486

87+
class cmd_clean(distutils.command.clean.clean):
88+
def run(self):
89+
import glob
90+
with open('.clean', 'r') as f:
91+
ignores = f.read()
92+
for wildcard in filter(bool, ignores.split('\n')):
93+
for filename in glob.glob(wildcard):
94+
try:
95+
os.remove(filename)
96+
except OSError:
97+
shutil.rmtree(filename, ignore_errors=True)
98+
99+
# It's an old-style class in Python 2.7...
100+
distutils.command.clean.clean.run(self)
101+
102+
85103
ea = []
86104
if sys.platform in ('darwin', 'linux'):
87105
# Silence unused stuff warnings
@@ -120,9 +138,12 @@ def __init__(self, *args, **kwargs):
120138
define_macros=[('GPUARRAY_SHARED', None)]
121139
)]
122140

141+
cmds=versioneer.get_cmdclass()
142+
cmds["clean"] = cmd_clean
143+
123144
setup(name='pygpu',
124145
version=versioneer.get_version(),
125-
cmdclass=versioneer.get_cmdclass(),
146+
cmdclass=cmds,
126147
description='numpy-like wrapper on libgpuarray for GPU computations',
127148
packages=['pygpu', 'pygpu/tests'],
128149
include_package_data=True,

versioneer.py

-20
Original file line numberDiff line numberDiff line change
@@ -1646,26 +1646,6 @@ def make_release_tree(self, base_dir, files):
16461646
write_to_version_file(target_versionfile,
16471647
self._versioneer_generated_versions)
16481648
cmds["sdist"] = cmd_sdist
1649-
1650-
import distutils.command.clean
1651-
import shutil
1652-
1653-
class cmd_clean(distutils.command.clean.clean):
1654-
def run(self):
1655-
import glob
1656-
with open('.clean', 'r') as f:
1657-
ignores = f.read()
1658-
for wildcard in filter(bool, ignores.split('\n')):
1659-
for filename in glob.glob(wildcard):
1660-
try:
1661-
os.remove(filename)
1662-
except OSError:
1663-
shutil.rmtree(filename, ignore_errors=True)
1664-
1665-
# It's an old-style class in Python 2.7...
1666-
distutils.command.clean.clean.run(self)
1667-
cmds["clean"] = cmd_clean
1668-
16691649
return cmds
16701650

16711651

0 commit comments

Comments
 (0)