Skip to content

Automate requirements.txt creation - #2086

Closed
Abhishek-Dev09-zz wants to merge 2 commits into
aboutcode-org:developfrom
Abhishek-Dev09-zz:#295-requirement.txt
Closed

Abhishek-Dev09-zz wants to merge 2 commits into
aboutcode-org:developfrom
Abhishek-Dev09-zz:#295-requirement.txt

Conversation

@Abhishek-Dev09-zz

@Abhishek-Dev09-zz Abhishek-Dev09-zz commented Jun 23, 2020

Copy link
Copy Markdown

This script is use to build deps for python 3.6 #295 and release the deps as assets on github

Fixes aboutcode-org/skeleton#50 #2068

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁

Signed-off-by: Abhishek Kumar abhishek.kasyap09@gmail.com

This script is use to build deps for python 3.6 aboutcode-org#295 and release the deps as assets on github

Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>
@Abhishek-Dev09-zz
Abhishek-Dev09-zz force-pushed the #295-requirement.txt branch 2 times, most recently from 519d18a to fad3166 Compare July 7, 2020 07:11
@Abhishek-Dev09-zz

Abhishek-Dev09-zz commented Jul 7, 2020

Copy link
Copy Markdown
Author

@pombredanne : Output of github_release.py - https://github.com/Abhishek-Dev09/thirdparty/releases/tag/v1.0 . It is automated and generated by this script only . Now i focussing for py3.6 for now. So don't panic for py 3.7 & 3.8 . Once we done with 3.6 , we can easily move to other py version.

@pombredanne

Copy link
Copy Markdown
Member

@Abhishek-Dev09 can you check your ABOUT files?
bin/about check thirdparty/

@Abhishek-Dev09-zz

Copy link
Copy Markdown
Author

@Abhishek-Dev09 can you check your ABOUT files?
bin/about check thirdparty/

mymac@ABHISHEKs-MacBook-Air scancode-toolkit % bin/about check thirdparty/ zsh: no such file or directory: bin/about

@pombredanne pombredanne left a comment

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.

Thanks!
I posted some comments for a start.

