Repository: ckan/ckan

Issue:
No such file or directory: '/usr/lib/ckan/default/src/ckan/requirement-setuptools.txt' during installation from source
### CKAN Version if known (or site URL)
Latest (setting up development environment)

### Please describe the expected behaviour
When following the CKAN [installation from source](http://docs.ckan.org/en/latest/maintaining/installing/install-from-source.html) instructions, I should be able to complete the development setup on Ubuntu 16.04. This implies that all requisite steps should be fully documented.

### Please describe the actual behaviour
I get the following error when creating the virtualenv:

```
$ virtualenv --no-site-packages /usr/lib/ckan/default
Using base prefix '/home/brylie/anaconda3'
New python executable in /usr/lib/ckan/default/bin/python
/usr/lib/ckan/default/bin/python: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
ERROR: The executable /usr/lib/ckan/default/bin/python is not functioning
ERROR: It thinks sys.prefix is '/home/brylie' (should be '/usr/lib/ckan/default')
ERROR: virtualenv is not compatible with this system or executable
```

I am getting an error on the step **2b: Install the recommended version of ‘setuptools’:**

```
 pip install -r /usr/lib/ckan/default/src/ckan/requirement-setuptools.txt

Could not open requirements file: [Errno 2] No such file or directory: '/usr/lib/ckan/default/src/ckan/requirement-setuptools.txt'

```

### What steps can be taken to reproduce the issue? 
Follow the steps on [Installing CKAN from source](http://docs.ckan.org/en/latest/maintaining/installing/install-from-source.html)





Discussion:

Which CKAN version are you installing? The docs you're quoting are for the current development version, which [does include the `requirement-setuptools.txt` file](https://github.com/ckan/ckan/blob/master/requirement-setuptools.txt).

If you're installing a specific release version then make sure that you use that version's documentation. For example [the instructions for installing CKAN 2.6.2 from source](http://docs.ckan.org/en/ckan-2.6.2/maintaining/installing/install-from-source.html), which doesn't mention `requirement-setuptools.txt`.


OK, so aside from not reading your question completely I also gave the wrong answer... Let's try again:

The problem is that you're told in step `b` to use a file which only gets installed in the latter step `c`. This obviously makes no sense. Unfortunately, simply switching the steps probably won't help, because the goal of step `b` is to prepare the environment for a correct execution of step `c`.

So instead of relying on a not-yet-existing file, the docs should simply spell out the desired version of `setuptools` in step `b`:

    pip install setuptools==20.4

This needs to be fixed in docs.

Resolving patch:
diff --git a/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -168,13 +168,24 @@ def latest_package_name(distro='trusty'):
         version=latest_minor_version, distro=distro)
 
 
-def write_latest_release_file():
-    '''Write a file in the doc/ dir containing reStructuredText substitutions
-    for the latest release tag name and version number.
+def min_setuptools_version():
+    '''
+    Get the minimum setuptools version as defined in requirement-setuptools.txt.
+    '''
+    filename = os.path.join(os.path.dirname(__file__), '..',
+                            'requirement-setuptools.txt')
+    with open(filename) as f:
+        return f.read().split('==')[1].strip()
+
+
+def write_substitutions_file(**kwargs):
+    '''
+    Write a file in the doc/ dir containing reStructuredText substitutions.
 
+    Any keyword argument is stored as a substitution.
     '''
-    filename = '_latest_release.rst'
-    template = ''':orphan:
+    filename = '_substitutions.rst'
+    header = ''':orphan:
 
 .. Some common reStructuredText substitutions.
 
@@ -189,22 +200,21 @@ def write_latest_release_file():
 
      |latest_release_version|
 
-.. |latest_release_tag| replace:: {latest_tag}
-.. |latest_release_version| replace:: {latest_version}
-.. |latest_package_name_precise| replace:: {package_name_precise}
-.. |latest_package_name_trusty| replace:: {package_name_trusty}
-
 '''
-    open(filename, 'w').write(template.format(
-        filename=filename,
-        latest_tag=latest_release_tag(),
-        latest_version=latest_release_version(),
-        package_name_precise=latest_package_name('precise'),
-        package_name_trusty=latest_package_name('trusty'),
-        ))
-
-
-write_latest_release_file()
+    with open(filename, 'w') as f:
+        f.write(header.format(filename=filename))
+        for name, substitution in kwargs.items():
+            f.write('.. |{name}| replace:: {substitution}\n'.format(
+                    name=name, substitution=substitution))
+
+
+write_substitutions_file(
+    latest_release_tag=latest_release_tag(),
+    latest_release_version=latest_release_version(),
+    latest_package_name_precise=latest_package_name('precise'),
+    latest_package_name_trusty=latest_package_name('trusty'),
+    min_setuptools_version=min_setuptools_version(),
+)
 
 
 # The language for content autogenerated by Sphinx. Refer to documentation
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,9 @@
 # encoding: utf-8
 
-# Avoid problem releasing to pypi from vagrant
 import os
+import os.path
+
+# Avoid problem releasing to pypi from vagrant
 if os.environ.get('USER', '') == 'vagrant':
     del os.link
 
@@ -17,18 +19,26 @@
 from ckan import (__version__, __description__, __long_description__,
                   __license__)
 
-MIN_SETUPTOOLS_VERSION = 20.4
-assert setuptools_version >= str(MIN_SETUPTOOLS_VERSION) and \
-    int(setuptools_version.split('.')[0]) >= int(MIN_SETUPTOOLS_VERSION),\
-    ('setuptools version error'
-     '\nYou need a newer version of setuptools.\n'
-     'You have {current}, you need at least {minimum}'
-     '\nInstall the recommended version:\n'
-     '    pip install -r requirement-setuptools.txt\n'
-     'and then try again to install ckan into your python environment.'.format(
-         current=setuptools_version,
-         minimum=MIN_SETUPTOOLS_VERSION
-         ))
+
+#
+# Check setuptools version
+#
+
+def parse_version(s):
+    return map(int, s.split('.'))
+
+HERE = os.path.dirname(__file__)
+with open(os.path.join(HERE, 'requirement-setuptools.txt')) as f:
+        setuptools_requirement = f.read().strip()
+min_setuptools_version = parse_version(setuptools_requirement.split('==')[1])
+if parse_version(setuptools_version) < min_setuptools_version:
+    raise AssertionError(
+        'setuptools version error\n'
+        'You need a newer version of setuptools.\n'
+        'Install the recommended version:\n'
+        '    pip install -r requirement-setuptools.txt\n'
+        'and then try again to install ckan into your python environment.'
+    )
 
 
 entry_points = {


Test patch: