-
-
Notifications
You must be signed in to change notification settings - Fork 792
Expose all .whl,.ABOUT, .NOTICE,.LICENCE files and Create an archive #2117
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
Changes from 4 commits
f08eacf
89e957e
90bff2b
2e80d15
393fad4
d0e1386
27c4e86
c062d21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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. | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remind me why and how this archive would be used?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you said earlier
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I would prefer to have the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \\ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
| 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): | ||
| """ | ||
|
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() | ||
There was a problem hiding this comment.
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