Skip to content

Commit

Permalink
PyCharm plugin target directory excluded when defined by user (#417)
Browse files Browse the repository at this point in the history
* pycharm-plugin-target-directory-excluded-when-defined-by-user
  • Loading branch information
szymonlyszkowski authored and arcivanov committed Nov 14, 2016
1 parent 293c54d commit bd6a4d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/main/python/pybuilder/plugins/python/pycharm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<component name="NewModuleRootManager">
<content url="file://$$MODULE_DIR$$">
<sourceFolder url="file://$$MODULE_DIR$$/${source_dir}" isTestSource="false" />${unit_tests}${integration_tests}
<excludeFolder url="file://$$MODULE_DIR$$/target" />
${output_directory}
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -40,8 +40,7 @@
<option name="projectConfiguration" value="Unittests" />
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
""")
</module>""")


def _ensure_directory_present(directory):
Expand All @@ -68,14 +67,14 @@ def pycharm_generate(project, logger):
if project.get_property("dir_source_integrationtest_python"):
integration_tests = """\n <sourceFolder url="file://$MODULE_DIR$/""" + project.get_property(
"dir_source_integrationtest_python") + """" isTestSource="true" />"""

output_directory = """<excludeFolder url="file://$MODULE_DIR$/%s" />""" % project.get_property(
"dir_target")
project_metadata = PROJECT_TEMPLATE.substitute({
"source_dir": project.get_property("dir_source_main_python"),
"unit_tests": unit_tests,
"integration_tests": integration_tests
"integration_tests": integration_tests,
"output_directory": output_directory
})

project_file_path = os.path.join(pycharm_directory, project_file_name)

with open(project_file_path, "w") as project_file:
project_file.write(project_metadata)
6 changes: 3 additions & 3 deletions src/unittest/python/plugins/python/pycharm_plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_should_write_pycharm_file(self, os, mock_open):
project.set_property('dir_source_main_python', 'src/main/python')
project.set_property('dir_source_unittest_python', 'src/unittest/python')
project.set_property('dir_source_integrationtest_python', 'src/integrationtest/python')
project.set_property('dir_target', 'build')
mock_open.return_value = MagicMock(spec=TYPE_FILE)
os.path.join.side_effect = lambda first, second: first + '/' + second

Expand All @@ -73,7 +74,7 @@ def test_should_write_pycharm_file(self, os, mock_open):
<sourceFolder url="file://$MODULE_DIR$/src/main/python" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/unittest/python" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/integrationtest/python" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -85,5 +86,4 @@ def test_should_write_pycharm_file(self, os, mock_open):
<option name="projectConfiguration" value="Unittests" />
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
""")
</module>""")

0 comments on commit bd6a4d5

Please sign in to comment.