margru / pybuilder-smart-copy-resources

PyBuilder plugin for copying additional resources
MIT License
0 stars 2 forks source link

Build fails on windows if resources files are in a subdirectory #11

Open pierralex opened 5 years ago

pierralex commented 5 years ago

Given the following build.py:

from pybuilder.core import use_plugin
from pybuilder.core import init

use_plugin("python.core")
use_plugin("pypi:pybuilder_smart_copy_resources")

default_task = 'publish'

@init
def initialize(project):
    project.set_property("smart_copy_resources_basedir", "./")
    project.set_property("smart_copy_resources", {
        "src/main/resources/*": "${dir_dist}/resources",
    })

Build fails with "Access is denied" because src/main/resources contains lang/test.txt. Build succeeds if i do

project.set_property("smart_copy_resources", {
        "src/main/resources/lang/*": "${dir_dist}/resources/lang",
    })

My real use case is to have many files and directories under src/main/resources and all of them must be copied in my distribution. So the latest code snipet is not a solution for me.

margru commented 5 years ago

Please, try to check you permissions on the given folder. I think this have nothing to do with the plugin but with access rights. Also, the full and exact error message would help here if that's not the permission problem.

farooqind commented 4 years ago

@margru I am also getting same error. It works for files under resources : project.set_property("smart_copy_resources", { "src/main/resources/*.json": "${dir_dist}/resources" })

but if we specify key as "src/main/resources/" it gives permission issue. project.set_property("smart_copy_resources", { "src/main/resources/": "${dir_dist}/resources" }) here is the error message and log:

Executing subtask from pybuilder_smart_copy_resources Copying additional resource files Copying resource c:\work\xxx\xxx\src/main/resources\xxxxxx to C:\work\xx\xxxx\target\dist\lxxxxxx-1.0\resources\xxxxxxxx Traceback (most recent call last): File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\cli.py", line 413, in main environments=options.environments, tasks=arguments) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\reactor.py", line 128, in build return self.build_execution_plan(tasks, execution_plan) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\reactor.py", line 166, in build_execution_plan reactor=self) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\execution.py", line 351, in execute_execution_plan summaries.append(self.execute_task(task, *keyword_arguments)) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\execution.py", line 298, in execute_task task.execute(self.logger, keyword_arguments) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\execution.py", line 169, in execute executable.execute(argument_dict) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder\execution.py", line 100, in execute self.callable(arguments) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder_smart_copy_resources__init.py", line 74, in package smart_copy_resource(file_to_copy, os.path.basename(file_to_copy) if copy_as is None else copy_as, destination, logger, verbose=project.get_property("verbose")) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\site-packages\pybuilder_smart_copy_resources\init__.py", line 83, in smart_copy_resource shutil.copy(absolute_filename, absolute_target_file_name) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\shutil.py", line 235, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "c:\users\xxxxxx\appdata\local\programs\python\python36\lib\shutil.py", line 114, in copyfile with open(src, 'rb') as fsrc: PermissionError: [Errno 13] Permission denied: 'c:\work\xxxxxx\xxxxxx\src/main/resources\xxxxxx'

BUILD FAILED - [Errno 13] Permission denied: 'c:\work\xxxxxx\xxxxxx\src/main/resources\xxxxxx

margru commented 4 years ago

@farooqind Have you tried to use the correct path separator (as you are obviously on Windows)? @pierralex @farooqind Have you tried a glob pattern, e.g. src/main/resources/*/ ?

farooqind commented 4 years ago

Thanks for quick response @margru I tried glob pattern you suggested and it copies all files from subfolders to single folder in dir_dist. Our requirement is to copy whole directory structure & its files i.e. contents of src/main/resources to dir_dist. Is there anyway to do it?

This is what I want to copy from src/main to dir_dist

resources

margru commented 4 years ago

@farooqind @pierralex OK, there is a bug in the code when copying the resources. Not sure when I have some time to fix that but I will keep it in mind and try to do it ASAP. Anyway, pull request is welcome.

farooqind commented 4 years ago

@margru Is it possible to fix this anytime soon? I am in middle of a sprint and we may need to stop using pybuilder itself if this doesn't work.