Skip to content
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

Adds Mastodon social network #10

Merged
merged 84 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
222026d
WIP: start on mastodon
jpgoldberg Nov 26, 2023
44ffc0f
git ignore my CV
jpgoldberg Nov 26, 2023
2d315dc
WIP: more mast parsing
jpgoldberg Nov 26, 2023
c4460bd
gitingnor venv stuff
jpgoldberg Nov 26, 2023
513d507
unittest
jpgoldberg Nov 26, 2023
76de600
Needed to build
jpgoldberg Nov 26, 2023
03b97cd
! some tests fail
jpgoldberg Nov 26, 2023
c95625f
\w is not whitespace. Derp
jpgoldberg Nov 27, 2023
125a1bb
Mastodon in connection tests
jpgoldberg Nov 27, 2023
d9e374b
update version tag
sinaatalay Nov 16, 2023
37dc7c8
remove requirements.txt
sinaatalay Nov 16, 2023
830dcf3
fix YYYY date issue (#5)
sinaatalay Nov 16, 2023
c38d293
update CI.yaml
sinaatalay Nov 16, 2023
fc6a3f7
remove spell checking feature
sinaatalay Nov 16, 2023
682bce0
fix escape characters test in test_data_model.py
sinaatalay Nov 16, 2023
17a1122
add more sections
sinaatalay Nov 17, 2023
94d2f56
improve classic theme
sinaatalay Nov 17, 2023
1af54eb
fix the reference latex file
sinaatalay Nov 17, 2023
7a3be88
support markdown_to_latex in more areas
sinaatalay Nov 17, 2023
243f7b4
fix run_rendercv.py
sinaatalay Nov 17, 2023
69ac7fd
update .gitignore
sinaatalay Nov 17, 2023
42ee8d9
add lastpage package
sinaatalay Nov 17, 2023
977a4a5
run latex twice for cross-referencing
sinaatalay Nov 17, 2023
9eb0467
make the highlighted author bold and italic
sinaatalay Nov 17, 2023
5c76e9d
add page numbering
sinaatalay Nov 17, 2023
08b262d
suppress lualatex output
sinaatalay Nov 17, 2023
71a02ab
improve the classic theme
sinaatalay Nov 17, 2023
1df1fdd
update tests
sinaatalay Nov 18, 2023
c9b3b0f
fix tests
sinaatalay Nov 18, 2023
a74cef7
create a reference pdf file
sinaatalay Nov 18, 2023
f19b8b1
fix an encoding bug
sinaatalay Nov 19, 2023
21d6849
allow division of section contents
sinaatalay Nov 19, 2023
6aabf78
don't escape backslashes
sinaatalay Nov 19, 2023
d132d1f
fix tests
sinaatalay Nov 19, 2023
f81bc5b
update starting input file
sinaatalay Nov 19, 2023
45ea956
add text alignment options
sinaatalay Nov 20, 2023
9b7639e
update JSON schema
sinaatalay Nov 20, 2023
85b1c49
update reference files
sinaatalay Nov 20, 2023
215eae9
add header margin options
sinaatalay Nov 22, 2023
b12274a
update README.md
sinaatalay Nov 22, 2023
9cd6f3e
add header_font_size option
sinaatalay Nov 24, 2023
6c5d70e
gitignore CV
jpgoldberg Nov 27, 2023
92caab2
more to ignore
jpgoldberg Nov 27, 2023
c301fbf
TeX rendering knows about Mastodon
jpgoldberg Nov 27, 2023
ea7a143
Disallow _ in domain names
jpgoldberg Nov 27, 2023
5e357f4
stricter mastodon hostname validation
jpgoldberg Nov 27, 2023
0764b39
fix YYYY date issue (#5)
sinaatalay Nov 16, 2023
d360813
remove spell checking feature
sinaatalay Nov 16, 2023
3c44412
fix escape characters test in test_data_model.py
sinaatalay Nov 16, 2023
10e0cc9
add more sections
sinaatalay Nov 17, 2023
6bd9fae
improve classic theme
sinaatalay Nov 17, 2023
ef6df9f
fix the reference latex file
sinaatalay Nov 17, 2023
6116245
support markdown_to_latex in more areas
sinaatalay Nov 17, 2023
05a5089
fix run_rendercv.py
sinaatalay Nov 17, 2023
6f12ffd
update .gitignore
sinaatalay Nov 17, 2023
57a295e
run latex twice for cross-referencing
sinaatalay Nov 17, 2023
0843e33
make the highlighted author bold and italic
sinaatalay Nov 17, 2023
144751f
add page numbering
sinaatalay Nov 17, 2023
72026f7
suppress lualatex output
sinaatalay Nov 17, 2023
e17f25b
improve the classic theme
sinaatalay Nov 17, 2023
4c1ecb7
update tests
sinaatalay Nov 18, 2023
8457bdb
fix tests
sinaatalay Nov 18, 2023
aa8d5e8
fix an encoding bug
sinaatalay Nov 19, 2023
c0bddbc
allow division of section contents
sinaatalay Nov 19, 2023
0c83a37
don't escape backslashes
sinaatalay Nov 19, 2023
237d791
fix tests
sinaatalay Nov 19, 2023
711a9a8
add text alignment options
sinaatalay Nov 20, 2023
ce34076
update reference files
sinaatalay Nov 20, 2023
bd3cb64
add header margin options
sinaatalay Nov 22, 2023
9c3073d
add header_font_size option
sinaatalay Nov 24, 2023
af50c7c
rename Code Documentation to API Reference
sinaatalay Nov 26, 2023
085d222
upload licenses for 3rd party fonts (#7)
sinaatalay Nov 26, 2023
68c1640
don't allow line break between first and last name in publications
sinaatalay Nov 27, 2023
2b7555e
add university_projects field
sinaatalay Nov 27, 2023
a5babe5
Merge branch 'main' into jpg/mastodon
jpgoldberg Nov 27, 2023
161b0d6
Ruff whitespace linting
jpgoldberg Nov 28, 2023
7283c9d
Merge branch 'main' into jpg/mastodon
jpgoldberg Nov 29, 2023
795a98d
Merge branch 'main' into jpg/mastodon
jpgoldberg Dec 3, 2023
08902b7
hostname validity (not domain name)
jpgoldberg Dec 3, 2023
e072721
update CI
sinaatalay Dec 3, 2023
60672db
improve issue templates
sinaatalay Dec 3, 2023
4ac7e75
gitignore some jpgoldberg files
jpgoldberg Dec 7, 2023
b26e232
doc mention mastodon
jpgoldberg Dec 7, 2023
2454cc7
improve data_model tests
sinaatalay Dec 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Create a report to help us improve
title: ''
labels: bug
assignees: sinaatalay

---

**Describe the bug**
Expand Down
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Enhancement
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: sinaatalay
---

A clear and concise description of what you want to happen.
16 changes: 0 additions & 16 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ jobs:
name: coverage
path: .coverage.${{ matrix.python-version }}.${{ matrix.os }}

combine-coverages:
name: Upload coverage report
report-coverage:
if: github.event_name == 'push'
name: Generate a coverage report
needs: [test]
runs-on: ubuntu-latest

Expand Down Expand Up @@ -108,6 +109,7 @@ jobs:
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 50
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}

publish:
if: github.event_name == 'release'
name: Publish to PyPI
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,9 @@ output/

# Personal CVs
Sina_Atalay_CV.yaml
run_sina_atalay_cv.py
run_sina_atalay_cv.py

# Jeffrey Goldbergs local stuff
# We can remove these once work by him is finished
Jeffrey_Paul_Goldberg_CV.yaml
pyvenv.cfg
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ linting = ["black", "ruff"]
requires = ['setuptools>=68.2.2', "setuptools-scm>=8.0.4"]
build-backend = 'setuptools.build_meta'

[tool.setuptools]
packages = ["rendercv"]

[tool.ruff]
line-length = 88

Expand Down
92 changes: 90 additions & 2 deletions rendercv/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,10 +1022,10 @@ def doi_url(self) -> str:
class SocialNetwork(BaseModel):
"""This class stores a social network information.

Currently, only LinkedIn, Github, and Instagram are supported.
Currently, only LinkedIn, Github, Mastodon, and Instagram are supported.
"""

network: Literal["LinkedIn", "GitHub", "Instagram", "Orcid"] = Field(
network: Literal["LinkedIn", "GitHub", "Instagram", "Orcid", "Mastodon"] = Field(
title="Social Network",
description="The social network name.",
)
Expand All @@ -1048,13 +1048,99 @@ class Connection(BaseModel):
"GitHub",
"Instagram",
"Orcid",
"Mastodon",
"phone",
"email",
"website",
"location",
]
value: str

@staticmethod
def is_valid_hostname(hostname: str) -> bool:
"""Is hostname a valid hostname by RFCs 952 and 1123"""

# slightly modified from
# https://stackoverflow.com/a/33214423/1304076
if hostname[-1] == ".":
# strip exactly one dot from the right, if present
hostname = hostname[:-1]
if len(hostname) > 253:
return False

labels = hostname.split(".")

# the last label must be not all-numeric
if re.match(r"[0-9]+$", labels[-1]):
return False

# labels cannot begin with a hyphen
# labels must have at least character
# labels may not have more than 63 characters
allowed = re.compile(r"(?!-)[a-z0-9-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(label) for label in labels)

Comment on lines +1059 to +1082
Copy link
Owner

@sinaatalay sinaatalay Dec 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need to verify Mastodon usernames, we should also verify other networks. Is it necessary to validate usernames? Moreover, if we want to do a validation, we should use the @field_validator decorator of Pydantic. This will help exception handling since we will know it's a validation error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two separate suggestions. The reason that Mastodon needs special validation as opposed to, say, LinkedIn is that we know that know that www.linkedin.com ia syntactically valid hostname. We aren't going to create a malicious PDF by using it.

There may be value in syntactically validating other usernames. But I do think it would be a mistake to actually perform any network calls while running RenderCV. So the validation is only syntactic.

I very much suspect you are correct about @field_validator, but the be perfectly honest, I don't fully grok what Pydantic is doing. However, I am happy to learn. So I will work on this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, (if you haven’t started working on it), we can keep it like this for now because the @field_validator check should be done on the SocialNetwork class since the Connection class is not used by the users directly. But if we move it to SocialNetwork, we will need to do something about other social networks, too. Therefore, we can address this validation problem later. Whatever you prefer.

@staticmethod
def MastodonUname2Url(address: str) -> Optional[HttpUrl]:
"""returns profile url from a mastodon user address.

Args:
address (str): A Mastodon user address. E.g., "[email protected]"

Returns:
A pydantic HttpUrl object with the https URL for the user profile

Example:
```
url = MastodonUname2Url("[email protected]")
assert(url == HttpUrl(http://social.example/@user))
```

Exceptions:
ValueError if the address is malformed.
Note that well-formed addresses should never yield
syntactically invalid URLs.
"""

# The closest thing to a formal spec of Mastodon usernames
# where these regular expressions from a (reference?)
# implementation
#
# https://github.com/mastodon/mastodon/blob/f1657e6d6275384c199956e8872115fdcec600b0/app/models/account.rb#L68
#
# USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
# MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
#
# `[[:word:]]` in Ruby includes lots of things that could never be in a # domain name. As my intent here is to construct an HTTPS URL,
# What we need are valid hostnames,
# and so need to satisfy the constraints of RFC 952 and and 1123.

pattern = re.compile(
r"""
^\s* # ignore leading spaces
@? # Optional @ prefix
(?P<uname>[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?) # username part
@ # separator
(?P<domain>[a-z0-9]+([a-z0-9.-]+)?) # domain part
\s*$ # ignore trailing whitespace
""",
re.VERBOSE | re.IGNORECASE,
)

m = pattern.match(address)
if m is None:
raise ValueError("Invalid mastodon address")
uname = m.group("uname")
domain = m.group("domain")

# the domain part of pattern allows some things that are not
# valid names. So we run a stricter check
if not Connection.is_valid_hostname(domain):
raise ValueError("Invalid hostname in mastodon address")

url = HttpUrl(f"https://{domain}/@{uname}")
return url
Comment on lines +1083 to +1142
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this function being used anywhere other than the url method. Maybe we can move the contents inside the url method for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have different opinions about "clarity", but it is your project, so I will follow your suggestion.


@computed_field
@cached_property
def url(self) -> Optional[HttpUrl | str]:
Expand All @@ -1066,6 +1152,8 @@ def url(self) -> Optional[HttpUrl | str]:
url = f"https://www.instagram.com/{self.value}"
elif self.name == "Orcid":
url = f"https://orcid.org/{self.value}"
elif self.name == "Mastodon":
url = self.MastodonUname2Url(self.value)
elif self.name == "email":
url = f"mailto:{self.value}"
elif self.name == "website":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faOrcid}\hspace{0.13cm}<<username>>}}
((*- endmacro *))

((* macro Mastodon(username, url) -*))
\mbox{\hrefWithoutArrow{<<url>>}{{\small\faMastodon}\hspace{0.13cm}<<username>>}}
((*- endmacro *))

((* macro phone(number, url) -*))
\mbox{\hrefWithoutArrow{<<url|replace("-","")>>}{{\footnotesize\faPhone*}\hspace{0.13cm}<<number|replace("tel:", "")|replace("-"," ")>>}}
((*- endmacro *))
Expand Down
3 changes: 2 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,8 @@
"LinkedIn",
"GitHub",
"Instagram",
"Orcid"
"Orcid",
"Mastodon"
],
"title": "Social Network",
"type": "string"
Expand Down
Loading