I think you need to design some Requirements object (see dparse or packaging or pyup for libraries that may be worth adopting such as https://github.com/pyupio/pyup/blob/master/pyup/requirements.py ) and not read/write continuously to files with hardcoded names.

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
import subprocess


os.chdir(os.pardir) #go to etc

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.

Why not keeping this in a function?

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.

removed

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
os.chdir(os.pardir) # go to scancode-toolkit
cwd = os.getcwd()
print("Current working directory:", cwd)
fp = open("requirements.txt", "wb")

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.

Why do you open/close here? It does nothing and is possibly a source of failures

@Abhishek-Dev09-zz Abhishek-Dev09-zz Jul 7, 2020

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 create empty file . We need that because without this this scripts not work. This script assume that we already have requirements.txt file.

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
def is_package_exist_with_hashes(package_name,hash_of_file):
""" Check if any line in the file contains package with same hashes """
# Open the file in read only mode
line_with_hash = package_name + " \\" + "\n" + " --hash=sha256:"+ hash_of_file

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 use .format() with a mapping? It makes things much easier to read

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.

Done

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
""" Check if any line in the file contains package with same hashes """
# Open the file in read only mode
line_with_hash = package_name + " \\" + "\n" + " --hash=sha256:"+ hash_of_file
with open("requirements.txt", 'r') as read_obj:

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.

You need to use single vs. double quotes consistently. We use single quotes unless this is a doc string.

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.

done

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 do it everywhere.

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
Comment on lines +53 to +65
for line in read_obj:
# For each line, check if line contains the package with same hashes
if line_with_hash in line:
return True
return False

def is_package_exist_without_hashes(package_name):
""" Check if any line in the file contains package without same hash """
# Open the file in read only mode
line_with_hash = package_name + " \\" + "\n"
with open("requirements.txt", 'r') as read_obj:
# Read all lines in the file one by one
for line in read_obj:

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 find a better name than read_obj

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.

i use name as file

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 find a better name: read_obj means nothing. What is this file about? what does it contain?

Comment thread etc/scripts/freeze_and_update_reqs.py Outdated
""" Check if any line in the file contains package without same hash """
# Open the file in read only mode
line_with_hash = package_name + " \\" + "\n"
with open("requirements.txt", 'r') as read_obj:

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.

Could you craft some kind of object for the requirements like some Requirement class and not open the requirements.txt file over and over?
Also the file may very likely be named some else than requirements.txt?

In open("requirements.txt", 'r') use instead open('requirements.txt') as reading text is the default alright.

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.

done

@Abhishek-Dev09-zz
Abhishek-Dev09-zz force-pushed the #295-requirement.txt branch 4 times, most recently from cf10c87 to d20fede Compare July 7, 2020 22:17
…ode-org#295

This script copies all thirdparty files(required) and place it in repo as release assets.

Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>

@pombredanne pombredanne left a comment

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.

Thank you! here are some comment for your consideration:

  • Can you review and fix the formatting for your code?
  • Having an a Requirement object of sorts would really make more sense that always opening and writing a file.
  • Please do not mix adding or removing wheels in this PR, focus instead on the scripts only
  • you need to add also tests

return hash.hexdigest()

def main():
os.chdir(os.pardir) #go to etc

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.

You should accept an argument with a path to a requirements files instead of trying to change the working dir.

os.chdir(os.pardir) # go to scancode-toolkit
cwd = os.getcwd()
print("Current working directory:", cwd)
fp= open('requirements.txt','w') #Create empty file because it must exits before opening the file in read mode.

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.

Use a with context manager.

cwd = os.getcwd()
print("Current working directory:", cwd)
fp= open('requirements.txt','w') #Create empty file because it must exits before opening the file in read mode.
for subdir, dirs, files in os.walk(cwd+"/thirdparty"):

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.

You should accept an argument for the thirdparty directory. Also it would be likely easier to understand if you load all file paths at once and iterate after. You should also reuse the commonode.fileutils functions

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.

You talking about which function in fileutils?

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.

resource_iter()

for filename in files:
filepath = subdir + os.sep + filename
if filepath.endswith(".whl") and (fnmatch.fnmatchcase(filename, "*py3*") or fnmatch.fnmatchcase(filename, "*cp36*")):
name = filename.split('-')[0]

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 would really prefer that you use that https://github.com/jwodder/wheel-filename as a library.

Comment thread github_release.py
def main():
cwd = os.getcwd()
print("Current working directory:", cwd)
subprocess.run(["pip3","install","github-release-retry"])

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.

Do not do that. Have a requirements file instead and a README.rst that explains what to do

Comment thread github_release.py

os.environ ["GITHUB_TOKEN"] = token

tag = input ("Enter tag_name :")

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.

do not use input, instead use arguments for main() and accept command line arguments

append_requirement_file(package_name,hs)
else: add_package(package_name,hs)

elif filepath.endswith(".gz") and not filename.startswith("py2-"):

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.

which filename would ever start with "py2-"? and what is endswith(".gz")? about?

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.

py2-ipaddress.tar.gz

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.

Why would you single out a specific package name? What's so special about this?

@Abhishek-Dev09-zz Abhishek-Dev09-zz Jul 8, 2020

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.

because my function would not work for py2-ipaddress.tar.gz but don't worry this package will be removed after dropping python 2.

@pombredanne pombredanne Jul 9, 2020

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.

your function should not have any Python-package specific hack. The problem is in your code then

@pombredanne pombredanne changed the title Script to atomate requirements.txt Automate requirements.txt creation Jul 8, 2020
@pombredanne

Copy link
Copy Markdown
Member

@Abhishek-Dev09 can you check your ABOUT files?
bin/about check thirdparty/

mymac@ABHISHEKs-MacBook-Air scancode-toolkit % bin/about check thirdparty/ zsh: no such file or directory: bin/about

You need to be properly configured with ./configure ... if you ran it once about would be there

@pombredanne

Copy link
Copy Markdown
Member

Hi: Is this PR obsolete and replaced by #2118 ? If yes, may you can close this one here?

@Abhishek-Dev09-zz

Copy link
Copy Markdown
Author

Hi: Is this PR obsolete and replaced by #2118 ? If yes, may you can close this one here?

Yes, i m closing this

pombredanne pushed a commit that referenced this pull request Sep 8, 2022
Uxn is a virtual machine which represents a personal computing
playground, and is described here:

    https://100r.co/site/uxn.html

Uxntal assembly language is described here:

    https://wiki.xxiivv.com/site/uxntal.html

The demo code piano.tal is used with permission.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev utility: Create script to generate requirements with hashes

3 participants