-
Notifications
You must be signed in to change notification settings - Fork 0
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
Comments
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" |
Check e.g. |
pypi and PEPs only allow for one sdist (tar.gz) so we have to either
@lfvdavid @lfvkalle @lfvJonas I reckon we need to go with option 1 Filename suggestions:
|
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´ |
So, final solution (which includes breaking changes):
|
Relates to: luftfartsverket/reqstool-client#111
For Java we create the zip file during
package
and attach it so that it is uploaded duringdeploy
.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
https://github.com/luftfartsverket/reqstool-python-hatch-plugin/blob/main/src/reqstool_python_hatch_plugin/publish_hooks/publish_reqstool_zip_artifact.py
Hook into
finalize
rather thaninitialize
https://github.com/luftfartsverket/reqstool-python-hatch-plugin/blob/main/src/reqstool_python_hatch_plugin/build_hook/hook.py#L49PLUGIN_NAME = "publish_reqstool_zip_artifact"
Update docs for publish hook in README and AsciiDoc.
The text was updated successfully, but these errors were encountered: