Skip to content

Commit

Permalink
fix(license): remove license file
Browse files Browse the repository at this point in the history
This PR removes the license file and uses the license field in meta data instead as the single source of declaring a license for a plugin or a recipe.

Resolves #154
  • Loading branch information
mostaphaRoudsari committed Dec 9, 2020
1 parent 9b364f5 commit 92d929c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 65 deletions.
4 changes: 2 additions & 2 deletions queenbee/base/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from typing import List
from pydantic import Field, constr
from pydantic import Field, constr, AnyUrl

from .basemodel import BaseModel

Expand Down Expand Up @@ -36,7 +36,7 @@ class License(BaseModel):
description='The license name used for the package.'
)

url: str = Field(
url: AnyUrl = Field(
None,
description='A URL to the license used for the package.'
)
Expand Down
9 changes: 4 additions & 5 deletions queenbee/plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Queenbee Plugin class."""
import json
import os
import yaml
from typing import List
Expand Down Expand Up @@ -143,7 +144,7 @@ def from_folder(cls, folder_path: str):

return cls.parse_obj(plugin)

def to_folder(self, folder_path: str, readme_string: str = None, license_string: str = None):
def to_folder(self, folder_path: str, *, readme_string: str = None):
"""Write a plugin to a folder
Note:
Expand All @@ -164,7 +165,6 @@ def to_folder(self, folder_path: str, readme_string: str = None, license_string:
Keyword Arguments:
readme_string {str} -- The README file string (default: {None})
license_string {str} -- The LICENSE file string (default: {None})
"""
os.makedirs(os.path.join(folder_path, 'functions'), exist_ok=True)

Expand All @@ -186,6 +186,5 @@ def to_folder(self, folder_path: str, readme_string: str = None, license_string:
with open(os.path.join(folder_path, 'README.md'), 'w') as f:
f.write(readme_string)

if license_string is not None:
with open(os.path.join(folder_path, 'LICENSE'), 'w') as f:
f.write(license_string)
with open(os.path.join(folder_path, 'LICENSE'), 'w') as f:
f.write('To see the license for this package refer to package.yaml')
11 changes: 4 additions & 7 deletions queenbee/recipe/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def write_dependency_file(self, folder_path: str):
)
)

def to_folder(self, folder_path: str, readme_string: str = None, license_string: str = None):
def to_folder(self, folder_path: str, readme_string: str = None):
"""Write a Recipe to a folder
Note:
Expand Down Expand Up @@ -309,7 +309,6 @@ def to_folder(self, folder_path: str, readme_string: str = None, license_string:
Keyword Arguments:
readme_string {str} -- The README file string (default: {None})
license_string {str} -- The LICENSE file string (default: {None})
"""

os.makedirs(os.path.join(folder_path, 'flow'), exist_ok=True)
Expand All @@ -330,9 +329,8 @@ def to_folder(self, folder_path: str, readme_string: str = None, license_string:
with open(os.path.join(folder_path, 'README.md'), 'w') as f:
f.write(readme_string)

if license_string is not None:
with open(os.path.join(folder_path, 'LICENSE'), 'w') as f:
f.write(license_string)
with open(os.path.join(folder_path, 'LICENSE'), 'w') as f:
f.write('To see the license for this package refer to package.yaml')

def write_dependencies(self, folder_path: str, config: Config = Config()):
"""Fetch dependencies manifests and write them to the `.dependencies` folder
Expand Down Expand Up @@ -372,8 +370,7 @@ def write_dependencies(self, folder_path: str, config: Config = Config()):
folder_path=os.path.join(
folder_path, '.dependencies',
dependency.dependency_kind, dependency.ref_name),
readme_string=package_version.readme,
license_string=package_version.license,
readme_string=package_version.readme
)


Expand Down
54 changes: 3 additions & 51 deletions queenbee/repository/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class PackageVersion(MetaData):
description='The README file string for this package'
)

license: str = Field(
None,
description='The License file string for this package'
)

manifest: Union[Recipe, Plugin] = Field(
None,
description="The package Recipe or Plugin manifest"
Expand Down Expand Up @@ -119,7 +114,6 @@ def from_resource(
def pack_tar(cls,
resource: Union[Plugin, Recipe],
readme: str = None,
license: str = None,
include_manifest: bool = False,
) -> Tuple['PackageVersion', BytesIO]:
"""Package a resource into a gzipped tar archive
Expand All @@ -131,8 +125,6 @@ def pack_tar(cls,
Keyword Arguments:
readme {str} -- resource README.md file text if it exists
(default: {None})
license {str} -- resource LICENSE file text if it exists
(default: {None})
Raises:
ValueError: Failed to create the package
Expand Down Expand Up @@ -176,17 +168,9 @@ def pack_tar(cls,
filename='README.md'
)

if license is not None:
add_to_tar(
tar=tar,
data=bytes(license, 'utf-8'),
filename='LICENSE'
)

tar.close()

resource_version.readme = readme
resource_version.license = license

if include_manifest:
resource_version.manifest = resource
Expand All @@ -206,7 +190,6 @@ def unpack_tar(
manifest_bytes = None
version = None
readme_string = None
license_string = None
read_digest = None

for member in tar.getmembers():
Expand All @@ -225,8 +208,6 @@ def unpack_tar(
version = cls.parse_raw(tar.extractfile(member).read())
elif member.name == 'README.md':
readme_string = tar.extractfile(member).read().decode('utf-8')
elif member.name == 'LICENSE':
license_string = tar.extractfile(member).read().decode('utf-8')

if manifest_bytes is None:
raise ValueError(
Expand All @@ -247,7 +228,6 @@ def unpack_tar(

version.manifest = manifest
version.readme = readme_string
version.license = license_string
version.digest = read_digest

return version
Expand Down Expand Up @@ -317,35 +297,11 @@ def read_readme(folder_path: str) -> str:
with open(path_to_readme, 'r') as f:
return f.read()

@staticmethod
def read_license(folder_path: str) -> str:
"""Infer the path to the license file within a folder and read it
Arguments:
folder_path {str} -- Path to the folder where a license file should be found
Returns:
str -- The found licence text (or None if no license file is found)
"""
path_to_license = None

license_pattern = r'^license$'

for file in os.listdir(folder_path):
res = re.match(license_pattern, file, re.IGNORECASE)
if res is not None:
path_to_license = os.path.join(folder_path, file)

if path_to_license is not None:
with open(path_to_license, 'r') as f:
return f.read()

@classmethod
def package_resource(cls,
resource: Union[Plugin, Recipe],
check_deps: bool = True,
readme: str = None,
license: str = None,
readme: str = None
) -> Tuple['PackageVersion', BytesIO]:
"""Package a Recipe or Plugin into a gzipped tar file
Expand All @@ -355,8 +311,6 @@ def package_resource(cls,
Keyword Arguments:
readme {str} -- resource README.md file text if it exists
(default: {None})
license {str} -- resource LICENSE file text if it exists
(default: {None})
Returns:
PackageVersion -- A plugin or recipe version object
Expand All @@ -368,8 +322,7 @@ def package_resource(cls,

return cls.pack_tar(
resource=resource,
readme=readme,
license=license,
readme=readme
)

@classmethod
Expand Down Expand Up @@ -403,8 +356,7 @@ def package_folder(
return cls.package_resource(
resource=resource,
check_deps=check_deps,
readme=cls.read_readme(folder_path),
license=cls.read_license(folder_path),
readme=cls.read_readme(folder_path)
)

def search_match(self, search_string: str = None) -> bool:
Expand Down

0 comments on commit 92d929c

Please sign in to comment.