Skip to content

Commit 433a4d5

Browse files
authored
Remove windows terminal api endpoints (#433)
* Removed Windows Terminal FastAPI endpoints since they are unused * Removed other mentions of Windows Terminal from source code and documentation
1 parent 46ad843 commit 433a4d5

File tree

3 files changed

+0
-289
lines changed

3 files changed

+0
-289
lines changed

src/murfey/server/api/bootstrap.py

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
bootstrap = APIRouter(prefix="/bootstrap", tags=["bootstrap"])
4444
cygwin = APIRouter(prefix="/cygwin", tags=["bootstrap"])
4545
msys2 = APIRouter(prefix="/msys2", tags=["bootstrap"])
46-
windows_terminal = APIRouter(prefix="/microsoft/terminal", tags=["bootstrap"])
4746
pypi = APIRouter(prefix="/pypi", tags=["bootstrap"])
4847
plugins = APIRouter(prefix="/plugins", tags=["bootstrap"])
4948

@@ -565,219 +564,6 @@ def get_msys2_package_file(
565564
raise HTTPException(status_code=package_file.status_code)
566565

567566

568-
"""
569-
=======================================================================================
570-
WINDOWS TERMINAL-RELATED FUNCTIONS AND ENDPOINTS
571-
=======================================================================================
572-
"""
573-
574-
windows_terminal_url = "https://github.com/microsoft/terminal/releases"
575-
576-
577-
def get_number_of_github_pages(url) -> int:
578-
"""
579-
Parses the main GitHub releases page to find the number of pages present in the
580-
repository.
581-
"""
582-
583-
response = requests.get(url)
584-
headers = response.headers
585-
if not headers["content-type"].startswith("text/html"):
586-
raise HTTPException("Unable to parse non-HTML page for page numbers")
587-
588-
# Find the number of pages present in this release
589-
text = response.text
590-
pattern = r'aria-label="Page ([0-9]+)"'
591-
matches = re.findall(pattern, text)
592-
if len(matches) == 0:
593-
raise HTTPException("No page numbers found")
594-
pages = [int(item) for item in matches]
595-
pages.sort(reverse=True)
596-
return pages[0]
597-
598-
599-
@windows_terminal.get("/releases", response_class=Response)
600-
def get_windows_terminal_releases(request: Request):
601-
"""
602-
Returns a list of stable Windows Terminal releases from the GitHub repository.
603-
"""
604-
605-
num_pages = get_number_of_github_pages(windows_terminal_url)
606-
607-
# Get list of release versions
608-
versions: list[str] = []
609-
610-
# RegEx patterns to parse HTML file with
611-
# https://github.com/{owner}/{repo}/releases/expanded_assets/{version} leads to a
612-
# HTML page with the assets for that particular version
613-
release_pattern = (
614-
r'src="' + f"{windows_terminal_url}" + r'/expanded_assets/([v0-9\.]+)"'
615-
)
616-
# Pre-release label follows after link to version tag
617-
prerelease_pattern = (
618-
r'[\s]*<span data-view-component="true" class="f1 text-bold d-inline mr-3"><a href="/microsoft/terminal/releases/tag/([\w\.]+)" data-view-component="true" class="Link--primary Link">[\w\s\.\-]+</a></span>'
619-
r"[\s]*<span>"
620-
r'[\s]*<span data-view-component="true" class="Label Label--warning Label--large v-align-text-bottom d-none d-md-inline-block">Pre-release</span>'
621-
)
622-
# Older packages in the repo are named "Color Tools"; omit them
623-
colortool_pattern = r'<span data-view-component="true" class="f1 text-bold d-inline mr-3"><a href="/microsoft/terminal/releases/tag/([\w\.]+)" data-view-component="true" class="Link--primary Link">Color Tool[\w\s]+</a></span>'
624-
625-
# Iterate through repository pages
626-
for p in range(num_pages):
627-
url = f"{windows_terminal_url}?page={p + 1}"
628-
response = requests.get(url)
629-
headers = response.headers
630-
if not headers["content-type"].startswith("text/html"):
631-
raise HTTPException("Unable to parse non-HTML page for package versions")
632-
text = response.text
633-
634-
# Collect only stable releases
635-
releases = re.findall(release_pattern, text)
636-
prereleases = re.findall(prerelease_pattern, text)
637-
colortool = re.findall(colortool_pattern, text)
638-
stable = set(releases) - (set(prereleases) | set(colortool))
639-
versions.extend(stable)
640-
641-
# Construct HTML document for available versions
642-
html_head = "\n".join(
643-
(
644-
"<!DOCTYPE html>",
645-
"<html>",
646-
"<head>",
647-
" <title>Links to Windows Terminal Versions</title>",
648-
"</head>",
649-
"<body>",
650-
" <h1>Links to Windows Terminal Versions</h1>",
651-
)
652-
)
653-
# Construct hyperlinks
654-
link_list = []
655-
base_url = str(request.base_url).strip("/") # Remove trailing '/'
656-
path = request.url.path.strip("/") # Remove leading '/'
657-
658-
for v in range(len(versions)):
659-
version = versions[v]
660-
hyperlink = f'<a href="{base_url}/{path}/{quote(version, safe="")}">{quote(version, safe="")}</a><br />'
661-
link_list.append(hyperlink)
662-
hyperlinks = "\n".join(link_list)
663-
664-
html_tail = "\n".join(
665-
(
666-
"</body>",
667-
"</html>",
668-
)
669-
)
670-
671-
# Combine
672-
content = "\n".join((html_head, hyperlinks, html_tail))
673-
674-
# Return FastAPI response
675-
return Response(
676-
content=content.encode("utf-8"),
677-
status_code=response.status_code,
678-
media_type="text/html",
679-
)
680-
681-
682-
@windows_terminal.get("/releases/{version}", response_class=Response)
683-
def get_windows_terminal_version_assets(
684-
version: str,
685-
request: Request,
686-
):
687-
"""
688-
Returns a list of packages for the selected version of Windows Terminal.
689-
"""
690-
691-
# Validate inputs
692-
if bool(re.match(r"^[\w\-\.]+$", version)) is False:
693-
raise HTTPException("Invalid version format")
694-
695-
# https://github.com/{owner}/{repo}/releases/expanded_assets/{version}
696-
url = f'{windows_terminal_url}/expanded_assets/{quote(version, safe="")}'
697-
698-
response = requests.get(url)
699-
headers = response.headers
700-
if not headers["content-type"].startswith("text/html"):
701-
raise HTTPException("Unable to parse non-HTML page for page numbers")
702-
text = response.text
703-
704-
# Find hyperlinks
705-
pattern = (
706-
r'href="[/\w\.]+/releases/download/'
707-
+ f'{quote(version, safe="")}'
708-
+ r'/([\w\.\-]+)"'
709-
)
710-
assets = re.findall(pattern, text)
711-
712-
# Construct HTML document for available assets
713-
html_head = "\n".join(
714-
(
715-
"<!DOCTYPE html>",
716-
"<html>",
717-
"<head>",
718-
f' <title>Links to Windows Terminal {quote(version, safe="")} Assets</title>',
719-
"</head>",
720-
"<body>",
721-
f' <h1>Links to Windows Terminal {quote(version, safe="")} Assets</h1>',
722-
)
723-
)
724-
# Construct hyperlinks
725-
link_list = []
726-
base_url = str(request.base_url).strip("/") # Remove trailing '/'
727-
path = request.url.path.strip("/") # Remove leading '/'
728-
729-
for a in range(len(assets)):
730-
asset = assets[a]
731-
hyperlink = f'<a href="{base_url}/{path}/{quote(asset, safe="")}">{quote(asset, safe="")}</a><br />'
732-
link_list.append(hyperlink)
733-
hyperlinks = "\n".join(link_list)
734-
735-
html_tail = "\n".join(
736-
(
737-
"</body>",
738-
"</html>",
739-
)
740-
)
741-
742-
# Combine
743-
content = "\n".join((html_head, hyperlinks, html_tail))
744-
745-
# Return FastAPI response
746-
return Response(
747-
content=content.encode("utf-8"),
748-
status_code=response.status_code,
749-
media_type="text/html",
750-
)
751-
752-
753-
@windows_terminal.get("/releases/{version}/{file_name}", response_class=Response)
754-
def get_windows_terminal_package_file(
755-
version: str,
756-
file_name: str,
757-
):
758-
"""
759-
Returns a package from the GitHub repository.
760-
"""
761-
762-
# Validate version and file names
763-
if bool(re.match(r"^[\w\.\-]+$", version)) is False:
764-
raise HTTPException("Invalid version format")
765-
if bool(re.match(r"^[\w\.\-]+$", file_name)) is False:
766-
raise HTTPException("Invalid file name")
767-
768-
# https://github.com/{owner}/{repo}/releases/download/{version}/{file_name}
769-
url = f'{windows_terminal_url}/download/{quote(version, safe="")}/{quote(file_name, safe="")}'
770-
response = requests.get(url)
771-
if response.status_code == 200:
772-
return Response(
773-
content=response.content,
774-
status_code=response.status_code,
775-
headers=response.headers,
776-
)
777-
else:
778-
raise HTTPException(status_code=response.status_code)
779-
780-
781567
"""
782568
=======================================================================================
783569
PYPI-RELATED FUNCTIONS AND ENDPOINTS

src/murfey/server/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class Settings(BaseSettings):
6565
app.include_router(murfey.server.api.bootstrap.bootstrap)
6666
app.include_router(murfey.server.api.bootstrap.cygwin)
6767
app.include_router(murfey.server.api.bootstrap.msys2)
68-
app.include_router(murfey.server.api.bootstrap.windows_terminal)
6968
app.include_router(murfey.server.api.bootstrap.pypi)
7069
app.include_router(murfey.server.api.bootstrap.plugins)
7170
app.include_router(murfey.server.api.clem.router)

src/murfey/templates/bootstrap.html

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -63,80 +63,6 @@ <h3>Installing MSYS2</h3>
6363
$ pacman -S mingw-w64-x86_64-rust --disable-download-timeout
6464
</pre>
6565

66-
<h3>Installing Windows Terminal</h3>
67-
<p>
68-
There is currently a bug with MSYS2 terminals on Windows 10 that prevents its
69-
user interface from working properly. Our current solution is to use
70-
Microsoft's
71-
<a href="https://github.com/microsoft/terminal">Windows Terminal</a> as a
72-
wrapper for MSYS2.
73-
</p>
74-
<p>
75-
The latest release of Windows Terminal can be downloaded directly from
76-
<a href="https://github.com/microsoft/terminal/releases">GitHub</a>, or
77-
through this <a href="/microsoft/terminal/releases">mirror</a>. This will
78-
download a ZIP file, which can be extracted to a directory of your choosing
79-
and used out of the box.
80-
</p>
81-
<p>
82-
In order to run the UCRT64 environment in Windows Terminal, Windows Terminal
83-
will need to be directed to it by adding a dictionary entry in its settings
84-
JSON file. To do so:
85-
</p>
86-
<ol start="1">
87-
<li>Open Windows Terminal.</li>
88-
<li>
89-
Click on the dropdown arrow to the right of the "new tab" button on the
90-
title bar.
91-
</li>
92-
<li>
93-
Click "Settings" (alternatively, use the "Ctrl + ," keyboard shortcut).
94-
</li>
95-
<li>
96-
On the bottom left corner of the window, click on the "Open JSON file"
97-
option. This will bring up the JSON file managing Windows Terminal's
98-
settings in your default code editor.
99-
</li>
100-
<li>Under "profiles" > "list", Add this dictionary entry for UCRT64:</li>
101-
</ol>
102-
<pre style="font-family: monospace">
103-
"profiles":
104-
{
105-
"defaults": {},
106-
"list":
107-
[
108-
{
109-
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
110-
"hidden": false,
111-
"name": "Windows PowerShell"
112-
},
113-
{
114-
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
115-
"hidden": false,
116-
"name": "Command Prompt"
117-
},
118-
<span style="color: red; font-family: monospace">{
119-
"guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
120-
"name": "UCRT64 / MSYS2",
121-
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64",
122-
"startingDirectory": "C:/msys64/home/%USERNAME%",
123-
"icon": "C:/msys64/ucrt64.ico"
124-
}</span>
125-
]
126-
},
127-
</pre>
128-
<ol start="6">
129-
<li>
130-
Additionally, if you want Windows Terminal to always start using UCRT64, you
131-
can replace the "defaultProfile" key with the "guid" value of UCRT64.
132-
</li>
133-
<li>Save your changes and close.</li>
134-
</ol>
135-
<p>
136-
With these changes, you should now be able to run UCRT64 in the Windows
137-
Terminal.
138-
</p>
139-
14066
<h2>Setting Up Python</h2>
14167
<p>
14268
Once Python and pip are installed in the terminal, you have the option to

0 commit comments

Comments
 (0)