Integrate pylint with github review comments - python

I am trying to make a script that runs pylint on the files present in the pull request and creates inline comments for the linting errors.
I got a hang on how to use PyGithub. The problem is that in order to comment on a pull-request you will have to know the commit that modified the file and the line number from the patch. Full documentation on the review comments API is found here.
Pylint returns the line in the resulted file. I need to get from foo/bar.py:30 to the commit that modified line 30 in foo/bar.py and to get the actual position in the diff for that file.
Is there something that already can do this or do I have to manually search for ## lines in every commit involved in a pull request?

What you are asking for is exactly what the blame feature does.
The only API I could find was this restfulgit.
Based on blind text search this here looks like the function that implements getting blame info, if you understand how it uses the underlying git api then you can just copy that part instead of using the restfulgit

Related

is there a way to set the title and author metadata properties of a pdf in python?

I need to create numerous ADA-compliant pdfs from word documents. I used a code snippet from comtypes.client which works very well to create a pdf, but when i run the accessibility checker on the PDF, it gives a Title FAIL, and it has my name as the author rather than my organization's name. Is there any way to set the title and author while making the PDF or alternatively, after it is finished? I would prefer to use python, but if there are any other simpler methods out there, I am game.
I have looked at PyPDF2, but it seems to only set 'custom metadata' rather than actually change or set title/author properties. (plus the code snippet I tried from the web kept returning an error - i am not pasting the code though as i dont think it does what i need anyways..)
I cannot tell if something like pdftk does what i need or not...i cant find anyway to do it with the free version, and i see this example https://sejh.wordpress.com/2014/11/26/changing-pdf-titles-with-pdftk/, but at best it looks like it might work for title but not author, and i am not sure if there is an easy way to run the script for many pdfs...
Ive also looked into EXIF, which seems to only read pdfs, but points to XMP as a way to write the metadata... only after resurfacing from an extensive XMP rabbit-hole i went down, i still cant tell if it would be useful or not.
so i thought i would try here. see if anyone has a nice, easy python solution, or if not, can point me to a rabbit hole worth going down, and any hints on how to navigate said rabbit-holes to find an answer.
Much appreciated!
i was able to solve my issue at the Word document stage by using the core_properties attribute in Python's docx (I had not been aware of this attribute at the time of my original post).
import docx
doc = docx.Document()
cp = doc.core_properties
cp.author = 'author name'
cp.title = 'title content'
cp.subject = 'subject content'
when I then used Python's comtypes to pdf the Word doc, the metadata transferred successfully.
The general reason for you as Author is "Machine User is the Author even if that is your secretary" so easiest is run a PDF app in an "Organisation" login, but as you point out pdftk allows you to make changes, so stick with that. Use Python to write the needful change in NewInfo.txt then shell out to run pdftk.
InfoBegin
InfoKey: Creator
InfoValue: Stack OverFlow
InfoBegin
InfoKey: Producer
InfoValue: Status Quo
InfoBegin
InfoKey: Author
InfoValue: K Steinmann
InfoBegin
InfoKey: Title
InfoValue: Whatever You Want, Whatever You Need, dah dah dah...
pdftk input.pdf update_info NewInfo.txt output output.pdf

Download latest update with inconsistent file name on github

I'm currently looking to make an updater program for my plugins for guildwars 2, but I got a little issue for the last download. The name of the file to download isn't consistent from version to version as you can see there. Asking the creator to update it so it is consistent is already something that has been done some month ago, but as the updates are fairly rare and nothing has been done.
Would there be a way to get either all the release files, or to downlaod the using filter so it doesn't get the other ones?
For now i've been using the following code to download the other plugins and write them to the corresponding file, but this method doesn't work at all with that specific one because the name of this release changes.
(using python 3.9.6)
import requests
test = requests.get('https://github.com/knoxfighter/arcdps-killproof.me-plugin/releases/latest/download/d3d9_arcdps_killproof_me.dll', allow_redirects=True)
print("code :" + str(test.status_code))
open('d3d9_arcdps_killproof_me.dll', 'wb').write(test.content)
Any ideas on how I could work arround this and still download this last plugin?
If you're looking for an example of how to call git pull from within python, this seems to be a good solution:
The code is using this library:
https://github.com/gitpython-developers/GitPython
import git
g = git.cmd.Git(git_dir)
g.pull()

Extremely new user to Python. "No module named request" error while trying code to detect image subdomains in a website to extract them to a folder

I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py

Code inside of a python file deleted

The code inside of a python file randomly deleted, is there anyway to restore? It is a file of 3.70 KB but when opened and put into a text document there is nothing.
Open with python to see what it contains
with open('deleted.py', 'rb') as f:
print(repr(f.read()))
Since you are a new user I am assuming you are new to code development etc. Therefore, you should look at some versioning control tools like:
SVN
Github
Gitlab
There are some more, but these are the most common ones. They are used to store your code and to revert you code if you mess up. They are also used to merge codes when different programmers are changing it. For the moment this will not help but will help in the future.
For now you may look at some restore tools but I highly doubt it that you are able to recreate the file. Another possiblity is: when you haven IDE to look at your command history. Maybe you executed the script and you can find the executed script as commands in the command history.

How do I get hgweb to actually display the repository I want?

I am having an infuriating experience with IIS7, Python 2.6, Mercurial 1.7.2, and hgweb.cgi.
After battling for an afternoon getting hgweb.cgi to work, I finally got it to render in the browser using hgweb.cgi and IIS7. I can now see a blank rendering of the web server, that is, a header with no repositories listed.
Now, according to the multipe sites I've read after scouring through Google results, I know that I have to update my hgweb.config file to point to some repositories.
However, for the life of me, I can't get it to list my repository using either the [paths] or [collections] entries.
I have the following directory structure, (simplified but illustrative...):
c:\code
c:\code\htmlwriter
c:\code\CommandLineProjects\Clean
The latter two directories have mercurial repositories in them.
I am trying to publish the repository in c:\code\htmlwriter
Now, if I make this entry in hgweb.config
[paths]
htmlwriter = c:\code\htmlwriter
I get nothing listed in my output.
If I put
[paths]
htmlwriter = c:\code\*
I get something, but not what I want, i.e. this:
htmlwriter/CommandLineProjects/Clean
(Note that the about drills down one directory level farther than I want it to).
I can't seem to find any combination of paths, asterisks, or anything else that will serve up the repository in c:\code\htmlwriter. It appears to always want to go one level deeper than I want it to, or to show nothing.
I know that my hgweb.config file is being read because I can change the style tag in it and it changes what is rendered.
I have read and re-read multiple time a number of resources on the web, but they all say what I'm trying should be working. For instance, I followed this instructions to the letter with no good results:
http://www.jeremyskinner.co.uk/mercurial-on-iis7/
Anyone have any suggestions?
I had about the same luck with hgweb.cgi, and ended up going a different route with wsgi and a "pure python" mercurial install.
I wrote a pretty comprehensive answer here.
I'll answer my own question:
The solution is that the path listed in the [paths] section is relative to the directory where the hgweb.config file is residing.
So, if you have your repository in:
c:\code\myrepo
and your hgweb.config file is in:
C:\inetpub\hgcgi
then the entry in your hgweb.config file needs to be:
/myrepo = ../../code/myrepo
That was the trick -- to put the correct relative path.
I was never able to get hgweb.cgi to work with a repo on a different drive.

Categories