Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify pyproject.toml #52

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"},
]
maintainers = [
{name = "PyAnsys developers", email = "[email protected]"},
]

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. <[email protected]>"]
maintainers = ["PyAnsys developers <[email protected]>"]
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 -%}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down