Repository: fail2ban/fail2ban

Issue:
Cannot install testcases with 0.11.1
### Environment:

_- Fail2Ban version (including any possible distribution suffixes): 0.11.1

### The issue:

It appears to be impossible to install the testcases anymore.  There is a --without-testcases option, but it appears to be active by default and there is no --with-testcases option.

#### Steps to reproduce

python3 setup.py install

#### Expected behavior

fail2ban-testcases and tests are installed.

#### Observed behavior
fail2ban-testcases and tests are not install.

#### Any additional information

Also, the fail2ban-testcases.1 man page does not appear to be handled by the switch.  It is still currently installed, and setting --without-testcases I do not think would change that.


Discussion:
I think the name of the switch is --without-test, not --without-testcases. I'm using the switch for the FreeBSD port and it doesn't install the tests, at leats not fail2ban-testcases and its man page.

But yes, there is no switch --with-test. Unfortunately. It could make it easier to have an option to install the tests: FreeBSD offers an automatic translation from "selecting option x" to "--with-x" / "--without-x".
Indeed this issue can be introduced by PR #2287 (0.11 only), but as long as I can see per default option `--without-test` is disabled (None), so without this option setup shall install the tests.
At least I see that if I try install manually from source (no idea at the moment there is a different to a build or how it could affect built distribution).
Well this PR moves setting of `packages` and `package_data` from `setup` to a handler `install.finalize_options`, but build process does not involve install (or am I wrong?), so if the assumption correct, it will be simply not executed and both `packages` and `package_data` does not contain test related stuff.
At least this can explain why it's different by install from source and by build.

In this case it should get whole data in `setup` and some filter removing unneeded packages in `finalize_options`.
@sebres : I think you are right. The correct approach here is to leave the files in the setup section and filter out in the finalize_option. I'll do a pr as soon as I can.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -134,28 +134,13 @@ def finalize_options(self):
 			cmdclass = self.distribution.cmdclass
 			cmdclass['build_py'] = build_py_2to3
 			cmdclass['build_scripts'] = build_scripts_2to3
-		if not self.without_tests:
-			self.distribution.scripts += [
-				'bin/fail2ban-testcases',
-			]
+		if self.without_tests:
+			self.distribution.scripts.remove('bin/fail2ban-testcases')
 
-			self.distribution.packages += [
-				'fail2ban.tests',
-				'fail2ban.tests.action_d',
-			]
+			self.distribution.packages.remove('fail2ban.tests')
+			self.distribution.packages.remove('fail2ban.tests.action_d')
 
-			self.distribution.package_data = {
-				'fail2ban.tests':
-					[ join(w[0], f).replace("fail2ban/tests/", "", 1)
-						for w in os.walk('fail2ban/tests/files')
-						for f in w[2]] +
-					[ join(w[0], f).replace("fail2ban/tests/", "", 1)
-						for w in os.walk('fail2ban/tests/config')
-						for f in w[2]] +
-					[ join(w[0], f).replace("fail2ban/tests/", "", 1)
-						for w in os.walk('fail2ban/tests/action_d')
-						for f in w[2]]
-			}
+			del self.distribution.package_data['fail2ban.tests']
 		install.finalize_options(self)
 	def run(self):
 		install.run(self)
@@ -239,13 +224,28 @@ def run(self):
 		'bin/fail2ban-client',
 		'bin/fail2ban-server',
 		'bin/fail2ban-regex',
+		'bin/fail2ban-testcases',
 		# 'bin/fail2ban-python', -- link (binary), will be installed via install_scripts_f2b wrapper
 	],
 	packages = [
 		'fail2ban',
 		'fail2ban.client',
 		'fail2ban.server',
+		'fail2ban.tests',
+		'fail2ban.tests.action_d',
 	],
+	package_data = {
+		'fail2ban.tests':
+			[ join(w[0], f).replace("fail2ban/tests/", "", 1)
+				for w in os.walk('fail2ban/tests/files')
+				for f in w[2]] +
+			[ join(w[0], f).replace("fail2ban/tests/", "", 1)
+				for w in os.walk('fail2ban/tests/config')
+				for f in w[2]] +
+			[ join(w[0], f).replace("fail2ban/tests/", "", 1)
+				for w in os.walk('fail2ban/tests/action_d')
+				for f in w[2]]
+	},
 	data_files = [
 		('/etc/fail2ban',
 			glob("config/*.conf")


Test patch: