def package_publish(package, owner, released_at, private, notify): p = PackagePacker(package) archive_path = p.pack() response = RegistryClient().publish_package(archive_path, owner, released_at, private, notify) os.remove(archive_path) click.secho(response.get("message"), fg="green")
def test_source_root(tmpdir_factory): pkg_dir = tmpdir_factory.mktemp("package") root_dir = pkg_dir.mkdir("root") src_dir = root_dir.mkdir("src") src_dir.join("main.cpp").write("#include <stdio.h>") root_dir.join("library.json").write('{"name": "bar", "version": "2.0.0"}') p = PackagePacker(str(pkg_dir)) with tarfile.open(p.pack(str(pkg_dir)), "r:gz") as tar: assert set(tar.getnames()) == set(["library.json", "src/main.cpp"])
def package_publish(package, owner, released_at, private, notify): assert ensure_python3() with tempfile.TemporaryDirectory() as tmp_dir: # pylint: disable=no-member with fs.cd(tmp_dir): p = PackagePacker(package) archive_path = p.pack() response = RegistryClient().publish_package( archive_path, owner, released_at, private, notify ) os.remove(archive_path) click.secho(response.get("message"), fg="green")
def test_filters(tmpdir_factory): pkg_dir = tmpdir_factory.mktemp("package") src_dir = pkg_dir.mkdir("src") src_dir.join("main.cpp").write("#include <stdio.h>") src_dir.mkdir("util").join("helpers.cpp").write("void") pkg_dir.mkdir("include").join("main.h").write("#ifndef") test_dir = pkg_dir.mkdir("tests") test_dir.join("test_1.h").write("") test_dir.join("test_2.h").write("") # test include with remap of root pkg_dir.join("library.json").write( json.dumps(dict(name="bar", version="1.2.3", export={"include": "src"}))) p = PackagePacker(str(pkg_dir)) with tarfile.open(p.pack(str(pkg_dir)), "r:gz") as tar: assert set(tar.getnames()) == set( ["util/helpers.cpp", "main.cpp", "library.json"]) os.unlink(str(src_dir.join("library.json"))) # test include "src" and "include" pkg_dir.join("library.json").write( json.dumps( dict(name="bar", version="1.2.3", export={"include": ["src", "include"]}))) p = PackagePacker(str(pkg_dir)) with tarfile.open(p.pack(str(pkg_dir)), "r:gz") as tar: assert set(tar.getnames()) == set([ "include/main.h", "library.json", "src/main.cpp", "src/util/helpers.cpp" ]) # test include & exclude pkg_dir.join("library.json").write( json.dumps( dict( name="bar", version="1.2.3", export={ "include": ["src", "include"], "exclude": ["*/*.h"] }, ))) p = PackagePacker(str(pkg_dir)) with tarfile.open(p.pack(str(pkg_dir)), "r:gz") as tar: assert set(tar.getnames()) == set( ["library.json", "src/main.cpp", "src/util/helpers.cpp"])
def test_manifest_uri(tmpdir_factory): pkg_dir = tmpdir_factory.mktemp("package") root_dir = pkg_dir.mkdir("root") src_dir = root_dir.mkdir("src") src_dir.join("main.cpp").write("#include <stdio.h>") root_dir.join("library.json").write('{"name": "foo", "version": "1.0.0"}') bar_dir = root_dir.mkdir("library").mkdir("bar") bar_dir.join("library.json").write('{"name": "bar", "version": "2.0.0"}') bar_dir.mkdir("include").join("bar.h").write("") manifest_path = pkg_dir.join("remote_library.json") manifest_path.write( '{"name": "bar", "version": "3.0.0", "export": {"include": "root/library/bar"}}' ) p = PackagePacker(str(pkg_dir), manifest_uri="file:%s" % manifest_path) p.pack(str(pkg_dir)) with tarfile.open(os.path.join(str(pkg_dir), "bar-2.0.0.tar.gz"), "r:gz") as tar: assert set(tar.getnames()) == set(["library.json", "include/bar.h"])
def package_publish(package, owner, released_at, private, notify): assert ensure_python3() # publish .tar.gz instantly without repacking if not os.path.isdir(package) and isinstance( FileUnpacker.new_archiver(package), TARArchiver): response = RegistryClient().publish_package(package, owner, released_at, private, notify) click.secho(response.get("message"), fg="green") return with tempfile.TemporaryDirectory() as tmp_dir: # pylint: disable=no-member with fs.cd(tmp_dir): p = PackagePacker(package) archive_path = p.pack() response = RegistryClient().publish_package( archive_path, owner, released_at, private, notify) os.remove(archive_path) click.secho(response.get("message"), fg="green")
def test_symlinks(tmpdir_factory): # Windows does not support symbolic links if WINDOWS: return pkg_dir = tmpdir_factory.mktemp("package") src_dir = pkg_dir.mkdir("src") src_dir.join("main.cpp").write("#include <stdio.h>") pkg_dir.mkdir("include").join("main.h").write("#ifndef") src_dir.join("main.h").mksymlinkto(os.path.join("..", "include", "main.h")) pkg_dir.join("library.json").write('{"name": "bar", "version": "2.0.0"}') tarball = pkg_dir.join("bar.tar.gz") with tarfile.open(str(tarball), "w:gz") as tar: for item in pkg_dir.listdir(): tar.add(str(item), str(item.relto(pkg_dir))) p = PackagePacker(str(tarball)) assert p.pack(str(pkg_dir)).endswith("bar-2.0.0.tar.gz") with tarfile.open(os.path.join(str(pkg_dir), "bar-2.0.0.tar.gz"), "r:gz") as tar: assert set(tar.getnames()) == set( ["include/main.h", "library.json", "src/main.cpp", "src/main.h"]) m = tar.getmember("src/main.h") assert m.issym()
def test_install_from_url(isolated_pio_core, tmpdir_factory): tmp_dir = tmpdir_factory.mktemp("tmp") storage_dir = tmpdir_factory.mktemp("storage") lm = LibraryPackageManager(str(storage_dir)) # install from local directory src_dir = tmp_dir.join("local-lib-dir").mkdir() src_dir.join("main.cpp").write("") spec = PackageSpec("file://%s" % src_dir) pkg = lm.install(spec, silent=True) assert os.path.isfile(os.path.join(pkg.path, "main.cpp")) manifest = lm.load_manifest(pkg) assert manifest["name"] == "local-lib-dir" assert manifest["version"].startswith("0.0.0+") assert spec == pkg.metadata.spec # install from local archive src_dir = tmp_dir.join("archive-src").mkdir() root_dir = src_dir.mkdir("root") root_dir.mkdir("src").join("main.cpp").write("#include <stdio.h>") root_dir.join("library.json").write( '{"name": "manifest-lib-name", "version": "2.0.0"}' ) tarball_path = PackagePacker(str(src_dir)).pack(str(tmp_dir)) spec = PackageSpec("file://%s" % tarball_path) pkg = lm.install(spec, silent=True) assert os.path.isfile(os.path.join(pkg.path, "src", "main.cpp")) assert pkg == lm.get_package(spec) assert spec == pkg.metadata.spec # install from registry src_dir = tmp_dir.join("registry-1").mkdir() src_dir.join("library.properties").write( """ name = wifilib version = 5.2.7 """ ) spec = PackageSpec("company/wifilib @ ^5") pkg = lm.install_from_url("file://%s" % src_dir, spec) assert str(pkg.metadata.version) == "5.2.7" # check package folder names lm.memcache_reset() assert ["local-lib-dir", "manifest-lib-name", "wifilib"] == [ os.path.basename(pkg.path) for pkg in lm.get_installed() ]
def test_base(tmpdir_factory): pkg_dir = tmpdir_factory.mktemp("package") pkg_dir.join(".git").mkdir().join("file").write("") pkg_dir.join(".gitignore").write("tests") pkg_dir.join("._ignored").write("") pkg_dir.join("main.cpp").write("#include <stdio.h>") p = PackagePacker(str(pkg_dir)) # test missed manifest with pytest.raises(UnknownManifestError): p.pack() # minimal package pkg_dir.join("library.json").write('{"name": "foo", "version": "1.0.0"}') pkg_dir.mkdir("include").join("main.h").write("#ifndef") with fs.cd(str(pkg_dir)): p.pack() with tarfile.open(os.path.join(str(pkg_dir), "foo-1.0.0.tar.gz"), "r:gz") as tar: assert set(tar.getnames()) == set( [".gitignore", "include/main.h", "library.json", "main.cpp"])
def package_pack(package, output): p = PackagePacker(package) archive_path = p.pack(output) click.secho('Wrote a tarball to "%s"' % archive_path, fg="green")
def platform_pack(package): p = PackagePacker(package) tarball_path = p.pack() click.secho('Wrote a tarball to "%s"' % tarball_path, fg="green")