pyproject¶
Python Project Structure Management.
This module provides the PyProjectStructure class that manages the file system structure,
build operations, and distribution management for Python packages in the boto3-dataclass ecosystem.
- class boto3_dataclass.structures.pyproject.PyProjectStructure(package_name: str)[source]¶
Manages the file system structure and operations for Python projects.
This class provides a complete abstraction for Python project management, including directory structure, build operations, and distribution handling. It’s designed specifically for boto3-dataclass packages but can be used for any Python project following standard conventions.
The class uses cached properties to efficiently manage file paths and provides methods for common development operations like building, uploading, and installing packages.
- Parameters:
package_name – The Python package name (with underscores)
Properties:
package_name_slug: Package name in slug format (with hyphens)dir_repo: Root directory for the project repositorydir_package: Directory containing the Python packagepath_*: Various file paths within the project structuredist_files: List of built distribution files
- Example:
>>> project = PyProjectStructure(package_name="my_awesome_package") >>> project.poetry_build() # Build distributions >>> project.twine_upload() # Upload to PyPI
- property package_name_slug: str¶
Get the package name in slug format (with hyphens instead of underscores).
Example:
boto3-dataclassboto3-dataclass-ec2
- property dir_repo: Path¶
Get the build directory path for the boto3_dataclass package repository. We use this directory to publish the package to PyPI.
Example:
build/repos/boto3_dataclass-projectbuild/repos/boto3_dataclass_ec2-project
- remove_dir()[source]¶
Remove the entire project repository directory.
This method safely removes the project’s build directory and all its contents. It’s typically used for cleaning up before a fresh build.
- property dir_package: Path¶
Get the directory path for the boto3_dataclass package.
Example:
build/repos/boto3_dataclass_ec2-project/boto3_dataclass_ec2
- property path_init_py: Path¶
Example:
build/repos/boto3_dataclass_ec2-project/boto3_dataclass_ec2/__init__.py
- property path_pyproject_toml: Path¶
Example:
build/repos/boto3_dataclass_ec2-project/pyproject.toml
- property dir_dist: Path¶
Get the distribution directory path for built packages.
Example:
build/repos/boto3_dataclass_ec2-project/dist
- property dist_files: list[str]¶
Get the list of distribution files in the dist directory.
Scans the project’s dist/ directory for built distribution files (both wheel and source distributions) that belong to this package.
- Returns:
List of absolute paths to distribution files as strings
Example:
[ "build/repos/boto3_dataclass_ec2-project/dist/boto3_dataclass_ec2-0.1.1.tar.gz", "build/repos/boto3_dataclass_ec2-project/dist/boto3_dataclass_ec2-0.1.1-py3-none-any.whl" ]
- poetry_build()[source]¶
Build the package using Poetry.
Creates both source distribution (.tar.gz) and wheel (.whl) files in the project’s dist/ directory using Poetry’s build command.
- Raises:
subprocess.CalledProcessError: If the Poetry build command fails
- twine_upload()[source]¶
Upload distribution files to PyPI using Twine.
Uploads all distribution files (both source and wheel) found in the dist/ directory to the configured PyPI repository using Twine.
- Raises:
twine.exceptions.TwineException: If upload fails requests.exceptions.RequestException: If network error occurs
- pip_install_editable()[source]¶
Install the package in editable mode for development.
Installs the package in development mode (editable install) using pip. This allows changes to the source code to be immediately reflected without reinstalling the package.
- Raises:
subprocess.CalledProcessError: If the pip install command fails