### Render Method Example Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Example showing how to trigger the rendering process. ```python writer.render() # Now writer._content contains the rendered version file text ``` -------------------------------- ### Initialize Writer Example Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Example showing how to instantiate the Writer class with a MetaData object. ```python from pyinstaller_versionfile.metadata import MetaData from pyinstaller_versionfile.writer import Writer metadata = MetaData( version="1.2.3.4", company_name="Acme Corp", product_name="My App" ) writer = Writer(metadata) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/CONTRIBUTING.md Run this command in the root directory to install all project requirements using Poetry. ```bash poetry install ``` -------------------------------- ### Instantiate MetaData object Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Example showing how to initialize a MetaData object with specific version and product details. ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData( version="1.2.3.4", company_name="Acme Corp", file_description="My App", product_name="My App" ) ``` -------------------------------- ### Usage Example for create_versionfile Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile.md Demonstrates how to call create_versionfile with explicit metadata parameters to generate a version file. ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.2.3.4", company_name="Acme Corp", file_description="My Application", internal_name="MyApp", legal_copyright="© 2024 Acme Corp", original_filename="myapp.exe", product_name="My Application", translations=[1033, 1200] ) ``` -------------------------------- ### Create version file from installed distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Extracts metadata from an installed Python package using importlib.metadata. ```bash pyivf-make_version \ --source-format dist \ --metadata-source mypackage \ --outfile versionfile.txt ``` ```bash pyivf-make_version \ --source-format distribution \ --metadata-source numpy \ --outfile versionfile.txt \ --version 1.0.0.0 ``` -------------------------------- ### Loading Metadata from File Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Usage example for initializing a MetaData instance from a YAML file with optional keyword overrides. ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData.from_file( "metadata.yml", version="2.0.0.0" # Override version from file ) ``` -------------------------------- ### YAML File Format Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-input-file.md Example structure for the input YAML metadata file. ```yaml Version: 1.2.3.4 CompanyName: Acme Corporation FileDescription: My Application InternalName: MyApp LegalCopyright: © 2024 Acme Corp. All rights reserved. OriginalFilename: myapp.exe ProductName: My Application Translation: - langID: 1033 charsetID: 1252 - langID: 0 charsetID: 1200 ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md A complete YAML configuration for version file metadata. The encoding must be UTF-8. All fields are optional. ```YAML Version: 1.2.3.4 CompanyName: My Imaginary Company FileDescription: Simple App InternalName: Simple App LegalCopyright: "© My Imaginary Company. All rights reserved." OriginalFilename: SimpleApp.exe ProductName: Simple App Translation: - langID: 0 charsetID: 1200 - langID: 1033 charsetID: 1252 ``` -------------------------------- ### Load metadata from distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Initializes a MetaData instance using metadata from an installed package. Optional keyword arguments can be provided to override specific metadata fields. ```python @classmethod def from_distribution(cls, distname: str, **kwargs: Any) -> MetaData ``` ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData.from_distribution("numpy") ``` -------------------------------- ### YAML Configuration File Format Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Example of a complete YAML configuration file where all fields are optional and default to empty or standard values if omitted. ```yaml # All fields are optional; unspecified fields use default values # Version in format X.Y.Z.W or path to a file containing the version Version: 1.2.3.4 # Company name CompanyName: Acme Corporation # File description for Windows File Properties FileDescription: My Application # Internal name of the file InternalName: MyApp # Copyright notice LegalCopyright: © 2024 Acme Corporation. All rights reserved. # Original filename (typically with .exe extension) OriginalFilename: myapp.exe # Product name ProductName: My Application # Language/Charset ID pairs Translation: - langID: 1033 charsetID: 1200 - langID: 1031 charsetID: 1252 ``` -------------------------------- ### Create Version File from Distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Command to create a version file by extracting metadata from an installed Python package. Specify the package name with --metadata-source. ```cmd pyivf-make_version --source-format dist --metadata-source PackageName --outfile file_version_info.txt ``` -------------------------------- ### Use MetadataKwargs for type checking Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/types.md Example of initializing MetaData using a dictionary typed with MetadataKwargs. ```python from pyinstaller_versionfile.metadata import MetaData, MetadataKwargs # Type checkers understand this is compatible with MetadataKwargs kwargs: MetadataKwargs = { "version": "1.0.0.0", "company_name": "Acme Corp", } metadata = MetaData(**kwargs) ``` -------------------------------- ### Python API: create_versionfile_from_distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Creates a version file by extracting metadata from an installed Python package. ```APIDOC ## Python API: create_versionfile_from_distribution ### Description Generates a version file by extracting metadata from an installed Python package. ### Function Signature ```python create_versionfile_from_distribution( output_file: str, distname: str ) ``` ### Parameters - `output_file` (str): The path to the file where the version information will be saved. - `distname` (str): The name of the installed Python package to extract metadata from. ### Example ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="myPackage" ) ``` ``` -------------------------------- ### YAML Configuration with External Version File Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Example YAML configuration where the version is specified by referencing an external file. This file should only contain the version string. ```YAML Version: VERSION.txt CompanyName: My Imaginary Company FileDescription: Simple App InternalName: Simple App LegalCopyright: "© My Imaginary Company. All rights reserved." OriginalFilename: SimpleApp.exe ProductName: Simple App ``` -------------------------------- ### Basic Usage of create_versionfile_from_distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-distribution.md Generates a version file using metadata automatically extracted from the specified installed package. ```python import pyinstaller_versionfile # Extract all metadata from installed package pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage" ) ``` -------------------------------- ### Catch UsageError Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/errors.md Example of catching a UsageError when providing an invalid output path. ```python import pyinstaller_versionfile from pyinstaller_versionfile.exceptions import UsageError try: pyinstaller_versionfile.create_versionfile( output_file="/some/directory/", # Directory, not file version="1.0.0.0" ) except UsageError as e: print(f"Usage error: {e}") ``` -------------------------------- ### MetaData.from_distribution() Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Loads metadata from an installed Python package distribution, merging it with optional keyword argument overrides. ```APIDOC ## Class Method: `from_distribution(distname: str, **kwargs: Any)` ### Description Load metadata from an installed Python package distribution. Automatically extracts version, description, names, copyright, and company information. ### Parameters - **distname** (str) - Required - Name of an installed Python package. - **kwargs** (Any) - Optional - Overrides for any metadata field. ### Returns - **MetaData** (instance) - Initialized MetaData object. ### Throws - **InputError** - Raised if the distribution `distname` is not found. ### Example ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData.from_distribution("numpy") ``` ``` -------------------------------- ### Create version file from distribution metadata Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/INDEX.md Extract metadata from an installed Python package to generate a version file. ```python import pyinstaller_versionfile # Extract from installed package pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage" ) # With version override pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage", version="3.0.0.0" ) ``` -------------------------------- ### Catch InternalUsageError Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/errors.md Example of catching an InternalUsageError, which indicates a library bug. ```python import pyinstaller_versionfile from pyinstaller_versionfile.exceptions import InternalUsageError try: pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.0.0.0" ) except InternalUsageError as e: # This should not happen in normal usage print(f"An internal error occurred: {e}") print("Please file a bug report.") ``` -------------------------------- ### Generate Version Files via Python Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/README.md Create version files using explicit parameters, YAML input files, or metadata from installed packages. ```python # From explicit parameters create_versionfile( output_file="versionfile.txt", version="1.0.0.0", company_name="My Company", product_name="My Product" ) # From YAML file create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml" ) # From installed package create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage" ) ``` -------------------------------- ### Catch InputError Exception Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/errors.md Example of handling InputError when a specified input file is missing. ```python import pyinstaller_versionfile from pyinstaller_versionfile.exceptions import InputError try: pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="missing.yml" ) except InputError as e: print(f"Input error: {e}") ``` -------------------------------- ### Generate version file from distribution metadata Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Extracts metadata from an installed package and applies a company name override. ```bash pyivf-make_version \ --source-format dist \ --metadata-source requests \ --outfile versionfile.txt \ --company-name "My Organization" ``` -------------------------------- ### Show pyivf-make_version help Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Run this command to see the full interface description for the pyinstaller-versionfile CLI. ```cmd pyivf-make_version --help ``` -------------------------------- ### Generate version file with minimal parameters Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Creates a basic version file using only the output path, version, and product name. ```bash pyivf-make_version \ --outfile versionfile.txt \ --version 1.0.0.0 \ --product-name "My App" ``` -------------------------------- ### Catch ValidationError Exception Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/errors.md Example of handling ValidationError when an invalid version string is provided. ```python import pyinstaller_versionfile from pyinstaller_versionfile.exceptions import ValidationError try: pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="invalid.version.string" ) except ValidationError as e: print(f"Validation error: {e}") ``` -------------------------------- ### Create version file from direct parameters Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Specifies all metadata directly via command-line flags without requiring a source file. ```bash pyivf-make_version \ --outfile versionfile.txt \ --version 1.2.3.4 \ --company-name "Acme Corp" \ --file-description "My Application" \ --internal-name "MyApp" \ --legal-copyright "© 2024 Acme Corp" \ --original-filename "myapp.exe" \ --product-name "My Application" ``` -------------------------------- ### Import Main Functions Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/README.md Import the primary entry points for creating version files from different sources. ```python from pyinstaller_versionfile import ( create_versionfile, create_versionfile_from_input_file, create_versionfile_from_distribution, ) ``` -------------------------------- ### Integrating with setuptools_scm Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-distribution.md Uses setuptools_scm to dynamically retrieve the current version for the generated version file. ```python import pyinstaller_versionfile from setuptools_scm import get_version version = get_version() pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage", version=version ) ``` -------------------------------- ### Generate version file with full specification Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Provides all available metadata fields directly via command-line arguments. ```bash pyivf-make_version \ --outfile build/version_file.txt \ --version 1.0.0.0 \ --company-name "ACME Corporation" \ --file-description "ACME Application Suite" \ --internal-name "ACME_APP" \ --legal-copyright "Copyright © 2024 ACME Corp. All rights reserved." \ --original-filename "acme.exe" \ --product-name "ACME Application" ``` -------------------------------- ### Execute full version file workflow Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Complete workflow including metadata creation, validation, rendering, and saving to disk. ```python from pyinstaller_versionfile.metadata import MetaData from pyinstaller_versionfile.writer import Writer # Step 1: Create and validate metadata metadata = MetaData( version="1.0.0.0", company_name="My Corp", file_description="My App", internal_name="MyApp", legal_copyright="© 2024 My Corp", original_filename="myapp.exe", product_name="My App" ) metadata.validate() metadata.sanitize() # Step 2: Create writer and render writer = Writer(metadata) writer.render() # Step 3: Save to file writer.save("versionfile.txt") ``` -------------------------------- ### MetaData.__init__() Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Initializes a new instance of the MetaData class with optional versioning and file information fields. ```APIDOC ## MetaData.__init__() ### Description Initializes a new MetaData object to store Windows version file information. ### Parameters - **version** (str) - Optional - Version string in format X.Y.Z.W. Defaults to "0.0.0.0". - **company_name** (str) - Optional - Company name. Defaults to "". - **file_description** (str) - Optional - File description text. Defaults to "". - **internal_name** (str) - Optional - Internal file name. Defaults to "". - **legal_copyright** (str) - Optional - Copyright notice. Defaults to "". - **original_filename** (str) - Optional - Original filename. Defaults to "". - **product_name** (str) - Optional - Product name. Defaults to "". - **translations** (list[int]) - Optional - Flat list of language/charset ID pairs. Defaults to [1033, 1200]. ### Example ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData( version="1.2.3.4", company_name="Acme Corp", file_description="My App", product_name="My App" ) ``` ``` -------------------------------- ### CLI Entry Points Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/modules.md Reference for CLI entry points configured via Poetry scripts. ```text # CLI entrypoints (via Poetry scripts) # pyivf-make_version -> pyinstaller_versionfile.__main__:make_version # create-version-file -> pyinstaller_versionfile.__main__:create_version_file ``` -------------------------------- ### Writer.__init__(metadata: MetaData) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Initializes a new instance of the Writer class with the provided metadata object. ```APIDOC ## Constructor: `__init__(metadata)` ### Description Initializes a Writer instance with the metadata required for rendering the version file. ### Parameters - **metadata** (`MetaData`) - Required - The metadata object containing version file information. ``` -------------------------------- ### Execute pyivf-make_version command Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Basic command signature for invoking the version file generator. ```bash pyivf-make_version [OPTIONS] ``` -------------------------------- ### Initialize MetaData constructor Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md The constructor signature for creating a new MetaData instance with optional parameters. ```python def __init__( self, version: Optional[str] = None, company_name: Optional[str] = None, file_description: Optional[str] = None, internal_name: Optional[str] = None, legal_copyright: Optional[str] = None, original_filename: Optional[str] = None, product_name: Optional[str] = None, translations: Optional[list[int]] = None, ) -> None ``` -------------------------------- ### Basic Usage Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-input-file.md Generate a version file using only the metadata provided in a YAML file. ```python import pyinstaller_versionfile # Read all metadata from YAML file pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml" ) ``` -------------------------------- ### Constructor Signature Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md The signature for initializing the Writer instance. ```python def __init__(self, metadata: MetaData) -> None ``` -------------------------------- ### Run Unit Tests Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/CONTRIBUTING.md Execute the unit tests for the project using Tox. ```bash tox -e tests ``` -------------------------------- ### Use KwargsDict Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/types.md Demonstrates how KwargsDict handles existing, None, and missing keys differently than a standard dictionary. ```python kwargs = KwargsDict({"version": None, "name": "App"}) kwargs.setdefault("version", "1.0.0.0") # Sets version to "1.0.0.0" kwargs.setdefault("name", "Default") # Returns "App" (not None) kwargs.setdefault("missing", "default") # Returns "default" ``` -------------------------------- ### Integrate with PyInstaller Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Generate a version file and pass it to the PyInstaller build process. ```bash # Create version file pyivf-make_version --version 1.0.0.0 --product-name "MyApp" --outfile myversion.txt # Use with PyInstaller pyinstaller \ --onefile \ --version-file=myversion.txt \ myapp.py ``` -------------------------------- ### Create Version File with Direct Values (Python API) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Use the functional API to create a version file by directly specifying all metadata values. All parameters are optional and will be filled with placeholders if not provided. ```Python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.2.3.4", company_name="My Imaginary Company", file_description="Simple App", internal_name="Simple App", legal_copyright="© My Imaginary Company. All rights reserved.", original_filename="SimpleApp.exe", product_name="Simple App", translations=[0, 1200] ) ``` -------------------------------- ### Python API: create_versionfile_from_input_file Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Creates a version file by reading metadata from a specified input file (e.g., YAML). ```APIDOC ## Python API: create_versionfile_from_input_file ### Description Generates a version file from a specified input file, such as a YAML configuration. ### Function Signature ```python create_versionfile_from_input_file( output_file: str, input_file: str, version: Optional[str] = None ) ``` ### Parameters - `output_file` (str): The path to the file where the version information will be saved. - `input_file` (str): The path to the input metadata file (e.g., a YAML file). - `version` (Optional[str]): An optional version string to override the version information found in the input file. ### Example ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml", version="1.2.3.4" ) ``` ``` -------------------------------- ### Create Version File from YAML Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Command to create a version file from a YAML configuration. Specify the YAML file path using --metadata-source and the output file with --outfile. ```cmd pyivf-make_version --source-format yaml --metadata-source metadata.yml --outfile file_version_info.txt ``` -------------------------------- ### create_versionfile(output_file, ...) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile.md Generates a Windows version file from explicit metadata parameters. ```APIDOC ## create_versionfile(output_file, version=None, company_name=None, file_description=None, internal_name=None, legal_copyright=None, original_filename=None, product_name=None, translations=None) ### Description Creates a Windows version file from explicit metadata parameters and writes it to the specified output path. ### Parameters - **output_file** (str) - Required - Path to the output version file to be created. - **version** (Optional[str]) - Optional - Version string in format X.Y.Z.W (1–4 numeric parts). Defaults to "0.0.0.0". - **company_name** (Optional[str]) - Optional - Name of the company that produced the file. - **file_description** (Optional[str]) - Optional - User-visible description of the file. - **internal_name** (Optional[str]) - Optional - Internal name of the file. - **legal_copyright** (Optional[str]) - Optional - Copyright notice text. - **original_filename** (Optional[str]) - Optional - Original filename without path. - **product_name** (Optional[str]) - Optional - Name of the product. - **translations** (Optional[list[int]]) - Optional - Flat list of language/charset ID pairs. ### Returns - **None** - Writes the version file to disk at output_file. ### Throws - **ValidationError** - Version string does not match the format \d+(\.\d+){0,3}. - **UsageError** - output_file is a directory instead of a file path. - **InternalUsageError** - Internal error during template rendering. ### Example ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.2.3.4", company_name="Acme Corp", file_description="My Application", internal_name="MyApp", legal_copyright="© 2024 Acme Corp", original_filename="myapp.exe", product_name="My Application", translations=[1033, 1200] ) ``` ``` -------------------------------- ### Create Version File from Distribution (Python API) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Use the functional API to create a version file by extracting metadata from a specified Python distribution. This is advantageous for automated versioning with tools like setuptools_scm. ```Python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="myPackage" ) ``` -------------------------------- ### Set Version from Command Line Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Command to create a version file from YAML metadata, overwriting the version with a specific value using the --version option. Useful for CI build numbers. ```cmd pyivf-make_version --source-format yaml --metadata-source metadata.yml --outfile file_version_info.txt --version 0.8.1.5 ``` -------------------------------- ### Python API: create_versionfile Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Creates a version file by directly specifying all desired version information fields as arguments. ```APIDOC ## Python API: create_versionfile ### Description Generates a version file by allowing all version information fields to be specified directly as function arguments. Fields not provided will be filled with placeholders. ### Function Signature ```python create_versionfile( output_file: str, version: Optional[str] = None, company_name: Optional[str] = None, file_description: Optional[str] = None, internal_name: Optional[str] = None, legal_copyright: Optional[str] = None, original_filename: Optional[str] = None, product_name: Optional[str] = None, translations: Optional[List[Union[int, Tuple[int, int]]]] = None ) ``` ### Parameters - `output_file` (str): The path to the file where the version information will be saved. - `version` (Optional[str]): The version string. - `company_name` (Optional[str]): The company name. - `file_description` (Optional[str]): A description of the file. - `internal_name` (Optional[str]): The internal name of the file. - `legal_copyright` (Optional[str]): The copyright notice. - `original_filename` (Optional[str]): The original filename of the executable. - `product_name` (Optional[str]): The name of the product. - `translations` (Optional[List[Union[int, Tuple[int, int]]]]): A list of translations, specified as language ID and charset ID pairs or just language IDs. ### Example ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.2.3.4", company_name="My Imaginary Company", file_description="Simple App", internal_name="Simple App", legal_copyright="© My Imaginary Company. All rights reserved.", original_filename="SimpleApp.exe", product_name="Simple App", translations=[(0, 1200), (1033, 1252)] ) ``` ``` -------------------------------- ### Function Signature for create_versionfile Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile.md Defines the parameters and type hints for the create_versionfile function. ```python def create_versionfile( output_file: str, version: Optional[str] = None, company_name: Optional[str] = None, file_description: Optional[str] = None, internal_name: Optional[str] = None, legal_copyright: Optional[str] = None, original_filename: Optional[str] = None, product_name: Optional[str] = None, translations: Optional[list[int]] = None, ) -> None ``` -------------------------------- ### Legacy Command Usage Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Syntax for the deprecated create-version-file command. ```bash create-version-file [METADATA_SOURCE] [OPTIONS] ``` -------------------------------- ### Handle InputError for missing files Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Demonstrates the error output when the specified metadata source file does not exist. ```bash $ pyivf-make_version --source-format yaml --metadata-source missing.yml --outfile versionfile.txt Error: File missing.yml does not exist ``` -------------------------------- ### Generate Version Files via CLI Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/README.md Use the pyivf-make_version command-line tool to generate version files from various sources. ```bash # Create from YAML pyivf-make_version --source-format yaml --metadata-source metadata.yml --outfile versionfile.txt # Create from installed package pyivf-make_version --source-format dist --metadata-source mypackage --outfile versionfile.txt # Create from parameters pyivf-make_version --outfile versionfile.txt --version 1.0.0.0 --product-name "My App" ``` -------------------------------- ### Create Version File from Input File (Python API) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md Use the functional API to create a version file from an input metadata file. The version can be optionally specified to overwrite information from the input file. ```Python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml", version="1.2.3.4" # optional, can be set to overwrite version information (equivalent to --version when using the CLI) ) ``` -------------------------------- ### Usage with Overrides Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-input-file.md Generate a version file while overriding specific fields like the version string. ```python import pyinstaller_versionfile # Read from YAML but override version (e.g., from CI build number) pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml", version="1.2.3.4" # Override version from file ) ``` -------------------------------- ### Create version file from YAML configuration Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/INDEX.md Generate a version file using metadata stored in a YAML file, with optional version overrides. ```python import pyinstaller_versionfile # Create from YAML file pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml" ) # With version override (e.g., from CI) pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml", version="2.0.0.0" ) ``` -------------------------------- ### Create version file from YAML Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Generates a version file using metadata defined in a YAML file. Requires a valid UTF-8 encoded YAML source. ```bash pyivf-make_version \ --source-format yaml \ --metadata-source metadata.yml \ --outfile versionfile.txt ``` ```bash pyivf-make_version \ --source-format yaml \ --metadata-source metadata.yml \ --outfile versionfile.txt \ --version 2.0.0.0 \ --company-name "New Company" ``` -------------------------------- ### Handle Output Path as Directory Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/errors.md Catch UsageError when the provided output path points to a directory instead of a file. ```python import pyinstaller_versionfile from pyinstaller_versionfile.exceptions import UsageError try: pyinstaller_versionfile.create_versionfile( output_file="/tmp/", # Directory version="1.0.0.0" ) except UsageError as e: # "You must specify a file to save the output..." pass ``` -------------------------------- ### Overriding Version Metadata Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-distribution.md Demonstrates how to provide a manual version string that takes precedence over the distribution's metadata. ```python import pyinstaller_versionfile # Extract from package metadata but override version (useful in CI/CD) pyinstaller_versionfile.create_versionfile_from_distribution( output_file="versionfile.txt", distname="mypackage", version="2.5.1.0" # Override version (e.g., from setuptools_scm) ) ``` -------------------------------- ### Run Linting Checks Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/CONTRIBUTING.md Execute the linting checks for the project using Tox. ```bash tox -e lint ``` -------------------------------- ### Function Signature Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-input-file.md The definition of the create_versionfile_from_input_file function. ```python def create_versionfile_from_input_file( output_file: str, input_file: str, version: Optional[str] = None, company_name: Optional[str] = None, file_description: Optional[str] = None, internal_name: Optional[str] = None, legal_copyright: Optional[str] = None, original_filename: Optional[str] = None, product_name: Optional[str] = None, translations: Optional[list[int]] = None, ) -> None ``` -------------------------------- ### Create version file with explicit parameters Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/INDEX.md Use this method to define all version file metadata directly within your Python script. ```python import pyinstaller_versionfile pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version="1.2.3.4", company_name="Acme Corp", file_description="My Application", internal_name="MyApp", legal_copyright="© 2024 Acme Corp", original_filename="myapp.exe", product_name="My Application" ) ``` -------------------------------- ### Integrate Environment Variables Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Reads configuration values from environment variables before passing them to the create_versionfile function. ```python import os import pyinstaller_versionfile version = os.getenv("APP_VERSION", "1.0.0.0") company = os.getenv("APP_COMPANY", "Default Company") pyinstaller_versionfile.create_versionfile( output_file="versionfile.txt", version=version, company_name=company ) ``` -------------------------------- ### Import Public API Components Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/modules.md Access core functions, exception classes, and internal classes for version file generation. ```python # Main functions from pyinstaller_versionfile import ( create_versionfile, create_versionfile_from_input_file, create_versionfile_from_distribution, ) # Exception classes from pyinstaller_versionfile.exceptions import ( InputError, ValidationError, UsageError, InternalUsageError, ) # Advanced: Direct class access from pyinstaller_versionfile.metadata import MetaData from pyinstaller_versionfile.writer import Writer ``` -------------------------------- ### Define Complete YAML Configuration Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Includes full metadata fields and custom translation pairs for language and charset IDs. ```yaml Version: 1.2.3.4 CompanyName: Acme Corporation FileDescription: Main application executable InternalName: AcmeApp LegalCopyright: © 2024 Acme Corporation. All rights reserved. OriginalFilename: acmeapp.exe ProductName: Acme Application Translation: - langID: 1033 charsetID: 1200 - langID: 1031 charsetID: 1252 ``` -------------------------------- ### Function Signature for create_versionfile_from_distribution Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/create-versionfile-from-distribution.md The definition of the function including all optional metadata override parameters. ```python def create_versionfile_from_distribution( output_file: str, distname: str, version: Optional[str] = None, company_name: Optional[str] = None, file_description: Optional[str] = None, internal_name: Optional[str] = None, legal_copyright: Optional[str] = None, original_filename: Optional[str] = None, product_name: Optional[str] = None, translations: Optional[list[int]] = None, ) -> None ``` -------------------------------- ### Writer.render() Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Renders the metadata into the version file content using a Jinja2 template. ```APIDOC ## Method: `render()` ### Description Processes the metadata and renders it into the version file content. This method validates that all required fields are present before rendering. ### Throws - `InternalUsageError` - Raised if a required parameter is missing or if template rendering fails. ``` -------------------------------- ### Define VSVersionInfo structure Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/template.md This template structure defines the fixed file information and string file information required for Windows version metadata. ```python # UTF-8 # # For more details about fixed file info 'ffi' see: # http://msdn.microsoft.com/en-us/library/ms646997.aspx VSVersionInfo( ffi=FixedFileInfo( # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # Set not needed items to zero 0. Must always contain 4 elements. filevers=(1,2,3,4), prodvers=(1,2,3,4), # Contains a bitmask that specifies the valid bits 'flags'r mask=0x3f, # Contains a bitmask that specifies the Boolean attributes of the file. flags=0x0, # The operating system for which this file was designed. # 0x4 - NT and there is no need to change it. OS=0x40004, # The general type of file. # 0x1 - the file is an application. fileType=0x1, # The function of the file. # 0x0 - the function is not defined for this fileType subtype=0x0, # Creation date and time stamp. date=(0, 0) ), kids=[ StringFileInfo( [ StringTable( u'040904B0', [StringStruct(u'CompanyName', u'...'), StringStruct(u'FileDescription', u'...'), StringStruct(u'FileVersion', u'...'), StringStruct(u'InternalName', u'...'), StringStruct(u'LegalCopyright', u'...'), StringStruct(u'OriginalFilename', u'...'), StringStruct(u'ProductName', u'...'), StringStruct(u'ProductVersion', u'...')] ]), VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) ] ) ``` -------------------------------- ### Version File Template Structure Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/src/pyinstaller_versionfile/version_file_template.txt This template defines the structure for a version information file used by PyInstaller. It includes placeholders for file version, product version, and various string information like company name, file description, and copyright. ```text # UTF-8 # # For more details about fixed file info 'ffi' see: # http://msdn.microsoft.com/en-us/library/ms646997.aspx VSVersionInfo( ffi=FixedFileInfo( # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # Set not needed items to zero 0. Must always contain 4 elements. filevers={{ "(" + Version.replace(".", ",") + ")" }}, prodvers={{ "(" + Version.replace(".", ",") + ")" }}, # Contains a bitmask that specifies the valid bits 'flags'r mask=0x3f, # Contains a bitmask that specifies the Boolean attributes of the file. flags=0x0, # The operating system for which this file was designed. # 0x4 - NT and there is no need to change it. OS=0x40004, # The general type of file. # 0x1 - the file is an application. fileType=0x1, # The function of the file. # 0x0 - the function is not defined for this fileType subtype=0x0, # Creation date and time stamp. date=(0, 0) ), kids=[ StringFileInfo( [ StringTable( u'040904B0', [StringStruct(u'CompanyName', u'{{CompanyName}}'), StringStruct(u'FileDescription', u'{{FileDescription}}'), StringStruct(u'FileVersion', u'{{Version}}'), StringStruct(u'InternalName', u'{{InternalName}}'), StringStruct(u'LegalCopyright', u'{{LegalCopyright}}'), StringStruct(u'OriginalFilename', u'{{OriginalFilename}}'), StringStruct(u'ProductName', u'{{ProductName}}'), StringStruct(u'ProductVersion', u'{{Version}}')]) ]), VarFileInfo([VarStruct(u'Translation', [{{ Translation|join(", ") }}])]) ] ) ``` -------------------------------- ### MetaData.from_file(filepath, **kwargs) Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Loads metadata from a specified YAML file and returns a MetaData instance. ```APIDOC ## Method: `MetaData.from_file()` ### Description Loads metadata from a YAML file. The method returns a `MetaData` instance initialized with data from the file, merged with any provided keyword argument overrides. ### Signature `@classmethod def from_file(cls, filepath: str, **kwargs: Any) -> MetaData` ### Parameters - **filepath** (str) - Required - Path to a UTF-8 encoded YAML file containing metadata. - **kwargs** (**Any) - Optional - Overrides for any metadata field (same names as constructor parameters). ### Returns - **MetaData** - An instance initialized with data from the file and overrides. ### Throws - **InputError** - Raised if the file does not exist, is a directory, cannot be read, contains invalid YAML, or if the YAML root is not a dictionary. ### Example ```python from pyinstaller_versionfile.metadata import MetaData metadata = MetaData.from_file( "metadata.yml", version="2.0.0.0" # Override version from file ) ``` ``` -------------------------------- ### Run Windows End-to-End Tests Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/CONTRIBUTING.md To include end-to-end tests on Windows, set the 'includeE2E' environment variable to 'true' before running Tox. ```bash tox -e tests-win ``` -------------------------------- ### Reference Version from External File Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Uses a text file path as the value for the Version field. ```yaml Version: VERSION.txt CompanyName: Acme Corporation ProductName: Acme Application ``` -------------------------------- ### Define Minimal YAML Configuration Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Provides the bare minimum fields required for a version file configuration. ```yaml Version: 1.0.0.0 ProductName: My Application ``` -------------------------------- ### Override configuration with function parameters Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/configuration.md Demonstrates how explicit function parameters take precedence over values defined in a YAML input file. ```python import pyinstaller_versionfile # Reads version from metadata.yml but version parameter takes precedence pyinstaller_versionfile.create_versionfile_from_input_file( output_file="versionfile.txt", input_file="metadata.yml", # Version in file: 1.0.0.0 version="2.0.0.0" # Parameter overrides to 2.0.0.0 ) ``` -------------------------------- ### Generate version file with YAML source and version override Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Uses a YAML metadata file as the source while overriding the version string, suitable for CI/CD pipelines. ```bash pyivf-make_version \ --source-format yaml \ --metadata-source config/metadata.yml \ --outfile dist/version_file.txt \ --version 3.2.1.0 ``` -------------------------------- ### Module Dependency Graph Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/modules.md Visual representation of the internal module dependencies. ```text __init__.py ├── metadata.py │ ├── exceptions.py │ ├── PyYAML │ └── importlib.metadata └── writer.py ├── exceptions.py └── jinja2 __main__.py ├── __init__.py ├── exceptions.py └── argparse (stdlib) ``` -------------------------------- ### Define Metadata for VersionFile Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/template.md Input structure used to define application metadata for the version file generation. ```python metadata = MetaData( version="1.2.3.4", company_name="Acme Corp", file_description="My Application", internal_name="MyApp", legal_copyright="© 2024 Acme", original_filename="myapp.exe", product_name="My Application", translations=[1033, 1200] ) ``` -------------------------------- ### Embed version file with PyInstaller Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/template.md Use the --version-file flag to include the generated version information in the build process. ```bash pyinstaller \ --onefile \ --version-file=versionfile.txt \ myapp.py ``` -------------------------------- ### Override Metadata with CLI Parameters Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Demonstrates how explicit command-line arguments override values provided in a metadata source file. ```bash # YAML has version: 1.0.0.0, but command-line overrides it pyivf-make_version \ --source-format yaml \ --metadata-source metadata.yml \ --version 2.0.0.0 # This takes precedence --outfile versionfile.txt ``` -------------------------------- ### Set version string Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md Updates the version string for a MetaData instance. The input must follow the X.Y.Z.W format with 1 to 4 numeric parts. ```python def set_version(self, version_string: str) -> None ``` ```python metadata.set_version("3.0.0.0") ``` -------------------------------- ### Handle UsageError for invalid output path Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Demonstrates the error output when the provided output path is a directory instead of a file. ```bash $ pyivf-make_version --outfile /some/directory/ --version 1.0.0.0 Error: You must specify a file to save the output. Received a directory name instead. ``` -------------------------------- ### MetaData.from_file Method Signature Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/metadata.md The class method signature for loading metadata from a YAML file. ```python @classmethod def from_file(cls, filepath: str, **kwargs: Any) -> MetaData ``` -------------------------------- ### CLI: pyivf-make_version Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/README.md The primary command-line tool for creating version files. It supports various input formats like YAML and distribution metadata, and allows overriding information via command-line options. ```APIDOC ## CLI: pyivf-make_version ### Description Generates a version file compatible with PyInstaller's `--version-file=` option. Supports input from YAML files, installed Python package metadata, or direct command-line arguments. ### Usage ```cmd pyivf-make_version [OPTIONS] ``` ### Options - `--source-format` (string): Specifies the format of the metadata source. Supported values: `yaml`, `dist`, `distribution`. - `--metadata-source` (string): Path to the YAML file or name of the Python package to extract metadata from. Required when `--source-format` is used. - `--outfile` (string): Path to the output file where the version information will be written. - `--version` (string): Overrides the version information. Useful for CI build numbers. ### Example (YAML input) ```cmd pyivf-make_version --source-format yaml --metadata-source metadata.yml --outfile file_version_info.txt ``` ### Example (Distribution input) ```cmd pyivf-make_version --source-format dist --metadata-source PackageName --outfile file_version_info.txt ``` ### Example (YAML with version override) ```cmd pyivf-make_version --source-format yaml --metadata-source metadata.yml --outfile file_version_info.txt --version 0.8.1.5 ``` ``` -------------------------------- ### Render Method Signature Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md The signature for the render method. ```python def render(self) -> None ``` -------------------------------- ### save(filepath: str) -> None Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/writer.md Writes the rendered content to a file on disk. The file is written using UTF-8 encoding. ```APIDOC ## save(filepath: str) -> None ### Description Writes the rendered content to a file on disk. If the file exists, it will be overwritten. The file is written in UTF-8 encoding. ### Parameters - **filepath** (str) - Required - Path to the output file. ### Throws - **InternalUsageError** - Thrown if render() was not called before save(). - **UsageError** - Thrown if filepath is a directory instead of a file path. ### Example ```python writer.render() writer.save("versionfile.txt") ``` ``` -------------------------------- ### Generated VSVersionInfo Output Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/template.md The resulting Windows VERSIONINFO structure generated from the provided metadata. ```python # UTF-8 # # For more details about fixed file info 'ffi' see: # http://msdn.microsoft.com/en-us/library/ms646997.aspx VSVersionInfo( ffi=FixedFileInfo( filevers=(1,2,3,4), prodvers=(1,2,3,4), mask=0x3f, flags=0x0, OS=0x40004, fileType=0x1, subtype=0x0, date=(0, 0) ), kids=[ StringFileInfo( [ StringTable( u'040904B0', [StringStruct(u'CompanyName', u'Acme Corp'), StringStruct(u'FileDescription', u'My Application'), StringStruct(u'FileVersion', u'1.2.3.4'), StringStruct(u'InternalName', u'MyApp'), StringStruct(u'LegalCopyright', u'© 2024 Acme'), StringStruct(u'OriginalFilename', u'myapp.exe'), StringStruct(u'ProductName', u'My Application'), StringStruct(u'ProductVersion', u'1.2.3.4')] ]), VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) ] ) ``` -------------------------------- ### Handle ValidationError for invalid version format Source: https://github.com/dudenr33/pyinstaller-versionfile/blob/master/_autodocs/api-reference/cli-make-version.md Demonstrates the error output when the provided version string does not meet the four-digit requirement. ```bash $ pyivf-make_version --outfile versionfile.txt --version invalid.version Error: Provided version invalid.version is not valid. Valid versions must contain four places with only digits. ```