Skip to main content

synth-a-py

Build

Project configuration as code

Goals

  • Use synth-a-py to manage project configs
    • Add support for:
      • LICENSE
      • TOML (for pyproject.toml)
      • YAML (for GitHub Actions config)
        • GitHub Action workflow?
      • INI (for flake8/mypy config)
      • Makefile
      • .gitignore
    • Add ./synth.py
  • Templates:
    • Poetry
    • setup.py
    • Pipenv
  • In-repo examples:
    • Minimal
    • Monorepo

Example usage

#!/usr/bin/env python
from textwrap import dedent

from synth_a_py import Dir, License, Project, SimpleFile, TomlFile, YamlFile

authors = ["Joseph Egan"]

project_name = "sample-project"
project_description = "A sample project generated using synth-a-py"
project_version = "0.1.0"

project_import = project_name.lower().replace("-", "_")

spec = Project()
with spec:

    TomlFile(
        "pyproject.toml",
        {
            "build-system": {
                "requires": ["poetry>=0.12"],
                "build-backend": "poetry.masonry.api",
            },
            "tool": {
                "poetry": {
                    "name": project_name,
                    "version": project_version,
                    "description": project_description,
                    "authors": authors,
                    "license": "MIT",
                    "dependencies": {
                        "python": "^3.6",
                    },
                    "dev-dependencies": {
                        "pytest": "^6",
                        "pyprojroot": "^0.2.0",
                        "synth-a-py": "../synth-a-py",
                    },
                },
            },
        },
    )

    License.MIT("2020", ", ".join(authors))

    GitIgnore(
      ignore=[
        "*.egg",
        "*.egg-info/",
        "*.pyc",
        ".cache/",
        ".idea/",
        ".mypy_cache/",
        ".venv/",
        "dist/",
      ],
    )

    SimpleFile(
        "Makefile",
        dedent(
            """\
            .PHONEY: test
            test:
            \tpoetry install
            \tpoetry run pytest

            .PHONEY: synth
            synth:
            \tpoetry run ./synth.py
            """
        ),
    )

    with Dir(project_import):
        SimpleFile(
            "__init__.py",
            dedent(
                f"""\
                __version__ = "{project_version}"
                """
            ),
        )

    with Dir("tests"):
        SimpleFile(
            "test_version.py",
            dedent(
                f"""\
                import toml
                from pyprojroot import here

                from {project_import} import __version__


                def test_version() -> None:
                    pyproject = toml.load(here("pyproject.toml"))
                    pyproject_version = pyproject["tool"]["poetry"]["version"]

                    assert __version__ == pyproject_version
                """
            ),
        )

    with Dir(".github"):
        with Dir("workflows"):
            YamlFile(
                "ci.yml",
                {
                    "name": "ci",
                    "on": {
                        "pull_request": {
                            "branches": ["main"],
                        },
                        "push": {"branches": ["main"]},
                    },
                    "jobs": {
                        "test": {
                            "runs-on": "ubuntu-latest",
                            "steps": [
                                {
                                    "name": "checkout",
                                    "uses": "actions/checkout@v2",
                                },
                                {
                                    "name": "setup Python",
                                    "uses": "actions/setup-python@v2",
                                    "with": {
                                        "python-version": "3.9",
                                    },
                                },
                                {
                                    "name": "test",
                                    "run": dedent(
                                        """\
                                        pip install poetry
                                        make test
                                        """
                                    ),
                                },
                            ],
                        },
                    },
                },
            )

spec.synth()

Updating project config

To do this make edits to the .projenrc.js file in the root of the project and run npx projen to update existing or generate new config. Please also use npx prettier --trailing-comma all --write .projenrc.js to format this file.

Metadata

Release files for synth-a-py 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for synth-a-py 1.6.0
File Size Uploaded
synth-a-py-1.6.0.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for synth-a-py 1.6.0
File Interpreter ABI Platform
synth_a_py-1.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / synth-a-py-1.6.0.tar.gz

Download URL synth-a-py-1.6.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ae51de6aca2f00a6d6746b6087229482aaff18c2d82b01b7844e627b63a5e927
BLAKE2b-256 checksum
How to use checksums
94e62954510bd371c868f59998bdd4eaffbd80d2457a9b343453d38e15af4ad9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1040-azure

Release files / synth_a_py-1.6.0-py3-none-any.whl

Download URL synth_a_py-1.6.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e5db826a9af372e8fd2aa6bfde19567bbc5f8e28cea28437bc12780aff116f8
BLAKE2b-256 checksum
How to use checksums
b4a85a45469fd8d256014f82aa79e7afb4d53ef2d642154d7b9e80e5f8c19054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1040-azure

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page