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

Add a Python (pypi) version of Maven Artifact Zip Directory Structure to build hook (and upload to pypi registry) #14

Closed
jimisola opened this issue Oct 15, 2024 · 6 comments · Fixed by #20
Assignees

Comments

@jimisola
Copy link

jimisola commented Oct 15, 2024

Relates to: luftfartsverket/reqstool-client#111

For Java we create the zip file during packageand attach it so that it is uploaded during deploy.
With hatch we have targets build and publish. We can create the zip file in build and/or publish so that it's uploaded to pypi in publish.

See: https://hatch.pypa.io/1.12/plugins/publisher/reference/#hatch.publish.plugin.interface.PublisherInterface

  1. config in pyproject.toml
[tool.hatch.publish.publish_reqstool_zip_artifact]
dependencies = ["reqstool-python-hatch-plugin == <version>"]
# https://luftfartsverket.github.io/reqstool-java-maven-plugin/reqstool-java-maven-plugin/0.0.3/index.html#_configuration
requirementsAnnotationsFile
svcsAnnotationsFile
outputDirectory
datasetPath
failsafeReportsDir/surefireReportsDir
  1. Implement a plugin with corresponding hook configuration

Update docs for publish hook in README and AsciiDoc.

@jimisola jimisola changed the title Add hook for a Python (pypi) version of Maven Artifact Zip Directory Structure and upload to pypi registry Add publish hook for a Python (pypi) version of Maven Artifact Zip Directory Structure and upload to pypi registry Oct 15, 2024
@jimisola
Copy link
Author

Stub:

import os
import zipfile
from hatchling.publish.plugin.interface import PublisherInterface
from dataclasses import field, dataclass
from typing import List

class ReqstoolZipArtifactPublisher(PublisherInterface):
    PLUGIN_NAME = 'publish_reqstool_zip_artifact'

    def publish(self, artifacts):
        config = self.config
        
        # Default values for paths

        # Fetch configuration from pyproject.toml or use default values
        requirements_annotations_file = config.get('requirements_annotations_file', "build/reqstool/annotations.yml")
        # ....
        
        
        # Define output ZIP file
        zipfile_name = os.path.join(output_directory, 'build_output.zip')

        # Create ZIP file
        with zipfile.ZipFile(zipfile_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
            # Add files to the ZIP archive
            if os.path.exists(requirements_annotations_file):
                zipf.write(requirements_annotations_file, os.path.basename(requirements_annotations_file))

            if os.path.exists(dataset_path):
                for root, _, files in os.walk(dataset_path):
                    for file in files:
                        file_path = os.path.join(root, file)
                        zipf.write(file_path, os.path.relpath(file_path, dataset_path))

            # Include junit report directory
            if os.path.exists(junit_reports_dir):
                for root, _, files in os.walk(junit_reports_dir):
                    for file in files:
                        file_path = os.path.join(root, file)
                        zipf.write(file_path, os.path.relpath(file_path, junit_reports_dir))

        print(f"ZIP file created: {zipfile_name}")
        return artifacts
[tool.hatch.publish.zip_publisher]
requirements_annotations_file = "path/to/requirements.yml"
svcs_annotations_file = "path/to/software_verification_cases.yml"
output_directory = "path/to/output"
dataset_path = "path/to/manual_verification_results.yml"
junit_reports_dir = "path/to/junit-reports"

@lfvjimisola lfvjimisola self-assigned this Oct 21, 2024
@lfvjimisola lfvjimisola changed the title Add publish hook for a Python (pypi) version of Maven Artifact Zip Directory Structure and upload to pypi registry Add a Python (pypi) version of Maven Artifact Zip Directory Structure to build hook (and upload to pypi registry) Oct 21, 2024
@lfvjimisola
Copy link
Contributor

Some changes will be made due to #13 and the decision with @lfvdavid to create zip in build hook

@lfvjimisola
Copy link
Contributor

lfvjimisola commented Oct 21, 2024

@jimisola
Copy link
Author

jimisola commented Oct 21, 2024

pypi and PEPs only allow for one sdist (tar.gz) so we have to either

  1. make sure that the reqstools files are in the tar.gz sdist file (which they are, but depending on build system; hatchling, poetry etc, the layout may differ. Some sort of fixes reqstool index file pointing out the files is then needed similar to reqstool_config.yml

  2. using a separate package with additional suffix, i.e. mypackage will have sibling package mypackage-reqstool. however, the drawbacks are substantial with this solution:

  3. administration of to pypi projects for each actual projects

  4. how to assure atomic deploys, that both mypackage and sibling mypackage-reqstool are uploaded successfully at the same time

@lfvdavid @lfvkalle @lfvJonas I reckon we need to go with option 1

Filename suggestions:

  1. reqstool.yaml
  2. reqstool-metadata.yaml
  3. reqstool_metadata.yaml
  4. reqstool.metadata.yaml

@lfvdavid
Copy link
Contributor

lfvdavid commented Oct 22, 2024

Agree with option 1.

Is it only one file? Had the impression it would be a dir containing the reqstool files.

In any case either 1. or 3.

1 is simple

3 is more describing and follows the same format as the reqstool files such as ´software_verification_cases.yml´

@lfvjimisola
Copy link
Contributor

So, final solution (which includes breaking changes):

  1. the configuration of the plugin has changed
  2. a reqstool_config.yml is added the sdist (which already includes all the reqstool files)
  3. the sdist is uploaded as usual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants