-
-
Notifications
You must be signed in to change notification settings - Fork 269
Remove pymc.*
and pymc3.*
tags from left bar on website
#374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, they all need to be removed. I am not sure about a PR removing them all at once, there are many notebooks with open PRs to update them to v4. Creating git conflicts for this seems too much trouble for what willbe getting fixed. I'd suggest reviewing all open PRs to make sure if they are editing a notebook with those tags they get removed and a PR removing them for those without open PRs |
Have been through all open PR's and requested removal of those tags. I will try to find time for more thorough reviews to help push them along. |
We could probably write a small script to do them all. |
New at this, but nearly there import os
import codecs
import re
from copy import copy
path = "examples"
exclude_directories = set(['.ipynb_checkpoints'])
filelist = []
for root, dirs, files in os.walk(path):
dirs[:] = [d for d in dirs if d not in exclude_directories]
for file in files:
file_extension = os.path.splitext(file)[1]
if file_extension == ".ipynb":
filelist.append(os.path.join(root,file))
for file in filelist:
print(f"\n{file}")
target = None
# read file
f = codecs.open(file, 'r')
source = f.read()
# extract tags text
target = re.findall(r'":tags:(.+?)\\n', source)
if len(target) == 0:
print("\tno tags found")
continue
target = target[0] + ","
print(f"\tTAGS FOUND: {target}")
# extract tags to remove
kill_these = re.findall(r'(pymc)(.+?,)', target)
kill_these = [''.join(tups) for tups in kill_these]
if len(kill_these) == 0:
print("\tno changes to be made")
continue
print(f"\tTAGS TO REMOVE: {kill_these}")
new = copy(target)
for to_kill in kill_these:
new = new.replace(to_kill, "")
print(f"\t REPLACE WITH: {new}")
# replace
source = source.replace(target[:-1], new)
print(source[:500])
# TODO: write to file here |
So this seems like a better approach, and that it should work. import json
import os
path = "examples"
exclude_directories = set(['.ipynb_checkpoints'])
filelist = []
for root, dirs, files in os.walk(path):
dirs[:] = [d for d in dirs if d not in exclude_directories]
for file in files:
file_extension = os.path.splitext(file)[1]
if file_extension == ".ipynb":
filelist.append(os.path.join(root,file))
for file in filelist:
with open(file, 'r+') as openfile:
json_object = json.load(openfile)
for i, string in enumerate(json_object['cells'][0]['source']):
if string.startswith(":tags:"):
elements = string.split()
filtered_elements = [token for token in elements if not token.startswith('pymc')]
new = " ".join(filtered_elements)
# update the dictionary
json_object['cells'][0]['source'][i] = new
# write out to disk
json.dump(json_object, openfile)
# end the iteration
break But the resulting
Any ideas what's going on here? |
Can you post a few lines of before/after JSON? Just a rough guess, but from looking at the code this could be a lot easier to do with RegEx via Otherwise, if the JSON looks fine visually, double check the encoding. Jupyter is a little picky about that. |
start
end
|
Quite possibly, but I'm not that experienced with regular expressions.
Will take a look |
It might be enough to do If you open the project with VS Code, you could even do this with the Find & Replace across all files (Ctrl+Shift+H). If you want to continue the programmatic route, maybe unindent your |
The formatting and the end of the file seems messed up. Problem seems to happen even if you just write the file with zero changes to it. |
But then it's definitely an encoding issue. VS Code shows the encoding in the bottom right corner. pymc-examples/scripts/rerun.py Lines 52 to 58 in c323de9
|
Well we want to remove the whole tag, not just the
That definitely helps. Although I think the issue is something fundamental with writing to the file... if I comment out any changes so you just read and write the file then the problem stays the same |
Got it. The file read/write pattern used in import json
import os
path = "examples"
exclude_directories = set(['.ipynb_checkpoints'])
filelist = []
for root, dirs, files in os.walk(path):
dirs[:] = [d for d in dirs if d not in exclude_directories]
for file in files:
file_extension = os.path.splitext(file)[1]
if file_extension == ".ipynb":
filelist.append(os.path.join(root,file))
for filename in filelist:
with open(filename, "r", encoding="utf-8") as file:
lines = file.read()
json_object = json.loads(lines)
made_changes = False
for i, string in enumerate(json_object['cells'][0]['source']):
if string.startswith(":tags:"):
elements = string.split()
filtered_elements = [token for token in elements if not token.startswith('pymc')]
new = " ".join(filtered_elements)
# update the dictionary
json_object['cells'][0]['source'][i] = new
made_changes = True
break
if made_changes:
json_string = json.dumps(json_object, indent=2)
with open(filename, "w", encoding="utf-8") as file:
file.write(json_string) |
This is mostly done. All we need to do now is ensure all pull requests remove any |
Do we have agreement that removing these tags from the left of the site is a good idea?

If so, would that be done with a PR which manually removes all such tags from all example notebooks? Or would it be done by some clever filtering web code in https://github.com/pymc-devs/pymc.io ?
If it's the former then I can probably do that. If it's the latter than I can't, or would need some help.
The text was updated successfully, but these errors were encountered: