Open marekyggdrasil opened 5 years ago
What are you expecting setting project.name
vs name
in the build.py
?
@arcivanov I'm expecting project.name
to be used for creating the distribution directory, not the name
. I also tried to removing name
variable, but then it still ignores project.name
and starts using main directory name as name
.
Source of source_distribution
plugin suggests it should be project.name
used for creating directory name.
@arcivanov I think I know where the problem is
The directory path is set to DISTRIBUTION_PROPERTY
in this task being part of @init
of core
plugin.
My guess is, when my task is run (which sets the project.name
property the DISTRIBUTION_PROPERTY
is already set. Is there a way to ensure my task is executed before the task @init
of core
plugin?
I found the solution.
In order to make sure the distribution name follows the project name set in the initialisation task we need to use @before
decorator to indicate for this task to be run before the package
task. Then we need to update the project name and set the distribution property one more time.
from pybuilder.core import use_plugin, init, task, depends, before, after
from pybuilder.utils import apply_on_files, GlobExpression
use_plugin("python.core")
use_plugin("python.unittest")
use_plugin("python.install_dependencies")
use_plugin("python.flake8")
use_plugin("python.coverage")
use_plugin("python.distutils")
name = "unwanted-name"
version = "0.0.1"
default_task = ["check_project", "publish"]
DISTRIBUTION_PROPERTY = "dir_dist"
@init
@before("package")
def set_properties(project, logger):
logger.info("Setting project name")
project.name = 'wanted-name'
project.set_property(DISTRIBUTION_PROPERTY,
"$dir_target/dist/{0}-{1}".format(project.name, project.version))
pass
@task
def check_project(project, logger):
logger.info("Project name is set to " + project.name)
As you can see where previously we had unwanted-name
now there is wanted-name
including the distribution directory.
$ pyb -E envname
PyBuilder version 0.11.17
Build started at 2019-10-30 20:44:34
------------------------------------------------------------
[INFO] Activated environments: envname
[INFO] Building unwanted-name version 0.0.1
[INFO] Executing build in /Users/marek/Development/projectname/api/
[INFO] Going to execute tasks: check_project, publish
[INFO] Project name is set to unwanted-name
[INFO] Running unit tests
[INFO] Executing unit tests from Python modules in /Users/marek/Development/projectname/api/src/unittest/python
[INFO] Executed 3 unit tests
[INFO] All unit tests passed.
[INFO] Setting project name
[INFO] Building distribution in /Users/marek/Development/projectname/api/target/dist/wanted-name-0.0.1
[INFO] Copying scripts to /Users/marek/Development/projectname/api/target/dist/wanted-name-0.0.1/scripts
[INFO] Writing setup.py as /Users/marek/Development/projectname/api/target/dist/wanted-name-0.0.1/setup.py
[INFO] Collecting coverage information
[WARN] coverage_branch_threshold_warn is 0 and branch coverage will not be checked
[WARN] coverage_branch_partial_threshold_warn is 0 and partial branch coverage will not be checked
[INFO] Running unit tests
[INFO] Executing unit tests from Python modules in /Users/marek/Development/projectname/api/src/unittest/python
[INFO] Executed 3 unit tests
[INFO] All unit tests passed.
[WARN] Module '__init__' was not imported by the covered tests
[INFO] Overall coverage is 100%
[INFO] Overall coverage branch coverage is 100%
[INFO] Overall coverage partial branch coverage is 100%
[INFO] Building binary distribution in /Users/marek/Development/projectname/api/target/dist/wanted-name-0.0.1
------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------
Build Summary
Project: wanted-name
Version: 0.0.1
Base directory: /Users/marek/Development/projectname/api
Environments: envname
Tasks: check_project [0 ms] prepare [513 ms] compile_sources [0 ms] run_unit_tests [49 ms] package [12 ms] run_integration_tests [0 ms] verify [762 ms] publish [1401 ms]
Build finished at 2019-10-30 20:44:37
Build took 2 seconds (2793 ms)
The use of that is it allows you to change package name depending on environment or other parameters. That's exactly what I needed. Closing.
Thank you for finding a workaround. I'm reopening to investigate whether it's a documentation error or an implementation error.
Sure thing @arcivanov, just let me know if you have questions or if I can be of any use. I may have not described perfectly what I needed.
Hi everyone!
I just started learning to use
pybuilder
and while including it into one of my projects I noticed that regardless of settingproject.name
it keeps the distribution name with default name. I prepared the smallest example that demonstrates the issue.Here is my
build.py
I run the task
check_project
which logs the project name, it will allow us to see that project name is set beforesource_distribution_plugin
is creating the directory. The output is the following:as you can see the line
is displayed before
and as you can see it is using the default name, not the project name I set inside of the
@init
.I also tried to set the property
dir_source_dist
manually as in:https://github.com/pybuilder/pybuilder/blob/772cf66a6fea86c59bd76f22388b0ce964b2fc1a/src/main/python/pybuilder/plugins/source_distribution_plugin.py#L29-L31
with no success.
My
pybuilder
version isAm I doing something wrong or is it a bug?