From 7cba474290c618448a61685cbcdd637e8bfc2699 Mon Sep 17 00:00:00 2001 From: Easton Wei Date: Sun, 16 Mar 2025 07:20:33 -0400 Subject: [PATCH 1/4] feat(puid): add custom lookup table in config --- von/puid.py | 3 +++ von/rc.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/von/puid.py b/von/puid.py index 20170f0..d2c9116 100644 --- a/von/puid.py +++ b/von/puid.py @@ -1,6 +1,8 @@ import hashlib import re +from rc import VON_CUSTOM_LOOKUP + lookup = { "Afghanistan": "AFG", "Albania": "ALB", @@ -207,6 +209,7 @@ lookup["USAMTS"] = "USMT" lookup["USA GST"] = "USAEST" +lookup.update(VON_CUSTOM_LOOKUP) # whooooo REGEX = r"(?P[a-zA-Z][a-zA-Z0-9 ]+)(19|20)(?P[0-9][0-9])(?P[ \/](?P[0-9A-Za-z\.\/\- ]+))?$" re_generic = re.compile(REGEX) diff --git a/von/rc.py b/von/rc.py index f45dac9..6256e1d 100644 --- a/von/rc.py +++ b/von/rc.py @@ -49,7 +49,15 @@ # Name of text editor to invoke # By default, it detects from $EDITOR automatically -# editor: vim""" +# editor: vim + +# If you would like to define a custom contest name +# (to be used in the PUID script), then you should +# define it here. This will also override any "standard" +# lookups in `puid.py`. (This should be in python dictionary +# format) +# lookups: {"contest-1": "abbreviation-1", "contest-2": "abbreviation-2"} +""" if not CONFIG_DIR.exists(): try: @@ -112,6 +120,11 @@ else: USER_OS = "linux" # including cygwin +if (custom_lookup := config.get("lookup")) is not None: + VON_CUSTOM_LOOKUP = custom_lookup +else: + VON_CUSTOM_LOOKUP = {} + # These used to be editable but I don't think it's worth it VON_INDEX_NAME = "index" VON_INDEX_PATH = os.path.join(VON_BASE_PATH, VON_INDEX_NAME) From 5a2e688f550f9f086d4baceac67d15c44c214796 Mon Sep 17 00:00:00 2001 From: Easton Wei Date: Sun, 16 Mar 2025 07:30:04 -0400 Subject: [PATCH 2/4] feat(rc): fix config call for lookup --- von/rc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/von/rc.py b/von/rc.py index 6256e1d..c6708c5 100644 --- a/von/rc.py +++ b/von/rc.py @@ -56,7 +56,7 @@ # define it here. This will also override any "standard" # lookups in `puid.py`. (This should be in python dictionary # format) -# lookups: {"contest-1": "abbreviation-1", "contest-2": "abbreviation-2"} +# lookup: {"contest-1": "abbreviation-1", "contest-2": "abbreviation-2"} """ if not CONFIG_DIR.exists(): From fa5a2387ff35b4036242d2b829d96735d19d62a5 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 16 Mar 2025 18:46:51 -0400 Subject: [PATCH 3/4] Rename var, etc. --- von/puid.py | 4 ++-- von/rc.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/von/puid.py b/von/puid.py index d2c9116..5599bd9 100644 --- a/von/puid.py +++ b/von/puid.py @@ -1,7 +1,7 @@ import hashlib import re -from rc import VON_CUSTOM_LOOKUP +from rc import VON_CUSTOM_PUID lookup = { "Afghanistan": "AFG", @@ -209,7 +209,7 @@ lookup["USAMTS"] = "USMT" lookup["USA GST"] = "USAEST" -lookup.update(VON_CUSTOM_LOOKUP) +lookup.update(VON_CUSTOM_PUID) # whooooo REGEX = r"(?P[a-zA-Z][a-zA-Z0-9 ]+)(19|20)(?P[0-9][0-9])(?P[ \/](?P[0-9A-Za-z\.\/\- ]+))?$" re_generic = re.compile(REGEX) diff --git a/von/rc.py b/von/rc.py index c6708c5..28bbdc0 100644 --- a/von/rc.py +++ b/von/rc.py @@ -51,12 +51,12 @@ # By default, it detects from $EDITOR automatically # editor: vim -# If you would like to define a custom contest name -# (to be used in the PUID script), then you should -# define it here. This will also override any "standard" -# lookups in `puid.py`. (This should be in python dictionary -# format) -# lookup: {"contest-1": "abbreviation-1", "contest-2": "abbreviation-2"} +# If you would like to define a custom contest name (to be used in the PUID script), +# then you should define it here. +# This will also override any "standard" lookups in `puid.py`. +# abbreviations: +# Inter Galaxy Math Olympiad: IGMO +# Inter Universe Math Olympiad: IUMO """ if not CONFIG_DIR.exists(): @@ -120,10 +120,7 @@ else: USER_OS = "linux" # including cygwin -if (custom_lookup := config.get("lookup")) is not None: - VON_CUSTOM_LOOKUP = custom_lookup -else: - VON_CUSTOM_LOOKUP = {} +VON_CUSTOM_PUID = config.get("abbreviations", {}) # These used to be editable but I don't think it's worth it VON_INDEX_NAME = "index" From 00620ae5199d46dab04ea4696f1d8acc0ab99efd Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 16 Mar 2025 18:48:11 -0400 Subject: [PATCH 4/4] ehh actually lookup is fine --- von/puid.py | 4 ++-- von/rc.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/von/puid.py b/von/puid.py index 5599bd9..d2c9116 100644 --- a/von/puid.py +++ b/von/puid.py @@ -1,7 +1,7 @@ import hashlib import re -from rc import VON_CUSTOM_PUID +from rc import VON_CUSTOM_LOOKUP lookup = { "Afghanistan": "AFG", @@ -209,7 +209,7 @@ lookup["USAMTS"] = "USMT" lookup["USA GST"] = "USAEST" -lookup.update(VON_CUSTOM_PUID) +lookup.update(VON_CUSTOM_LOOKUP) # whooooo REGEX = r"(?P[a-zA-Z][a-zA-Z0-9 ]+)(19|20)(?P[0-9][0-9])(?P[ \/](?P[0-9A-Za-z\.\/\- ]+))?$" re_generic = re.compile(REGEX) diff --git a/von/rc.py b/von/rc.py index 28bbdc0..4c3560b 100644 --- a/von/rc.py +++ b/von/rc.py @@ -120,7 +120,7 @@ else: USER_OS = "linux" # including cygwin -VON_CUSTOM_PUID = config.get("abbreviations", {}) +VON_CUSTOM_LOOKUP = config.get("abbreviations", {}) # These used to be editable but I don't think it's worth it VON_INDEX_NAME = "index"