Skip to content

Commit

Permalink
Merge branch 'main' into transformer-hyphen-help
Browse files Browse the repository at this point in the history
  • Loading branch information
Heather Li authored and GitHub Enterprise committed Jun 23, 2023
2 parents e5266ae + df97e5c commit f00983a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 35 deletions.
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# fme-packager changes

# 1.4.2
# 1.4.4

* Improve help validation for packages with hyphenated UIDs.

# 1.4.1
# 1.4.3

* Improve verify command

# 1.4.2

* Improve help validation for packages containing formats.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Available templates:

* `transformer`: [Transformer template for FME Packages](https://github.com/safesoftware/fpkg-transformer-template)

_These templates are not currently bundled with fme-packager.
_These templates are not currently bundled with fme-packager._


## Make an fpkg distribution
Expand Down
2 changes: 1 addition & 1 deletion fme_packager/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.2"
__version__ = "1.4.4"
2 changes: 1 addition & 1 deletion fme_packager/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_formatinfo(package_metadata, format_metadata, db_path):
for line in inf:
if line.startswith(";"):
continue # comment line.
formatinfo = parse_formatinfo(db_path)
formatinfo = parse_formatinfo(line)
if formatinfo.FORMAT_NAME == fqname:
return formatinfo

Expand Down
10 changes: 0 additions & 10 deletions fme_packager/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ def _unzip_and_build(self):
steps.build()
steps.make_fpkg()

# Verify package file name is the same
if not os.path.exists(pathlib.Path(temp_dir) / "dist" / os.path.basename(self.file)):
raise ValueError(
"The file name is invalid. Expected {}".format(
build_fpkg_filename(
steps.metadata.publisher_uid, steps.metadata.uid, steps.metadata.version
)
)
)

def _print(self, msg):
if self.verbose:
print(msg)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
License :: OSI Approved :: BSD License
Intended Audience :: Developers

Expand Down Expand Up @@ -43,6 +44,7 @@ dev =
black
tox
twine
urllib3<2

[options.entry_points]
console_scripts =
Expand Down
68 changes: 67 additions & 1 deletion tests/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
TransformerPythonCompatError,
CustomTransformerPythonCompatError,
)
from fme_packager.metadata import TransformerMetadata
from fme_packager.metadata import TransformerMetadata, FormatMetadata, FMEPackageMetadata
from fme_packager.operations import parse_formatinfo
from fme_packager.packager import (
FMEPackager,
is_valid_python_compatibility,
get_formatinfo,
get_format_visibility,
)


Expand All @@ -38,6 +41,69 @@ def test_is_valid_python_compatibility(version, expected_is_valid):
assert is_valid_python_compatibility(version) == expected_is_valid


def test_get_formatinfo(tmp_path):
package_metadata = FMEPackageMetadata(
{
"uid": "package",
"publisher_uid": "example",
"package_content": {"formats": [{"name": "myformat"}]},
}
)
format_metadata = FormatMetadata({"name": "myformat"})

with pytest.raises(ValueError):
filepath = tmp_path / "emptyformat.db"
with open(filepath, "w") as f:
f.write(";")
get_formatinfo(package_metadata, format_metadata, filepath)

with pytest.raises(ValueError):
filepath = tmp_path / "formatnotfound.db"
with open(filepath, "w") as f:
f.write(
"SAFE.CKAN.CKANDATASTORE|CKAN DataStore|NONE|BOTH|NONE|NO||NON_SPATIAL|NO|YES|YES|YES|3|3|CKAN|NO|CKAN"
)
get_formatinfo(package_metadata, format_metadata, filepath)

filepath = tmp_path / "myformat.db"
with open(filepath, "w") as f:
f.writelines(
"EXAMPLE.PACKAGE.MYFORMAT|My Format|NONE|BOTH|NONE|NO||NON_SPATIAL|NO|YES|YES|YES|3|3|MYFORMAT|NO|MYFORMAT\n"
+ "EXAMPLE.PACKAGE.NOTMYFORMAT|Not My Format|NONE|BOTH|NONE|NO||NON_SPATIAL|NO|YES|YES|YES|3|3|MYFORMAT|NO|MYFORMAT"
)

formatinfo = get_formatinfo(package_metadata, format_metadata, filepath)
assert formatinfo.FORMAT_NAME == "EXAMPLE.PACKAGE.MYFORMAT"


def test_get_format_visibility():
base_formatinfo = parse_formatinfo(
"EXAMPLE.PACKAGE.MYFORMAT|My Format|NONE|BOTH|NONE|NO||NON_SPATIAL|NO|YES|YES|YES|3|3|MYFORMAT|NO|MYFORMAT"
)

assert get_format_visibility(base_formatinfo._replace(DIRECTION="BOTH", VISIBLE="NO")) == ""
assert get_format_visibility(base_formatinfo._replace(DIRECTION="BOTH", VISIBLE="YES")) == "rw"

assert get_format_visibility(base_formatinfo._replace(DIRECTION="BOTH", VISIBLE="INPUT")) == "r"
for visibility in ["YES", "INPUT"]:
assert (
get_format_visibility(base_formatinfo._replace(DIRECTION="INPUT", VISIBLE=visibility))
== "r"
)

assert (
get_format_visibility(base_formatinfo._replace(DIRECTION="BOTH", VISIBLE="OUTPUT")) == "w"
)
for visibility in ["YES", "OUTPUT"]:
assert (
get_format_visibility(base_formatinfo._replace(DIRECTION="OUTPUT", VISIBLE=visibility))
== "w"
)

with pytest.raises(ValueError):
assert get_format_visibility(base_formatinfo._replace(DIRECTION="INPUT", VISIBLE="OUTPUT"))


@pytest.mark.parametrize(
"transformer_path,metadata,expected_exc",
[
Expand Down
19 changes: 0 additions & 19 deletions tests/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,3 @@ def test_verify_non_existant():
runner = CliRunner()
result = runner.invoke(verify, [str(CWD / "fixtures" / "does-not-exist.fpkg")])
assert "The file must exist and have a .fpkg extension" in result.output


@pytest.mark.parametrize("flags", [[], ["--json"]])
def test_verify_wrong_filename(flags):
runner = CliRunner()
result = runner.invoke(
verify,
[
str(CWD / "fixtures" / "fpkgs" / "example.my-package-changed-filename-0.1.0.fpkg"),
*flags,
],
)
if "--json" in flags:
assert (
'{"status": "error", "message": "The file name is invalid. Expected example.my-package-0.1.0.fpkg"}'
in result.output
)
else:
assert "The file name is invalid. Expected example.my-package-0.1.0.fpkg" in result.output

0 comments on commit f00983a

Please sign in to comment.