#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Package Setup.py fails with readonly files


    I have a python package that I install using pip install.

    The setup.py file is then called to install the package, it generates a "build" folder each time defore deploying in the python environment. The first time I try to install the package, is works great. The problem is when I try to install it a second time (let's say it was uninstalled or a new version is out) when the "build" folder already exist. I get an error "error: could not delete 'build\scripts-2.7\package-cmd.py': Access is denied" It happens when it copies the "package-cmd.py" file in the "build\scripts" folder, because the file is in read-only mode. All the files in my package are in read-only, but the setup.py is removing that attribute beofre installing. The only remaining read-only file is one that was not in my package : "package-cmd.py".

    Is there a way to generate that file without the read-only? I am not very familiar with the setup process (note that I did not write the following code, but have to maintain it...)

    Is there a way to modify the setup.py file so that it generates a package-cmd.py file that is not readonly?

    Code:
    from setuptools import setup
    from distutils.command.install import INSTALL_SCHEMES
    from distutils.command.install_data import install_data as _install_data
    import os
    import sys
    
    # remove read-only from data files
    class install_data(_install_data):  
    def copy_file(self, infile, outfile,
                  preserve_mode=0, preserve_times=1, link=None, level=1):
        return _install_data.copy_file(self,infile, outfile, preserve_mode=0, preserve_times=1, link=None, level=1)
    
    def fullsplit(path, result=None):
    """
    Split a pathname into components (the opposite of os.path.join) in a
    platform-neutral way.
    """
    if result is None:
        result = []
    head, tail = os.path.split(path)
    if head == '':
        return [tail] + result
    if head == path:
        return result
    return fullsplit(head, [tail] + result)
    
    # Tell distutils to put the data_files in platform-specific installation
    # locations. See here for an explanation:
    #       
    for scheme in INSTALL_SCHEMES.values():
    scheme['data'] = scheme['purelib']
    
    # Compile the list of packages available, because distutils doesn't have
    # an easy way to do this.
    packages, data_files = [], []
    root_dir = os.path.dirname(__file__)
    if root_dir != '':
    os.chdir(root_dir)
    tool_dir = 'package_name'
    
    # install
    for dirpath, dirnames, filenames in os.walk(tool_dir):
    # Ignore dirnames that start with '.'
    for i, dirname in enumerate(dirnames):
        if dirname.startswith('.'): del dirnames[i]
    if '__init__.py' in filenames:
        packages.append('.'.join(fullsplit(dirpath)))
        for f in filenames:
            if not f.endswith('.py'):
                data_files.append([dirpath, [os.path.join(dirpath,f)]])
    elif filenames:
        data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
    
    #setup
    
    
    setup(
    name = "Package_name",
    version = '1.2.4',
    cmdclass = {
        'install_data' : install_data,
    },
    packages = packages,
    data_files = data_files,
    scripts = ['scripts/package-cmd.py'],
    entry_points = {
      'console_scripts' : ['package = package:execute_from_command_line']
    },
    )
    EDIT: On the first installation, when the "build" folder does not exist beforehand, I also get those errors:

    creating 'dist\package-1.2.4-py2.7.egg' and adding 'build\bdist.win32\egg' to it
    removing 'build\bdist.win32\egg' (and everything under it)
    error removing build\bdist.win32\egg: build\bdist.win32\egg\EGG-INFO\scripts\package-cmd.py: Access is denied
    error removing build\bdist.win32\egg: build\bdist.win32\egg\EGG-INFO\scripts: The directory is not empty
    error removing build\bdist.win32\egg: build\bdist.win32\egg\EGG-INFO: The directory is not empty
    error removing build\bdist.win32\egg: build\bdist.win32\egg: The directory is not empty
    Since the file build\bdist.win32\egg\EGG-INFO\scripts\package-cmd.py is also read-only.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    484
    Rep Power
    33
    error removing build\bdist.win32\egg: build\bdist.win32\egg\EGG-INFO\scripts\package-cmd.py: Access is denied
    You don't have proper permissions for that file. Try running it as root instead of a normal user.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by dwblas
    You don't have proper permissions for that file. Try running it as root instead of a normal user.
    I don't have the credentials for root. My user does have admin rights though. The people that will install this package either have the same admin rights, or less.

IMN logo majestic logo threadwatch logo seochat tools logo