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

add vnu-validator 23.4.11 #24509

Merged
merged 18 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
15 changes: 15 additions & 0 deletions recipes/vnu-validator/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@ECHO ON

cd "%SRC_DIR%"

if not exist "%LIBRARY_LIB%" mkdir "%LIBRARY_LIB%"

copy build\dist\vnu.jar "%LIBRARY_LIB%\vnu.jar" || exit 1

if not exist "%LIBRARY_BIN%" mkdir "%LIBRARY_BIN%"

echo @ECHO OFF > "%LIBRARY_BIN%\vnu.cmd"
echo java -jar "%LIBRARY_LIB%\vnu.jar" %%* >> "%LIBRARY_BIN%\vnu.cmd"
echo IF %%ERRORLEVEL%% NEQ 0 EXIT /B %%ERRORLEVEL%% >> "%LIBRARY_BIN%\vnu.cmd"

type %LIBRARY_BIN%\vnu.cmd
13 changes: 13 additions & 0 deletions recipes/vnu-validator/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eux

mkdir -p "${PREFIX}/lib/"
cp "${SRC_DIR}/build/dist/vnu.jar" "${PREFIX}/lib/"

mkdir -p "${PREFIX}/bin"

echo '#!/usr/bin/env bash' > "${PREFIX}/bin/vnu"
echo 'java -jar "'$PREFIX'/lib/vnu.jar" "$@"' >> "${PREFIX}/bin/vnu"
chmod +x "${PREFIX}/bin/vnu"

cat "${PREFIX}/bin/vnu"
4 changes: 4 additions & 0 deletions recipes/vnu-validator/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
noarch_platform:
- unix # [osx]
- unix # [linux]
- win # [win]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- unix # [osx]
- unix # [linux]
- win # [win]
- linux_64
- win_64

Copy link
Contributor Author

@bollwyvl bollwyvl Dec 4, 2023

Choose a reason for hiding this comment

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

thanks for the review!,

we'll get there over in conda-forge.yml: here, it's being used as the name of __{virtual platform}, as we only want to end up with 2 builds (unix and win).

This is adapted from ipython-feedstock:

Copy link
Member

Choose a reason for hiding this comment

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

That's overly complicated. Here's a simplification of the ipython-feedstock. conda-forge/ipython-feedstock#205

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, tried that locally, getting:

recipes/vnu-validator/ has some lint:
  `noarch` packages can't have selectors. If the selectors are necessary, please remove `noarch: generic`.

37 changes: 37 additions & 0 deletions recipes/vnu-validator/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% set version = "23.4.11" %}

package:
name: vnu-validator
version: {{ version }}

source:
# building from source is... untenable due to sh/py/ant/java/git sandwich
url: https://registry.npmjs.org/vnu-jar/-/vnu-jar-{{ version }}.tgz
sha256: cbba595a86d680d48e9c5261a16d9ef409e5658ad8aa47081c593690a652cf0f

build:
number: 0
noarch: generic

requirements:
run:
- __{{ noarch_platform }}
- openjdk >=8

test:
requires:
- m2-grep # [win]
- python
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved
- pytest

about:
home: https://validator.github.io/validator
license: MIT
# TODO: see if licenses are in jar (unlikely)
license_file: LICENSE
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved
summary: Helps you catch problems in your HTML/CSS/SVG
dev_url: https://github.com/validator/validator

extra:
recipe-maintainers:
- bollwyvl
176 changes: 176 additions & 0 deletions recipes/vnu-validator/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import os
from subprocess import Popen, PIPE
import pytest
import re
import sys
import shutil
import time
import textwrap
import socket
from urllib.request import urlopen
from pathlib import Path

WIN = os.name == "nt"

UTF8 = dict(encoding="utf-8")

BAD_HTML = """
<html/>
"""

GOOD_HTML = """<!DOCTYPE html>
<html lang="en-US">
<head>
<title>hello world</title>
<meta charset="utf-8">
</head>
<body>
<h1>hello world</h1>
</body>
</html>
"""

HTML = {"bad": BAD_HTML, "good": GOOD_HTML}

VNU = shutil.which("vnu") or shutil.which("vnu.cmd")
JAVA = Path(shutil.which("java") or shutil.which("java.exe"))
JAR = Path(sys.prefix) / ("Library/lib" if WIN else "lib") / "vnu.jar"


def test_version():
"""Can it report its version?"""
vnu("--version", expect_stdout=re.escape(os.environ["PKG_VERSION"]))


def test_help():
"""Can it provide help?"""
vnu("--help")


@pytest.mark.parametrize("http", [True, False])
@pytest.mark.parametrize(
"keys,rc,stdout,stderr",
[
("good", 0, r"^$", r"^$"),
("bad", 1, r"^$", r"Start tag seen"),
("bad,good", 1, r"^$", r"Start tag seen"),
],
)
def test_files_cli(
tmp_path: Path,
a_vnu_client_http_args: list[str],
keys: list[str],
rc: int,
stdout: str | None,
stderr: str | None,
http: bool,
):
"""Can it validate?"""
htmls = []
for key in keys.split(","):
html = tmp_path / f"{key}.html"
html.write_text(HTML[key].strip(), **UTF8)
htmls.append(html)

vnu(
*htmls,
expect_rc=rc,
expect_stdout=stdout,
expect_stderr=stderr,
http=http,
http_args=a_vnu_client_http_args,
)


def vnu(
*args,
expect_rc=0,
expect_stdout=None,
expect_stderr=None,
http=False,
http_args=None,
):
"""Run vnu and look for output."""
vnu_args = [str(VNU)]
if http:
vnu_args = http_args
if expect_stderr is not None:
# only writes to stdout
expect_stdout = expect_stderr
expect_stderr = None
str_args = list(map(str, [*vnu_args, *args]))
print("\t".join(str_args))
proc = Popen(str_args, stdout=PIPE, stderr=PIPE, **UTF8)
stdout, stderr = proc.communicate()
proc.wait()
rc = proc.returncode
_indent_some(rc=rc, stdout=stdout, stderr=stderr)
assert rc == expect_rc, f"vnu unexpectedly returned code: {rc}"
if expect_stdout is not None:
assert re.findall(expect_stdout, str(stdout if stdout else "").strip())
if expect_stderr is not None:
assert re.findall(expect_stderr, str(stderr if stderr else "").strip())
return rc, stdout, stderr


@pytest.fixture()
def an_unused_port() -> int:
"""Find an unused network port (could still create race conditions)."""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port


@pytest.fixture()
def a_vnu_client_http_args(an_unused_port: int):
java = [str(JAVA), "-cp", str(JAR)]
host = "127.0.0.1"
server_args = [
*java,
f"-Dnu.validator.servlet.bind-address={host}",
"nu.validator.servlet.Main",
str(an_unused_port),
]
server = Popen(server_args)

retries = 5
started = False
last_error = None

time.sleep(5)

for retry in range(retries):
try:
urlopen(f"http://{host}:{an_unused_port}/", timeout=10)
started = True
break
except Exception as err:
last_error = err
time.sleep(1)
pass

assert started, f"{last_error}"

client_args = [
*java,
f"-Dnu.validator.client.port={an_unused_port}",
f"-Dnu.validator.client.host={host}",
"nu.validator.client.HttpClient",
]

yield client_args
server.terminate()
server.kill()


def _indent_some(**label_text):
for label, text in label_text.items():
print("=" * 8, label, "=" * 8)
print(textwrap.indent(str(text), " " * 8))


if __name__ == "__main__":
pytest.main(["-vv", "--color=yes", __file__])