gemspec.py: support Gemspec files in addition to Gems
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cd5f76126a
commit
9e3473f38a
|
@ -0,0 +1,29 @@
|
|||
1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers.
|
||||
|
||||
2. You may modify your copy of the software in any way, provided that you do at least ONE of the following:
|
||||
|
||||
a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software.
|
||||
|
||||
b) use the modified software only within your corporation or organization.
|
||||
|
||||
c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution.
|
||||
|
||||
d) make other distribution arrangements with the author.
|
||||
|
||||
3. You may distribute the software in object code or binary form, provided that you do at least ONE of the following:
|
||||
|
||||
a) distribute the binaries and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution.
|
||||
|
||||
b) accompany the distribution with the machine-readable source of the software.
|
||||
|
||||
c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution.
|
||||
|
||||
d) make other distribution arrangements with the author.
|
||||
|
||||
4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under these terms.
|
||||
|
||||
For the list of those files and their copying conditions, see the file LEGAL.
|
||||
|
||||
5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software.
|
||||
|
||||
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
@ -5,10 +5,11 @@
|
|||
Release Notes
|
||||
=============
|
||||
|
||||
0.4.2
|
||||
1.0.0
|
||||
-----
|
||||
|
||||
* Fix metadata schema violation for URLs with whitespace in them
|
||||
* [Ruby Gem] Support extracting metadata from Gemspec files, not just Gems
|
||||
|
||||
0.4.1
|
||||
-----
|
||||
|
|
|
@ -3,16 +3,19 @@
|
|||
# No warranty
|
||||
|
||||
"""
|
||||
Metadata XML generator for Crystal Shards.
|
||||
Metadata XML generator for Ruby Gems.
|
||||
|
||||
The following attributes are supported:
|
||||
|
||||
* Upstream maintainer(s)
|
||||
* Upstream bug tracker
|
||||
* Upstream changelog
|
||||
* Upstream documentation
|
||||
* Remote ID
|
||||
"""
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from gentle.generators import AbstractGenerator
|
||||
|
@ -47,12 +50,27 @@ logger = logging.getLogger("gemspec")
|
|||
|
||||
class GemspecGenerator(AbstractGenerator):
|
||||
def __init__(self, srcdir: Path):
|
||||
self.srcdir = srcdir
|
||||
|
||||
self.gemspec_files = list(srcdir.glob("*.gemspec"))
|
||||
self.metadata_yml = srcdir / "all" / "metadata"
|
||||
|
||||
self.ruby = shutil.which("ruby")
|
||||
|
||||
def update_metadata_xml(self, mxml: MetadataXML) -> None:
|
||||
with open(self.metadata_yml) as file:
|
||||
if (metadata := yaml.load(file, Loader)) is None:
|
||||
return
|
||||
if self.metadata_yml.is_file():
|
||||
with open(self.metadata_yml, "rb") as file:
|
||||
data = file.read()
|
||||
else:
|
||||
gemspec = self.gemspec_files[0]
|
||||
code = f'print Gem::Specification.load("{gemspec}").to_yaml'
|
||||
data = subprocess.run([str(self.ruby), "-e", code],
|
||||
cwd=self.srcdir,
|
||||
check=False,
|
||||
capture_output=True).stdout
|
||||
|
||||
if (metadata := yaml.load(data, Loader)) is None:
|
||||
return
|
||||
|
||||
if metadata.homepage:
|
||||
logger.info("Found homepage: %s", metadata.homepage)
|
||||
|
@ -77,4 +95,13 @@ class GemspecGenerator(AbstractGenerator):
|
|||
|
||||
@property
|
||||
def active(self) -> bool:
|
||||
return _HAS_PYYAML and self.metadata_yml.is_file()
|
||||
return (
|
||||
_HAS_PYYAML
|
||||
and (
|
||||
self.metadata_yml.is_file()
|
||||
or (
|
||||
len(self.gemspec_files) == 1
|
||||
and self.ruby is not None
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -13,10 +13,13 @@ from gentle.pms.portagepm import parse_mxml
|
|||
def pytest_addoption(parser):
|
||||
parser.addoption("--with-perl", action="store_true",
|
||||
help="run tests that require Perl")
|
||||
parser.addoption("--with-ruby", action="store_true",
|
||||
help="run tests that require Ruby")
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line("markers", "perl: mark test as using Perl")
|
||||
config.addinivalue_line("markers", "ruby: mark test as using Ruby")
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
|
@ -26,6 +29,12 @@ def pytest_collection_modifyitems(config, items):
|
|||
if "perl" in item.keywords:
|
||||
item.add_marker(skip_perl)
|
||||
|
||||
if not config.getoption("--with-ruby"):
|
||||
skip_perl = pytest.mark.skip(reason="need --with-ruby option to run")
|
||||
for item in items:
|
||||
if "ruby" in item.keywords:
|
||||
item.add_marker(skip_perl)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mxml() -> MetadataXML:
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<pkgmetadata>
|
||||
<!-- maintainer-needed -->
|
||||
<upstream>
|
||||
<remote-id type="github">rubygems/rubygems</remote-id>
|
||||
</upstream>
|
||||
</pkgmetadata>
|
|
@ -0,0 +1,3 @@
|
|||
SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
|
||||
|
||||
SPDX-License-Identifier: CC0-1.0
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "rubygems-update"
|
||||
s.version = "3.6.0.dev"
|
||||
s.authors = ["Jim Weirich", "Chad Fowler", "Eric Hodel", "Luis Lavena", "Aaron Patterson", "Samuel Giddins", "André Arko", "Evan Phoenix", "Hiroshi SHIBATA"]
|
||||
s.email = ["", "", "drbrain@segment7.net", "luislavena@gmail.com", "aaron@tenderlovemaking.com", "segiddins@segiddins.me", "andre@arko.net", "evan@phx.io", "hsbt@ruby-lang.org"]
|
||||
|
||||
s.summary = "RubyGems is a package management framework for Ruby. This gem is downloaded and installed by `gem update --system`, so that the `gem` CLI can update itself."
|
||||
s.description = "A package (also known as a library) contains a set of functionality
|
||||
that can be invoked by a Ruby program, such as reading and parsing an XML file. We call
|
||||
these packages 'gems' and RubyGems is a tool to install, create, manage and load these
|
||||
packages in your Ruby environment. RubyGems is also a client for RubyGems.org, a public
|
||||
repository of Gems that allows you to publish a Gem that can be shared and used by other
|
||||
developers. See our guide on publishing a Gem at guides.rubygems.org"
|
||||
s.homepage = "https://guides.rubygems.org"
|
||||
s.metadata = { "source_code_uri" => "https://github.com/rubygems/rubygems" }
|
||||
s.licenses = ["Ruby", "MIT"]
|
||||
|
||||
s.bindir = "exe"
|
||||
s.executables = ["update_rubygems"]
|
||||
s.require_paths = ["hide_lib_for_update"]
|
||||
s.rdoc_options = ["--main", "README.md", "--title=RubyGems Update Documentation"]
|
||||
s.extra_rdoc_files = [
|
||||
"LICENSE.txt", "MAINTAINERS.txt",
|
||||
"MIT.txt", "Manifest.txt", "README.md",
|
||||
"UPGRADING.md", "POLICIES.md", "CODE_OF_CONDUCT.md",
|
||||
"CONTRIBUTING.md",
|
||||
"bundler/LICENSE.md", "bundler/README.md",
|
||||
"hide_lib_for_update/note.txt", *Dir["bundler/lib/bundler/man/*.1", base: __dir__]
|
||||
]
|
||||
|
||||
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0")
|
||||
|
||||
s.specification_version = 4
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
SPDX-FileCopyrightText: 2024 Rubygems Authors
|
||||
|
||||
SPDX-License-Identifier: Ruby AND MIT
|
|
@ -38,3 +38,30 @@ def test_pkg(mxml: MetadataXML, dirname: str):
|
|||
mxml_prev = deepcopy(mxml)
|
||||
gen.update_metadata_xml(mxml)
|
||||
assert compare_mxml(mxml_prev, mxml) == ""
|
||||
|
||||
|
||||
@pytest.mark.ruby
|
||||
def test_pkg_spec_empty(mxml: MetadataXML):
|
||||
gen = GemspecGenerator(Path(__file__).parent / "pkg_spec" / "pkg_empty")
|
||||
assert gen.active
|
||||
|
||||
mxml_old = deepcopy(mxml)
|
||||
gen.update_metadata_xml(mxml)
|
||||
assert compare_mxml(mxml_old, mxml) == ""
|
||||
|
||||
|
||||
@pytest.mark.ruby
|
||||
@pytest.mark.parametrize("dirname", ["rubygems"])
|
||||
def test_pkg_spec(mxml: MetadataXML, dirname: str):
|
||||
directory = Path(__file__).parent / "pkg_spec" / dirname
|
||||
|
||||
gen = GemspecGenerator(directory)
|
||||
assert gen.active
|
||||
|
||||
gen.update_metadata_xml(mxml)
|
||||
with open(directory / "metadata.xml") as file:
|
||||
assert mxml.dumps() == file.read().rstrip()
|
||||
|
||||
mxml_prev = deepcopy(mxml)
|
||||
gen.update_metadata_xml(mxml)
|
||||
assert compare_mxml(mxml_prev, mxml) == ""
|
||||
|
|
Loading…
Reference in New Issue