Zulip Chat Archive
Stream: mathlib4
Topic: starting the port of a new file
Johan Commelin (Dec 22 2022 at 18:12):
From mathlib4/scripts/start_port.sh
:
echo "usage: ./scripts/start_port.sh Mathlib/Foo/Bar/Baz.lean"
Johan Commelin (Dec 22 2022 at 18:13):
This will create a new branch named Foo.Bar.Baz
with two commits:
- the output of mathports
Mathbin/Foo/Bar/Baz.lean
- a commit that adds the new file to
Mathlib.lean
and replacesMathbin
byMathlib
in the import lines of the new file.
Kevin Buzzard (Dec 22 2022 at 18:34):
That's so cool that you keep the mathbin commit. I always check for mathbins as it gives me confidence that the commit claimed to be the first commit really is a commit with no edits at all to the mathlib3port file.
Arien Malec (Dec 22 2022 at 18:45):
Is this the preferred approach? Is it documented in the wiki?
Eric Wieser (Dec 22 2022 at 18:59):
Can we make it call the branch port/X.Y.Z
instead?
Eric Wieser (Dec 22 2022 at 19:00):
One day we'll want to have non-port branches too!
Johan Commelin (Dec 22 2022 at 19:00):
Fair enough. I'll update the script.
Johan Commelin (Dec 22 2022 at 19:00):
@Arien Malec yes, I hope this will be adopted as the standard approach.
Johan Commelin (Dec 22 2022 at 19:00):
I'll document it in the wiki.
Mario Carneiro (Dec 22 2022 at 19:01):
well it's pretty weird to have branches named X.Y.Z
otherwise
Mario Carneiro (Dec 22 2022 at 19:01):
they are usually named more like x_y_z
Eric Wieser (Dec 22 2022 at 19:02):
The next cool thing to build would be an update command that commits the latest mathport as a child of commit 1 (1a), then creates 2a as a child of 1 and 2 with the import fixes, then merges head
Eric Wieser (Dec 22 2022 at 19:03):
Mario, that doesn't work well for a_b.c
vs a.b_c
filenames
Eric Wieser (Dec 22 2022 at 19:04):
Git allows dots, so I don't think they're that weird. port/X/Y/Z
would also be nice, as then the folder tree inside git matches the source tree (but this might be illegal for some branch names on windows!)
Johan Commelin (Dec 22 2022 at 19:04):
Eric Wieser said:
Can we make it call the branch
port/X.Y.Z
instead?
Mario Carneiro (Dec 22 2022 at 19:08):
Eric Wieser said:
Mario, that doesn't work well for
a_b.c
vsa.b_c
filenames
We don't have file names like that though?
Mario Carneiro (Dec 22 2022 at 19:08):
and also I don't understand how that is a conflict, those are different names
Reid Barton (Dec 22 2022 at 19:10):
I think Eric was assuming you were suggesting tr . _
Mario Carneiro (Dec 22 2022 at 19:13):
oh, no I meant to just use X.Y.Z
and rely on the fact that most other branch names are named using a different convention to avoid conflicts
Johan Commelin (Dec 22 2022 at 19:13):
I've updated the wiki. (It assumes mathlib4#1170 will be merged at some point.)
zbatt (Dec 28 2022 at 21:28):
I'm having a bit of trouble with this. When I run ./scripts/start_port.sh Mathlib/Data/PNat/Prime.lean
it seems to not work as I get back a file start_port_tmp.lean
with contents 404: Not Found
.
The output of running the command is
+ set -o pipefail
+ MATHLIB3PORT_BASE_URL=https://raw.githubusercontent.com/leanprover-community/mathlib3port/master
+ PORT_STATUS_YAML=https://raw.githubusercontent.com/wiki/leanprover-community/mathlib/mathlib4-port-status.md
+ TMP_FILE=start_port_tmp.lean
+ mathlib4_path=Mathlib/Data/PNat/Prime.lean
+++ echo Mathlib/Data/PNat/Prime.lean
+++ tr / .
++ basename Mathlib.Data.PNat.Prime.lean .lean
+ mathlib4_mod=Mathlib.Data.PNat.Prime
+ mathlib3port_url=https://raw.githubusercontent.com/leanprover-community/mathlib3port/master/Mathbin/Data/PNat/Prime.lean
+ curl --silent --show-error -o start_port_tmp.lean https://raw.githubusercontent.com/leanprover-community/mathlib3port/master/Mathbin/Data/PNat/Prime.lean
++ grep '^! .*source module '
++ sed 's/.*source module \(.*\)$/\1/'
+ mathlib3_module=
Any help would be really appreciated!
zbatt (Dec 28 2022 at 22:06):
I figured it out, there's an inconsistency in the naming schemes for PNat
. In Mathlib4, its given as PNat
, but in mathlib3port
its given as Pnat
which causes the curl
to fail.
Kevin Buzzard (Dec 28 2022 at 22:10):
Oh nice catch!
zbatt (Dec 28 2022 at 22:14):
I feel like the naming inconsistency might make this port a bit delicate, so maybe not suitable for my first one haha. I'll leave it to the experts
Arien Malec (Dec 28 2022 at 23:21):
naming inconsistency is part of the joy of porting, along with autoimplicits, simp
/rw
inconsistencies -- just dive in!
Reid Barton (Dec 29 2022 at 07:24):
Is this Pnat
vs PNat
thing something we can/should inform mathport about?
Johan Commelin (Jan 05 2023 at 10:20):
I just created
chore: start_port.sh makes empty commit with nice PR title #1345
This should give you a nice PR title, when you open a PR.
Eric Wieser (Jan 05 2023 at 10:24):
Eric Wieser (Jan 05 2023 at 10:25):
I don't think this helps?
Eric Wieser (Jan 05 2023 at 10:25):
Doesn't github just use the branch name for the PR title if there is more than one commit?
Johan Commelin (Jan 05 2023 at 10:25):
Nope, it takes the title of the first commit, in that case. I'm pretty sure about that.
Johan Commelin (Jan 05 2023 at 10:30):
Or is that something that hub
does on my end?
Eric Wieser (Jan 05 2023 at 10:32):
That sounds like something hub
does; or github changed this behavior within the last two days; I've not seen this happen before
Anne Baanen (Jan 05 2023 at 10:33):
The web interface indeed tries to parse the branch name, which I find very frustrating :(
Eric Wieser (Jan 05 2023 at 10:34):
For example: https://github.com/leanprover-community/mathlib/compare/eric-wieser/bad-pr-title?expand=1
Johan Commelin (Jan 05 2023 at 10:35):
Aah, I didn't realize it was hub
doing that. Ok. Maybe let's drop the PR in that case.
Yaël Dillies (Jan 05 2023 at 10:37):
It helps if you open PRs from within VScode
Eric Wieser (Jan 05 2023 at 10:37):
Oh, you can set the title in a URL!
Eric Wieser (Jan 05 2023 at 10:37):
Eric Wieser (Jan 05 2023 at 10:38):
So maybe the script can just emit a url to click at the end to open the PR?
Johan Commelin (Jan 05 2023 at 10:39):
Ooh! That sounds like a good idea!
Eric Wieser (Jan 05 2023 at 10:40):
(don't forget to query-string-quote the title! Python's urllib.parse.quote_plus
would do it)
Johan Commelin (Jan 05 2023 at 10:56):
script is in bash
Johan Commelin (Jan 05 2023 at 10:59):
chore: start_port.sh can print a URL to open PR with useful title mathlib4#1346
Johan Commelin (Jan 05 2023 at 10:59):
Should the script also do a git push
?
Eric Wieser (Jan 05 2023 at 11:21):
I think it's fine to do the git push, as long as it:
- Does it silently, so that github doesn't insert it's own url with a bad link
- Catches errors and turns them into an error message like "someone else has already ported this file"
Johan Commelin (Jan 05 2023 at 11:22):
I don't know how to do that off the top of my head.
Eric Wieser (Jan 05 2023 at 11:58):
git push --quiet
is the first. Maybe a better approach for the last is to first check if origin/$mathport_branch
already exists
Eric Rodriguez (Jan 05 2023 at 13:17):
Have people tried the gh
tool? gh pr new
is a really good way to create a PR, in my experience.
Johan Commelin (Jan 06 2023 at 10:00):
gh pr create
is perfect. It also uses the first commit message to create a PR title.
Johan Commelin (Jan 06 2023 at 10:01):
@Eric Wieser What do you think of doing both (i) an empty commit with a nice title at the start of the PR, and (ii) print a URL to open a PR with a nice title
Johan Commelin (Jan 06 2023 at 10:01):
That way we can support both a gh
and non-gh
workflow.
Eric Wieser (Jan 06 2023 at 10:03):
I don't think the empty commit does any harm if it helps with some workflows
Johan Commelin (Jan 06 2023 at 10:06):
I updated the PR
Johan Commelin (Jan 06 2023 at 10:07):
I suggest that the pushing etc be done in another PR.
Arien Malec (Jan 06 2023 at 19:50):
FWIW, my workflow is to first see if the port is possible for me to make meaningful progress on before I push. If I walk into a file and when I compile after fixing Mathlib
I see a see of red that I have no idea how to fix, and I can't make progress on cleanup, I delete the branch and walk slowly away.
Johan Commelin (Jan 19 2023 at 07:36):
In mathlib4#1667 I add two tiny features to the start_port script:
- fix
Smul
andPnat
toSMul
andPNat
in import statements - move
by
to the end of the previous line, when it fits
Johan Commelin (Jan 19 2023 at 07:37):
The second one might need some second touch ups due to later changes to the file, but I still hope it will take care of 90% of the by
issues.
Johan Commelin (Jan 19 2023 at 07:49):
In semi-related news: mathport will now add #align
statements for to_additive
ized decls
Eric Rodriguez (Jan 19 2023 at 18:16):
Johan Commelin said:
In mathlib4#1667 I add two tiny features to the start_port script:
- fix
Smul
andPnat
toSMul
andPNat
in import statements- move
by
to the end of the previous line, when it fits
fwiw, this causes the same issue for mac because awk
doesn't line up on both operating systems - i think the workaround is similar, just worth noting
Johan Commelin (Jan 19 2023 at 18:18):
Good point.
Arien Malec (Jan 19 2023 at 18:34):
The workaround being "install gnu awk via brew"?
Eric Rodriguez (Jan 19 2023 at 18:37):
yes, and add the correct thing to your .zshrc
Arien Malec (Jan 19 2023 at 18:37):
I've taken to adding to /etc/paths
Arien Malec (Jan 19 2023 at 18:49):
Added instructions to the porting guide wiki.
Eric Rodriguez (Jan 19 2023 at 19:02):
Arien Malec said:
Added instructions to the porting guide wiki.
where exactly, sorry? can't find ti
Arien Malec (Jan 19 2023 at 19:09):
Last bullet of 3.
Arien Malec (Jan 19 2023 at 19:09):
Note that on OS X, the OS installed version of sed and awk do not work with the start_port.sh script. The fix is to install the GNU versions (e.g. via brew install gawk gsed) and ensure they, rather than the OS versions, are the default for sed and awk (e.g. by following the path instructions provided by brew)
Last updated: Dec 20 2023 at 11:08 UTC