2021.4.1 #11

Merged
edraft merged 172 commits from 2021.04.01 into 2021.04 2021-03-21 20:04:24 +01:00
5 changed files with 42 additions and 13 deletions
Showing only changes of commit e8afff0e48 - Show all commits

View File

@ -31,10 +31,14 @@
"Main": "cpl_cli.main",
"EntryPoint": "cpl",
"IncludePackageData": "False",
"Included": [],
"Included": [
"src/cpl_cli/templates/new/console/src/tests"
],
"Excluded": [
"*/__pycache__",
"*/logs"
]
"*/logs",
"*/tests"
],
"PackageData": {}
}
}

View File

@ -19,6 +19,7 @@ class BuildSettings(ConfigurationModelABC):
self._include_package_data: Optional[bool] = None
self._included: Optional[list[str]] = None
self._excluded: Optional[list[str]] = None
self._package_data: Optional[dict[str, list[str]]] = None
@property
def source_path(self) -> str:
@ -48,15 +49,20 @@ class BuildSettings(ConfigurationModelABC):
def excluded(self) -> list[str]:
return self._excluded
@property
def package_data(self) -> dict[str, list[str]]:
return self._package_data
def from_dict(self, settings: dict):
try:
self._source_path = settings[BuildSettingsName.sourcePath.value]
self._output_path = settings[BuildSettingsName.outputPath.value]
self._source_path = settings[BuildSettingsName.source_path.value]
self._output_path = settings[BuildSettingsName.output_path.value]
self._include_package_data = bool(settings[BuildSettingsName.include_package_data.value])
self._main = settings[BuildSettingsName.main.value]
self._entry_point = settings[BuildSettingsName.entry_point.value]
self._included = settings[BuildSettingsName.included.value]
self._excluded = settings[BuildSettingsName.excluded.value]
self._package_data = settings[BuildSettingsName.package_data.value]
except Exception as e:
Console.set_foreground_color(ForegroundColor.red)
Console.write_line(

View File

@ -3,10 +3,11 @@ from enum import Enum
class BuildSettingsName(Enum):
sourcePath = 'SourcePath'
outputPath = 'OutputPath'
source_path = 'SourcePath'
output_path = 'OutputPath'
main = 'Main'
entry_point = 'EntryPoint'
include_package_data = 'IncludePackageData'
included = 'Included'
excluded = 'Excluded'
package_data = 'PackageData'

View File

@ -26,6 +26,7 @@ class Publisher(PublisherABC):
self._output_path = os.path.join(self._runtime.working_directory, self._build_settings.output_path)
self._included_files: list[str] = []
self._included_dirs: list[str] = []
self._distributed_files: list[str] = []
@property
@ -74,7 +75,7 @@ class Publisher(PublisherABC):
if excluded.startswith('*'):
excluded = excluded.replace('*', '')
if excluded in path:
if excluded in path and path not in self._build_settings.included:
return True
return False
@ -102,6 +103,12 @@ class Publisher(PublisherABC):
relative_path = os.path.relpath(r)
file_path = os.path.join(relative_path, os.path.relpath(file))
if len(d) > 0:
for directory in d:
empty_dir = os.path.join(os.path.dirname(file_path), directory)
if len(os.listdir(empty_dir)) == 0:
self._included_dirs.append(empty_dir)
if not self._is_path_excluded(relative_path):
self._included_files.append(os.path.relpath(file_path))
@ -187,6 +194,15 @@ class Publisher(PublisherABC):
Console.error(__name__, f'Cannot copy file: {file} to {output_path} -> {e}')
return
for empty_dir in self._included_dirs:
dist_dir = empty_dir
if 'src/' in dist_dir:
dist_dir = dist_dir.replace('src/', '', 1)
output_path = os.path.join(build_path, dist_dir)
if not os.path.isdir(output_path):
os.makedirs(output_path)
def _clean_dist_files(self):
paths: list[str] = []
for file in self._distributed_files:
@ -228,12 +244,12 @@ class Publisher(PublisherABC):
setup_string = stringTemplate(template_string).substitute(
Name=self._project_settings.name,
Version=self._project_settings.version.to_str(),
Packages=setuptools.find_packages(where=self._build_settings.source_path, exclude=self._build_settings.excluded),
Packages=setuptools.find_packages(where=self._output_path, exclude=self._build_settings.excluded),
URL=self._project_settings.url,
LicenseName=self._project_settings.license_name,
Author=self._project_settings.author,
AuthorMail=self._project_settings.author_email,
InstallPackageData=self._build_settings.include_package_data,
IncludePackageData=self._build_settings.include_package_data,
Description=self._project_settings.description,
PyRequires=self._project_settings.python_version,
Dependencies=self._project_settings.dependencies,
@ -241,7 +257,8 @@ class Publisher(PublisherABC):
'console_scripts': [
f'{self._build_settings.entry_point} = {main.__name__}:{main.main.__name__}'
]
}
},
PackageData=self._build_settings.package_data
)
setup_py.write(setup_string)
setup_py.close()

View File

@ -12,9 +12,10 @@ setuptools.setup(
license='$LicenseName',
author='$Author',
author_email='$AuthorMail',
include_package_data=$InstallPackageData,
include_package_data=$IncludePackageData,
description='$Description',
python_requires='$PyRequires',
install_requires=$Dependencies,
entry_points=$EntryPoints
entry_points=$EntryPoints,
package_data=$PackageData
)