Getting Mercurial in-process hook to run on Windows - windows

I'm trying to get a Mercurial in-process hook to run on Windows.
The problem is not how to write the hook (I want to use an existing one, in this case BugTracker.Net's hook for Mercurial integration - I didn't find a direct link to the file, but you can see it if you download BT.net here, it's in the "mercurial" subfolder).
The problem is how to tell Mercurial to run it.
I spent quite some time to read the documentation, but I'm stuck right now.
(it would probably be easier with a certain knowledge of Python - which I don't have)
I know that I have to insert a line in the hgrc file (in the .hg folder of my repository).
There's an example in the HG Book which looks like this:
[hooks]
commit.example = python:mymodule.submodule.myhook
And there's another example on the Mercurial site, it looks like this:
[hooks]
changegroup = /path/to/changegrouphook
Now I want a "incoming" hook, so at least I know I have to do this:
[hooks]
incoming.btnet = X
The problem is to figure out "X".
The filename is hg_hook_for_btnet.py and in the file, there is a line which looks like this:
def debug_out(s):
I suppose that's the name of the "function" itself.
So my line needs to look something like this:
[hooks]
incoming.btnet = python:hg_hook_for_btnet.debug_out
But this gives me an error message [Errno 2] No such file or directory when I push.
I already tried lots of different variations, but it doesn't work and I don't know what I'm doing wrong.
Do I need python: at the beginning or not?
Do I need to specify the file extension .py or not?
Do I need /path/to/... as indicated in the example from the Mercurial site (see above)?
If yes, what is the correct syntax for the path? (just c:\MyRepo\ doesn't work - syntax must be different in Python)
Also, did I put the hook file into the correct folder?
Right now, it is in the main folder of my repository (on the same level as the .hg folder).
EDIT:
Martin, I changed it into this:
[hooks]
incoming.btnet = python:~c:\HG\MyRepo\hg_hook_for_btnet.py:debug_out
Now I get a different message: [Errno 22] Invalid argument
I suppose this is because of the repo and ui arguments you mentioned.
So, does this mean that the hook script is broken?
(as I said - I don't know anything about Python, this is an existing hook script from an open source bugtracker)
EDIT 2:
Sorry for the confusion regarding in-process and separate process - I know there is a difference, but I assumed that if the hook is written in Python, it must be in-process automatically (turns out I was wrong :-)
Okay, with the syntax in your edited answer, the script at least runs.
I have Python 2.7 installed (already did that before I asked the question here) and changed the first line in the script into #!C:\Python27\python.exe.
Now I get this:
running hook incoming.btnet: c:\HG\MyRepo\hg_hook_for_btnet.py
warning: incoming.btnet hook exited with status 1
So the script runs, but there is still some error.
This seems to be a Bugtracker.NET related problem, so I will ask on the BT.NET mailing list for further advice.
Thank you for your help though, without you I probably wouldn't even have come so far!

You should use
[hooks]
incoming.btnet = python:~/path/to/hg_hook_for_btnet.py:debug_out
and define debug_out as
def debug_out(ui, repo, **kwargs):
# ...
as explained in the HG book -- all hooks are called with a ui and a repo argument plus some extra hook-specific arguments. The Mercurial API page explains what you can do with the ui and a repo arguments.
Edit: Aha... I've now looked at the script. It is not designed to be run as an in-process Mercurial hook. It is instead designed to be run as a separate process. So you will need to use
[hooks]
incoming.btnet = c:\HG\MyRepo\hg_hook_for_btnet.py
and make sure you follow the instructions in the script: it talks about setting the path to the hg.exe binary and to your Python interpreter. The latter means that the author expects you to install Python. There is an email address in the script -- I suggest you contact corey Trager directly or via a BugTracker.NET mailinglist. Since it's a bug tracker, I assume they have a proper place where you can report this! :-)

Related

How to download model from huggingface?

https://huggingface.co/models
For example, I want to download 'bert-base-uncased', but cann't find a 'Download' link. Please help. Or is it not downloadable?
Accepted answer is good, but writing code to download model is not always convenient. It seems git works fine with getting models from huggingface. Here is an example:
git lfs clone https://huggingface.co/sberbank-ai/ruT5-base
where 'lfs' stays for 'large file storage'. Technically this command is deprecated and simple 'git clone' should work, but then you need to setup filters to not skip large files (How do I clone a repository that includes Git LFS files?)
The models are automatically cached locally when you first use it.
So, to download a model, all you have to do is run the code that is provided in the model card (I chose the corresponding model card for bert-base-uncased).
At the top right of the page you can find a button called "Use in Transformers", which even gives you the sample code, showing you how to use it in Python. Again, for bert-base-uncased, this gives you the following code snippet:
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForMaskedLM.from_pretrained("bert-base-uncased")
When you run this code for the first time, you will see a download bar appear on screen. See this post (disclaimer: I gave one of the answers) if you want to find the actual folder where Huggingface stores their models.
I aggre with Jahjajaka's answer. In addition, you can find the git url by clicking the button called "Use in Transformers", shown in the picture.
I typically see if the model has a GitHub repo where I can download the zip file. Due to my company protocols I often cannot directly connect to some sources without getting an SSL certificate error, but I can download from GitHub.
How about using hf_hub_download from huggingface_hub library?
hf_hub_download returns the local path where the model was downloaded so you could hook this one liner with another shell command.
python3 -c 'from huggingface_hub import hf_hub_download; downloaded_model_path = hf_hub_download(
repo_id="CompVis/stable-diffusion-v-1-4-original",
filename="sd-v1-4.ckpt",
use_auth_token=True
); print(downloaded_model_path)'

Ruby / Git library. How to get a full file of a particular check in?

Am working on a script based on git repository. Using ruby's git library.
Having trouble to find the feature to load the full file of a history check in. In git the content can be shown like:
git show 234h23h4j23l4j:path/to/file.java
Just need to know in ruby / git, how do I do that?
Note that this commit (234h23h4j23l4j) does not necessarily have the file I'm looking at.
Or if you know any other git library can easily do this please also recommend. We can still switch, it's not too late.
You can try something like
commit = g.gcommit('1cc8667014381') #to get reference to some commit.
and then explore the commit object you get. (I found some documentation here.)

Is there a safe way to modify another package's entry in the RPM database?

I've run into the problem described in this question, where an old package was Obsoleted, and its %preun script is run with $1 = 0, resulting in undesirable behavior. I know this could be worked around by using -e + -i, as suggested in that answer, or the --nopreun flag, but it's difficult to get that information out to users who are accustomed to simply using -U.
I can't modify the existing %preun scripts in the wild. I don't see any way to run additional code from the new package after the old one's preun. I can't find any way to have my new package programmatically prevent the old %preun script from executing.
Is there any safe way to reach into the RPM database and remove a scriptlet for an existing package?
Jeff Johnson is absolutely correct that it should not be done. However it certainly can be done.
I have done this in an RPM at work, for distribution, but note, this was a contained semi-structured environment with no remote hands to all systems.
If you have remote hands access, take the "remove, install" path, and script that.
If you really feel you should be doing this, then these are the pointers. I'm not going to show you exactly how I did it because it was "work" and not mine to share. The concepts are mine :-)
First, back up the /var/lib/rpm/Packages file (cp /var/lib/rpm/Packages /var/tmp/Packages.bkp). Put it somehwere safe. Update your backup if any one else changes the system whilst you are working on your solution. MAke regular checks on the count of RPMs and test every which way from Sunday, after each change or step.
You will need to use the db_unload and db_load commands. For speed, you will need to use "s2p" to convert any shell sed patterns to perl. Then build a pipe which looks like this:
db_unload /var/tmp/Packages.bkp |perl -i -e "s2p converted string" |db_load /var/tmp/Packages.new
You can then attempt to test the Packages.new by copying ot over the original. Always run rpm --rebuilddb after manual changes. If you see any errors, restore the back up and rebuild the db again.
If you need to put it in an RPM, then convert it to Lua, and put it in the pretrans or posttrans scriptlet (%pretrans -p <lua>). The selection depends on the ordering you are trying to achieve. The Lua interpreter is built in to rpm, and so it will run OK during a new system install even if your RPM gets called somehow. I wrapped my "pipe" in a lua long string, and made it only execute if the system already exists. It does nothing otherwise. If you are thinking "that will never happen" then check out "Never say Never".
BTW you can completely stiff your RPM base and thus future administration of the system if you mess this up. If you do that, and have no backup or way out, it would be a hard way to learn that you are responsible for your own actions. Just saying that you have been warned!
No you cannot edit an rpmdb: the headers are protected
from change by a SHA1 or a digital signature.
Instead upgrade to a fixed version of the package using --nopreun
to prevent running the buggy script let.

PhpStorm: SCSS File Watcher Settings

I need help setting up my SCSS file watcher in PhpStorm. I'm on Ubuntu, I have PhpStorm 6, I have RVM with Ruby 1.9.3p194 and Sass 3.2.5. I've set my File Watcher options in, Settings >> File Watcher as follows:
Once I had done that, I changed something in my .SCSS file but I got this error.
...-1.9.3-p194/bin/sass --no-cache --update style_update.scss:style_update.css
/usr/bin/env: ruby: No such file or directory
(I added three dots at the begin of the first line to make the line shorter) So what might be the problem?
The problem is that IDE is not able to find ruby in the PATH. Note that it may be different in terminal and in applications that you start from Ubuntu launchpad.
Use the Environment variables option in the file watcher configuration to specify custom PATH value with a directory containing the required executables.
A quote from an answer/comment before:
"[...] ... just do what is written, add PATH variable ... [...]"
... That's exactly a common misunderstanding between helping people (who are mostly not teachers), who do the tasks on a daily basis, and asking people on the other hand, who can imagine 3 different things behind standartized answers and their words. Stackoverflow should extend on this, not repeat manuals or documentations.
In PHPstorm for example, you have 2 empty fields after hitting the plus on the right corner of the Enviroment variable settings window. The left field has the header "Variable", the right field the header "Value". So, if somebody is not familiar with PATH and ENVIROMENT variables of desktop or server systems, this person will be slidely confused about what has to be placed in the first field. Is it "ruby"? Is it "PATH"? Wouldn't it override the whole PATH variable of the system? Is it a custom given NAME I can choose and how does the system knows about it? No explanation can be found.
If you don't know the logic behind, you cannot assume the right steps from this standart formulated advice. While I am very excited about the feature set of PHPstorm I find the documentation slidely too standartized and unexplainable. Thats why many entries have bad votes from readers below. Like if somebody would ask: "how do I bake bred?" and the answerer says: "First you have to prepare flour and create dough, then you can bake bred." So what do the asker has learned from this answer? Exactly. Nothing what he didn't knew already before. Ok, maybe the question was not clear enough, but this is also a common case: how to ask correctly if you don't know what you actually ask for? From where can the person know, that there is a need to understand how to set PATH variables? I think this is what differs between makers and teachers. Teachers learn to communicate that gap. Documentation often lacks of better teachers writing it. People who work in the support team should be better in thinking like teachers.
To become more constructive: The documentation of PHPstorm says in its example: "choose PATH_TO_LIB as NAME and the path to the library for the VALUE field." Again: from where does this PATH_TO_LIB comes? Is it an own given Name, or a prepared empty VARIABE name PHPstorm watches? If something wents wrong and you start to look for issues which may cause this and start to worry about wrong settings you are lost on this questions even as an experienced PHP developer.
I generally prefer using tools like guard and RVM based ruby installations ATM over build in watch file solutions like these from PHPstorm, which mostly look for a system wide ruby and such first. But with rvm we have project based paths to ruby and such. RVM prevents breaking the compiling-chain of long term theme or module developments based on certain gem versions. Watch here http://www.youtube.com/watch?v=CmTuvzbPduI where Sebastian Siemssen (well known Drupal developer) explains why this is a good concept. But to nicely implement this with PHPstorm features, you need a better low level entry to path editing in PHPstorm.
Sadly this involves pressing save again, since this needs the save file event to be triggered. I would love to see a better implementation, flexibility and better explanation of how to go with the PHPstorm in-build watchers to have a refresh on edit at hand.

Using SVN for the first time

Not sure if I should be asking here or Server Fault.
Anyhow, I recently started a project at a new job that has SVN installed. I didn't use it even though I was given SSH access with some keygen thing. But now I've done some reading online for beginner's and I'm having a tough time getting past "which svn" after I input a command through SSH. I guess that tells me the path to the repository (which is /usr/bin/svn) but I don't even know how to get to that directory (I'm using Terminal on Mac OS X).
All this makes me feel pretty stupid, since I've never really had to use the terminal to do web projects before and this is my first experience with SVN via SSH (Hell, first time using SSH even).
I have been googling and reading for a weekend now, but I figured someone on here probably has a good idea of where to find the files or to check which are under SVN etc. I think my main problem is finding out how to use the terminal to "get" to the folder I want to be working on.
I did read up on the commands to check if a file is under SVN, check out, update, commit, etc. I would just like to know how to get to these files to do that. Sorry for the noob question and thanks in advance
Bonus points if someone explains the benefits of SSH (I totally understand the benefits of SVN and would love to learn it properly)
You're likely better off using a subversion client. Two of the most popular ones for OS X are http://versionsapp.com and http://zennaware.com/cornerstone/index.php (lately my dev friends seem to like cornerstone more.)
These should let you do all (or nearly all) SVN functions, but by using a GUI. You'll still want to learn the terminology. Take a look at http://svnbook.red-bean.com/en/1.6/svn.basic.html
You want SVN+SSH as it's more secure, but that shouldn't mean you have to use the command line.
Well there is no need to go to the /usr/bin even though svn resides there. /usr/bin is a standard location which is automatically included when the system tries to resolve the location of a file. You should be able to just start using SVN commands like:
svn checkout ...
The benefits of using SVN and SSH are separate questions all together.
svn list --verbose http://host_name/svn_dir will give you a list of the current versioned projects (including revision number and modified date)
svn checkout http://host_name/svn_dir/repository_name projectx will checkout the repo (creating a working copy on your local machine)
I'd recommend the manual here, even if you don't read it to start with and just use it as your first reference point when needed.

Resources