Repository: cython/cython

Issue:
cython-tool might produce an error for cython.pyx, the same way cythonize does
When building a file called `cython.pyx` via 

`cythonize cython.pyx` 

I get an error message saying: "ValueError: cython is a special module, cannot be used as a module name" which is a Good Thing.

However, using `cython cython.pyx`  doesn't produce any errors but a cython.c file - one which at least at Linux cannot be compiled.

Given that `cython` - tool is advertized in documentation (http://cython.readthedocs.io/en/latest/src/reference/compilation.html#compiling-from-the-command-line) and that it is not unusual for somebody new to Cython to call her/his pyx-file "cython.pyx", please consider to produce the same error message also with `cython`-tool.
cython-tool might produce an error for cython.pyx, the same way cythonize does
When building a file called `cython.pyx` via 

`cythonize cython.pyx` 

I get an error message saying: "ValueError: cython is a special module, cannot be used as a module name" which is a Good Thing.

However, using `cython cython.pyx`  doesn't produce any errors but a cython.c file - one which at least at Linux cannot be compiled.

Given that `cython` - tool is advertized in documentation (http://cython.readthedocs.io/en/latest/src/reference/compilation.html#compiling-from-the-command-line) and that it is not unusual for somebody new to Cython to call her/his pyx-file "cython.pyx", please consider to produce the same error message also with `cython`-tool.


Discussion:
PR welcome

PR welcome


Resolving patch:
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
--- a/Cython/Build/Dependencies.py
+++ b/Cython/Build/Dependencies.py
@@ -809,8 +809,7 @@ class Extension_setuptools(Extension): pass
             elif name:
                 module_name = name
 
-            if module_name == 'cython':
-                raise ValueError('cython is a special module, cannot be used as a module name')
+            Utils.raise_error_if_module_name_forbidden(module_name)
 
             if module_name not in seen:
                 try:
diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py
--- a/Cython/Compiler/Main.py
+++ b/Cython/Compiler/Main.py
@@ -469,6 +469,8 @@ def run_pipeline(source, options, full_module_name=None, context=None):
     abs_path = os.path.abspath(source)
     full_module_name = full_module_name or context.extract_module_name(source, options)
 
+    Utils.raise_error_if_module_name_forbidden(full_module_name)
+
     if options.relative_path_in_code_position_comments:
         rel_path = full_module_name.replace('.', os.sep) + source_ext
         if not abs_path.endswith(rel_path):
diff --git a/Cython/Utils.py b/Cython/Utils.py
--- a/Cython/Utils.py
+++ b/Cython/Utils.py
@@ -487,3 +487,9 @@ def wrapper(cls):
         orig_vars.pop('__weakref__', None)
         return metaclass(cls.__name__, cls.__bases__, orig_vars)
     return wrapper
+
+
+def raise_error_if_module_name_forbidden(full_module_name):
+    #it is bad idea to call the pyx-file cython.pyx, so fail early
+    if full_module_name == 'cython'  or full_module_name.endswith('.cython'):
+        raise ValueError('cython is a special module, cannot be used as a module name')


Test patch:
diff --git a/tests/build/cythonize_cython.srctree b/tests/build/cythonize_cython.srctree
new file mode 100644
--- /dev/null
+++ b/tests/build/cythonize_cython.srctree
@@ -0,0 +1,50 @@
+PYTHON -c "import cythonize_tests"
+PYTHON -c "import cython_tests"
+
+######## cythonize_tests.py ########
+
+from Cython.Build.Cythonize import main as cythonize
+
+for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]:
+    try:
+        cythonize([test_case])
+    except ValueError:
+        pass
+    else:
+        assert False, "ValueError not raised - forbidding cythonize "+test_case+" doesn't work"
+
+try:
+    cythonize(["notcython.pys"])
+except ValueError:
+    assert False, "ValueError raised - forbidding cythonize notcython.pyx should work"
+else:
+    pass
+
+######## cython_tests.py ########
+
+
+from Cython.Compiler.Main import main as cython
+import sys
+
+for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]:
+    sys.argv=["cython", test_case]  #cython.py will extract parameters from sys.argv
+    try:
+        cython(command_line=1)
+    except ValueError:
+        pass
+    else:
+        assert False, "ValueError not raised - forbidding cython "+test_case+" doesn't work"
+
+sys.argv=["cython", "notcython.pyx"]  #cython.py will extract parameters from sys.argv
+try:
+    cython(["notcython.pys"])
+except ValueError:
+    assert False, "ValueError raised - forbidding cythonize notcython.pyx should work"
+else:
+    pass
+
+######## cython.pyx ########
+######## src/__init__.py ########
+######## src/cython.pyx ########
+######## notcython.pyx ########
+######## src2/cython.pyx ########