Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions etc/scripts/deps_archive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
# The ScanCode software is licensed under the Apache License version 2.0.
# Data generated with ScanCode require an acknowledgment.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# When you publish or redistribute any data created with ScanCode or any ScanCode
# derivative work, you must accompany this data with the following acknowledgment:
#
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
# ScanCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.

from __future__ import absolute_import
from __future__ import print_function

import argparse
from commoncode.system import on_windows

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort your imports: commoncode is not from the stdlib, but our own code and should go in a separate block.
See for instance https://github.com/nexB/scancode-toolkit/blob/develop/src/packagedcode/cargo.py#L36

import os
from shutil import make_archive
from subprocess import run
import sys


def generate_os_archive(links, requirement, output_file):
"""
Generate an archive for dependencies for specific OS and
given version of python by taking directory as an input.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why and how this archive would be used?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will generate an archive for each os and each python. For example - macOS_py36.tar.gz, win3_py36.zip, win64_py.36zip, linux_py36.tar.gz . For more info see PR description

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not know what these archives will be used for.... Are you saying that you plan to upload one such archive per OS/Python/scancode version to a GH release?
That archive will not be usable as a pip find-link then. And if there are dupes between OSes... that is going to be problematic. The archives we want to upload would be something built with etc/release/ scripts instead... e.g. full sdist with a streamlined thirparty

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you said earlier One archive for each OS/Python combo should be created and each should have its exact set of pinned requirements included in the built archive, no more and no less.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I would prefer to have the sdist being use for these archives that's using a proper manifest and does not include things we do not want there. For this you should expand on the release script instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI , this will give you 1 directory along with tar.gz ,if you are on linux /macOS.
if you are on window, you get 1 directory along with zip.

BTW i got directory of wheels of 30.1 MB and tar.gz of 28 MB on my macOS.

pip_agrs =[
'pip',
'download',
'--verbose',
'--no-cache-dir',
'--no-index',
'--find-links',
links,
'-r',
requirement,
'--dest',
'my_deps',
]
run(pip_agrs)
root_dir = os.path.abspath('my_deps')
output_dir = os.path.abspath(output_file)
if on_windows:
make_archive(output_dir, 'zip', root_dir)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am stil not clear about what these archives wrt. to what we need as sdist

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you get all wheel/sdist deps packed like sdist file that required for ur python/os.

else:
make_archive(output_dir, 'gztar', root_dir)


def main_with_args(args: str) -> None:
parser = argparse.ArgumentParser(
description="""Creates a archive for specific OS and specific python.
EXAMPLE:
deps_archive.py \\
--input thirdparty \\
--req requirements.txt
--output_file macOS_py36 \\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove that as it does help readability.

""",
formatter_class=argparse.RawDescriptionHelpFormatter,
)

parser.add_argument(
'--find_links',
help="Required: A url or path to an html file, then parse for links to archives. If a local path or file://url that's a directory, then look for archives in the directory listing",
type=str,
required=True,
)

parser.add_argument(
'--req',
help='A requirement_file with hashes',
type=str,
required=True,
)

parser.add_argument(
'--output_file',
help='Required: The Generated archive file name without extension.',
type=str,
required=True,
)

args = parser.parse_args()

link = args.find_links
req = args.req
output = args.output_file
generate_os_archive(link, req, output)


def main() -> None:
main_with_args(sys.argv[1:])


if __name__ == '__main__':
main()
158 changes: 158 additions & 0 deletions etc/scripts/github_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
# The ScanCode software is licensed under the Apache License version 2.0.
# Data generated with ScanCode require an acknowledgment.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# When you publish or redistribute any data created with ScanCode or any ScanCode
# derivative work, you must accompany this data with the following acknowledgment:
#
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
# ScanCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.

from __future__ import absolute_import
from __future__ import print_function

import argparse
from commoncode.fileutils import resource_iter
from fnmatch import fnmatchcase
import os
from subprocess import run
import sys

python_version = str(sys.version_info[0]) + str(sys.version_info[1])
py_abi = '{0}cp{1}{0}'.format('*', python_version)


def release_asset(token, tag, repo, body, user, limit, asset_dir):
"""
Comment thread
Abhishek-Dev09-zz marked this conversation as resolved.
Release .whl,.ABOUT,.NOTICE,.LICENSE to github repository from
given directory.
"""

os.environ['GITHUB_TOKEN'] = token
thirdparty = list(resource_iter(asset_dir, with_dirs=False))
dependencies = [
files
for files in thirdparty
if fnmatchcase(files, '*py3*')
or fnmatchcase(files, py_abi)
or (
fnmatchcase(files, '*tar.gz*')
and not fnmatchcase(files, '*py2-ipaddress-3.4.1.tar.gz*')
)
]
for deps in dependencies:
github_args = [
'python3',
'-m',
'github_release_retry.github_release_retry',
'--user',
user,
'--repo',
repo,
'--tag_name',
tag,
'--body_string',
body,
'--retry_limit',
limit,
deps,
]
run(github_args)


def main_with_args(args: str) -> None:
parser = argparse.ArgumentParser(
description="""Creates a GitHub release (if it does not already exist) and uploads files to the release.
Please pass the GITHUB_TOKEN as an argument.
EXAMPLE:
github-release.py \\
--user Abhishek-Dev09 \\
--token XXXXXXXXXXXXX \\
--repo thirdparty \\
--tag_name v1.0 \\
--body_string "Python 3.6 wheels" \\
hello-world.zip RELEASE_NOTES.txt
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
)

parser.add_argument(
'--user',
help='Required: The GitHub username or organization name in which the repo resides.',
type=str,
required=True,
)

parser.add_argument(
'--token',
help='Required: The Github token is required to acess the repository where you want to upload.',
type=str,
required=True,
)

parser.add_argument(
'--repo',
help='Required: The GitHub repo name in which to make the release.',
type=str,
required=True,
)

parser.add_argument(
'--tag_name',
help='Required: The name of the tag to create or use.',
type=str,
required=True,
)

parser.add_argument(
'--body_string',
help='Required : Text describing the release. Ignored if the release already exists.',
type=str,
required=True,
)

parser.add_argument(
'--retry_limit',
help='The number of times to retry creating/getting the release and/or uploading each file.',
type=str,
default='10',
)

parser.add_argument(
'--files', type=str, help='The files to upload to the release.',
)

args = parser.parse_args()

token = args.token
tag = args.tag_name
repo = args.repo
body = args.body_string
user = args.user
limit = args.retry_limit
deps_dir = args.files

release_asset(token, tag, repo, body, user, limit, deps_dir)


def main() -> None:
main_with_args(sys.argv[1:])


if __name__ == '__main__':
main()