Repository: dave-shawley/setupext-janitor

Issue:
clean --egg misses .eggs (plural)
Eggs downloaded via `setup_requires=...` are put in `.eggs` not `.egg` and `python setup.py clean --eggs` misses them.

(sidebar: setup_requires isn't necessary post PEP-518 and pip >v10)

Comments:

Patch:
diff --git a/README.rst b/README.rst
index 6a767de..3b7d103 100644
--- a/README.rst
+++ b/README.rst
@@ -38,7 +38,7 @@ imported into *setup.py* so that it can be passed as a keyword parameter
 
    import setuptools
    try:
-      from setupext import janitor
+      from setupext_janitor import janitor
       CleanCommand = janitor.CleanCommand
    except ImportError:
       CleanCommand = None
@@ -49,8 +49,13 @@ imported into *setup.py* so that it can be passed as a keyword parameter
 
    setup(
       # normal parameters
-      setup_requires=['setupext.janitor'],
+      setup_requires=['setupext_janitor'],
       cmdclass=cmd_classes,
+      entry_points={
+         # normal parameters, ie. console_scripts[]
+         'distutils.commands': [
+            ' clean = setupext_janitor.janitor:CleanCommand']
+         }
    )
 
 You can use a different approach if you are simply a developer that wants
@@ -67,7 +72,7 @@ few new command line parameters.
 ``setup.py clean --dist``
    Removes directories that the various *dist* commands produce.
 
-``setup.py clean --egg``
+``setup.py clean --eggs``
    Removes *.egg* and *.egg-info* directories.
 
 ``setup.py clean --environment``
diff --git a/docs/conf.py b/docs/conf.py
index 718339e..f1efef7 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -3,7 +3,7 @@
 
 import sphinx_rtd_theme
 
-from setupext import janitor
+from setupext_janitor import janitor
 
 
 project = 'Setupext: janitor'
diff --git a/setup.py b/setup.py
index d564df8..a267c85 100755
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ import codecs
 import setuptools
 import sys
 
-from setupext import janitor
+from setupext_janitor import janitor
 
 
 with codecs.open('README.rst', 'rb', encoding='utf-8') as file_obj:
@@ -26,7 +26,6 @@ setuptools.setup(
     description='Making setup.py clean more useful.',
     long_description=long_description,
     packages=setuptools.find_packages(exclude=['tests', 'tests.*']),
-    namespace_packages=['setupext'],
     zip_safe=True,
     platforms='any',
     install_requires=install_requirements,
@@ -41,7 +40,7 @@ setuptools.setup(
     ],
     entry_points={
         'distutils.commands': [
-            'clean = setupext.janitor:CleanCommand',
+            'clean = setupext_janitor.janitor:CleanCommand',
         ],
     },
     cmdclass={
diff --git a/setupext/__init__.py b/setupext/__init__.py
deleted file mode 100644
index de40ea7..0000000
--- a/setupext/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-__import__('pkg_resources').declare_namespace(__name__)
diff --git a/setupext_janitor/__init__.py b/setupext_janitor/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/setupext_janitor/__init__.py
@@ -0,0 +1,1 @@
+
diff --git a/setupext/janitor.py b/setupext_janitor/janitor.py
similarity index 83%
rename from setupext/janitor.py
rename to setupext_janitor/janitor.py
index 1a014e0..13b08c1 100644
--- a/setupext/janitor.py
+++ b/setupext_janitor/janitor.py
@@ -1,11 +1,11 @@
 from distutils import dir_util, errors
 from distutils.command.clean import clean as _CleanCommand
 import os.path
+import traceback
 
-
-version_info = (1, 0, 0)
+version_info = (1, 0, 1)
 __version__ = '.'.join(str(v) for v in version_info)
-
+debug = False
 
 class CleanCommand(_CleanCommand):
     """
@@ -71,17 +71,32 @@ class CleanCommand(_CleanCommand):
             for cmd_name, _ in self.distribution.get_command_list():
                 if 'dist' in cmd_name:
                     command = self.distribution.get_command_obj(cmd_name)
-                    command.ensure_finalized()
+                    #command.ensure_finalized()
+                    # Stop premature exit for RPM-on-NT err
+                    # https://github.com/dave-shawley/setupext-janitor/issues/12
+                    try:
+                        command.ensure_finalized()
+                    except Exception as err:
+                        skip = "don't know how to create RPM distributions on platform nt"
+                        if skip in err.args:
+                            print('-'*50,'\nException encountered and ignored:')
+                            print('{} {}'.format(err.__class__.__name__, err.args[0]))
+                            if debug: traceback.print_exc()
+                            print('-'*50)
+                        else:
+                            raise err
+                        
                     if getattr(command, 'dist_dir', None):
                         dir_names.add(command.dist_dir)
-
+                    
         if self.eggs:
             for name in os.listdir(self.egg_base):
                 if name.endswith('.egg-info'):
                     dir_names.add(os.path.join(self.egg_base, name))
             for name in os.listdir(os.curdir):
-                if name.endswith('.egg'):
-                    dir_names.add(name)
+                for e in ['.egg', '.eggs']:
+                    if name.endswith(e):
+                        dir_names.add(name)
 
         if self.environment and self.virtualenv_dir:
             dir_names.add(self.virtualenv_dir)


Test patch:
diff --git a/tests.py b/tests.py
index 39af958..53f0d20 100644
--- a/tests.py
+++ b/tests.py
@@ -12,7 +12,7 @@ if sys.version_info >= (2, 7):
 else:  # noinspection PyPackageRequirements,PyUnresolvedReferences
     import unittest2 as unittest
 
-from setupext import janitor
+from setupext_janitor import janitor
 
 
 def run_setup(*command_line):
@@ -171,6 +171,16 @@ class EggDirectoryCleanupTests(DirectoryCleanupMixin, unittest.TestCase):
             os.rmdir(dir_name)
             raise
 
+    def test_that_eggs_directories_are_removed(self):
+        dir_name = uuid.uuid4().hex + '.eggs'
+        os.mkdir(dir_name)
+        try:
+            run_setup('clean', '--eggs')
+            self.assert_path_does_not_exist(dir_name)
+        except:
+            os.rmdir(dir_name)
+            raise
+
     def test_that_directories_are_not_removed_in_dry_run_mode(self):
         egg_root = self.create_directory('egg-info-root')
         os.mkdir(os.path.join(egg_root, 'package.egg-info'))