From 18558f04f753a4f30cf4e40386ed242785e247f6 Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Thu, 7 Apr 2022 10:03:07 +0200 Subject: [PATCH 1/2] Unify pyproject.toml --- .../pyproject.toml | 68 +++++++++++++++++++ .../pyproject_flit.toml | 34 ---------- .../pyproject_poetry.toml | 27 -------- 3 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject.toml delete mode 100644 src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_flit.toml delete mode 100644 src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_poetry.toml diff --git a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject.toml b/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject.toml new file mode 100644 index 000000000..a2652d25a --- /dev/null +++ b/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject.toml @@ -0,0 +1,68 @@ +[build-system] +{%- if cookiecutter.build_system == "flit" %} +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" +{% elif cookiecutter.build_system == "poetry" %} +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" +{% elif cookiecutter.build_system == "setuptools" %} +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" +{% endif -%} + +{%- if cookiecutter.build_system == "flit" %} +[project] +# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections +name = "{{ cookiecutter.__pkg_name }}" +version = "{{ cookiecutter.__version }}" +description = "{{ cookiecutter.__short_description }}" +readme = "README.rst" +requires-python = ">={{ cookiecutter.__requires_python }}" +license = {file = "LICENSE"} +authors = [ + {name = "ANSYS, Inc.", email = "pyansys.support@ansys.com"}, +] +maintainers = [ + {name = "PyAnsys developers", email = "pyansys.maintainers@ansys.com"}, +] + +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +dependencies = [ + "importlib-metadata >=4.0", +] + +[tool.flit.module] +name = "{{ cookiecutter.__pkg_namespace }}" + +[project.urls] +Source = "{{ cookiecutter.__repository_url }}" +{% elif cookiecutter.build_system == "poetry" %} +[tool.poetry] +# Check https://python-poetry.org/docs/pyproject/ for all available sections +name = "{{ cookiecutter.__pkg_name }}" +version = "{{ cookiecutter.__version }}" +description = "{{ cookiecutter.__short_description }}" +license = "MIT" +authors = ["ANSYS, Inc. "] +maintainers = ["PyAnsys developers "] +readme = "README.rst" +repository = "{{ cookiecutter.__repository_url }}" +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +packages = [ + { include = "ansys", from = "src" }, +] + +[tool.poetry.dependencies] +python = ">={{ cookiecutter.__requires_python }},<4.0" +importlib-metadata = {version = "^4.0", python = "<3.8"} +{% endif -%} diff --git a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_flit.toml b/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_flit.toml deleted file mode 100644 index 1dddf7748..000000000 --- a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_flit.toml +++ /dev/null @@ -1,34 +0,0 @@ -[build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" - -[project] -# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections -name = "{{ cookiecutter.__pkg_name }}" -version = "{{ cookiecutter.__version }}" -description = "{{ cookiecutter.__short_description }}" -readme = "README.rst" -requires-python = ">={{ cookiecutter.__requires_python }}" -license = {file = "LICENSE"} -authors = [ - {name = "ANSYS, Inc.", email = "pyansys.support@ansys.com"}, -] -maintainers = [ - {name = "PyAnsys developers", email = "pyansys.maintainers@ansys.com"}, -] - -classifiers = [ - "Development Status :: 4 - Beta", - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", -] -dependencies = [ - "importlib-metadata >=4.0", -] - -[tool.flit.module] -name = "{{ cookiecutter.__pkg_namespace }}" - -[project.urls] -Source = "{{ cookiecutter.__repository_url }}" diff --git a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_poetry.toml b/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_poetry.toml deleted file mode 100644 index c889b3593..000000000 --- a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/pyproject_poetry.toml +++ /dev/null @@ -1,27 +0,0 @@ -[build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry] -# Check https://python-poetry.org/docs/pyproject/ for all available sections -name = "{{ cookiecutter.__pkg_name }}" -version = "{{ cookiecutter.__version }}" -description = "{{ cookiecutter.__short_description }}" -license = "MIT" -authors = ["ANSYS, Inc. "] -maintainers = ["PyAnsys developers "] -readme = "README.rst" -repository = "{{ cookiecutter.__repository_url }}" -classifiers = [ - "Development Status :: 4 - Beta", - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", -] -packages = [ - { include = "ansys", from = "src" }, -] - -[tool.poetry.dependencies] -python = ">={{ cookiecutter.__requires_python }},<4.0" -importlib-metadata = {version = "^4.0", python = "<3.8"} From bf851b453401ca686c7fac0500e2b69da03a590e Mon Sep 17 00:00:00 2001 From: Jorge Martinez Date: Thu, 7 Apr 2022 10:58:59 +0200 Subject: [PATCH 2/2] Simplify pyansys-advanced post-hook --- .../hooks/post_gen_project.py | 44 ++----------------- .../{setup_setuptools.py => setup.py} | 0 .../test_template_python_pyansys_advanced.py | 6 ++- 3 files changed, 9 insertions(+), 41 deletions(-) rename src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/{setup_setuptools.py => setup.py} (100%) diff --git a/src/ansys/templates/python/pyansys_advanced/hooks/post_gen_project.py b/src/ansys/templates/python/pyansys_advanced/hooks/post_gen_project.py index 10a8d9da8..1622238f8 100644 --- a/src/ansys/templates/python/pyansys_advanced/hooks/post_gen_project.py +++ b/src/ansys/templates/python/pyansys_advanced/hooks/post_gen_project.py @@ -9,39 +9,6 @@ """A list of all allowed build systems by the template.""" -def remove_tool_files(tool_name, basedir): - """ - Remove files matching given glob expression within desired base directory. - - Parameters - ---------- - tool_name: str - Name of the tool used as build system. - basedir: Path - Base directory path. - - """ - for filepath in basedir.glob(f"**/*_{tool_name}*"): - filepath.unlink() - - -def rename_tool_files(tool_name, basedir): - """ - Rename tool filenames within desired base directory. - - Parameters - ---------- - tool_name: str - Name of the tool used as build system. - basedir: Path - Base directory path. - - """ - for original_filepath in basedir.glob(f"**/*_{tool_name}*"): - new_filename = original_filepath.name.replace(f"_{tool_name}", "") - original_filepath.rename(Path(original_filepath.parent, new_filename)) - - def main(): """Entry point of the script.""" # Get baked project location path @@ -50,13 +17,10 @@ def main(): # Get the desired build system build_system = "{{ cookiecutter.build_system }}" - # Remove non-desired build system files - for tool in ALLOWED_BUILD_SYSTEMS: - if tool != build_system: - remove_tool_files(tool, project_path) - - # Rename any files including tool name suffix - rename_tool_files(build_system, project_path) + # Remove setup.py file if not required + if build_system in ["flit", "poetry"]: + setup_file = project_path / "setup.py" + setup_file.unlink() # Move all requirements files into a requirements/ directory os.mkdir(project_path / "requirements") diff --git a/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/setup_setuptools.py b/src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/setup.py similarity index 100% rename from src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/setup_setuptools.py rename to src/ansys/templates/python/pyansys_advanced/{{cookiecutter.__project_name_slug}}/setup.py diff --git a/tests/tests_templates_python/test_template_python_pyansys_advanced.py b/tests/tests_templates_python/test_template_python_pyansys_advanced.py index 6bb298782..312a61e5b 100644 --- a/tests/tests_templates_python/test_template_python_pyansys_advanced.py +++ b/tests/tests_templates_python/test_template_python_pyansys_advanced.py @@ -83,10 +83,14 @@ def test_template_python_pyansys_advanced(tmp_path, python_common_files, build_s basedir_files = [ "LICENSE", "README.rst", - "pyproject.toml" if build_system != "setuptools" else "setup.py", + "pyproject.toml", "tox.ini", ] + # Add setup.py file if using setuptools + if build_system == "setuptools": + basedir_files.append("setup.py") + all_expected_baked_files = ( new_python_common_files + basedir_files