def _register(self, session: requests.Session, url: str) -> requests.Response: """ Register a package to a repository. """ dist = self._poetry.file.parent / "dist" file = dist / "{}-{}.tar.gz".format( self._package.name, normalize_version(self._package.version.text)) if not file.exists(): raise RuntimeError('"{0}" does not exist.'.format(file.name)) data = self.post_data(file) data.update({":action": "submit", "protocol_version": "1"}) data_to_send = self._prepare_data(data) encoder = MultipartEncoder(data_to_send) resp = session.post( url, data=encoder, allow_redirects=False, headers={"Content-Type": encoder.content_type}, ) resp.raise_for_status() return resp
def files(self) -> List[Path]: dist = self._poetry.file.parent / "dist" version = normalize_version(self._package.version.text) wheels = list( dist.glob( f"{escape_name(self._package.pretty_name)}-{escape_version(version)}-*.whl" )) tars = list(dist.glob(f"{self._package.pretty_name}-{version}.tar.gz")) return sorted(wheels + tars)
def from_package(cls, package: "Package") -> "Metadata": from poetry.core.utils.helpers import canonicalize_name from poetry.core.utils.helpers import normalize_version from poetry.core.version.helpers import format_python_constraint meta = cls() meta.name = canonicalize_name(package.name) meta.version = normalize_version(package.version.text) meta.summary = package.description if package.readme: with package.readme.open(encoding="utf-8") as f: meta.description = f.read() meta.keywords = ",".join(package.keywords) meta.home_page = package.homepage or package.repository_url meta.author = package.author_name meta.author_email = package.author_email if package.license: meta.license = package.license.id meta.classifiers = package.all_classifiers # Version 1.2 meta.maintainer = package.maintainer_name meta.maintainer_email = package.maintainer_email # Requires python if package.python_versions != "*": meta.requires_python = format_python_constraint( package.python_constraint) meta.requires_dist = [d.to_pep_508() for d in package.requires] # Version 2.1 if package.readme: if package.readme.suffix == ".rst": meta.description_content_type = "text/x-rst" elif package.readme.suffix in [".md", ".markdown"]: meta.description_content_type = "text/markdown" else: meta.description_content_type = "text/plain" meta.provides_extra = [e for e in package.extras] if package.urls: for name, url in package.urls.items(): if name == "Homepage" and meta.home_page == url: continue meta.project_urls += ("{}, {}".format(name, url), ) return meta
def files(self) -> List[Path]: dist = self._poetry.file.parent / "dist" version = normalize_version(self._package.version.text) wheels = list( dist.glob("{}-{}-*.whl".format( escape_name(self._package.pretty_name), escape_version(version)))) tars = list( dist.glob("{}-{}.tar.gz".format(self._package.pretty_name, version))) return sorted(wheels + tars)
def from_package(cls, package: Package) -> Metadata: from poetry.core.utils.helpers import canonicalize_name from poetry.core.utils.helpers import normalize_version from poetry.core.version.helpers import format_python_constraint meta = cls() meta.name = canonicalize_name(package.name) meta.version = normalize_version(package.version.text) meta.summary = package.description if package.readmes: descriptions = [] for readme in package.readmes: with readme.open(encoding="utf-8") as f: descriptions.append(f.read()) meta.description = "\n".join(descriptions) meta.keywords = ",".join(package.keywords) meta.home_page = package.homepage or package.repository_url meta.author = package.author_name meta.author_email = package.author_email if package.license: meta.license = package.license.id meta.classifiers = tuple(package.all_classifiers) # Version 1.2 meta.maintainer = package.maintainer_name meta.maintainer_email = package.maintainer_email # Requires python if package.python_versions != "*": meta.requires_python = format_python_constraint(package.python_constraint) meta.requires_dist = [d.to_pep_508() for d in package.requires] # Version 2.1 if package.readmes: meta.description_content_type = readme_content_type(package.readmes[0]) meta.provides_extra = list(package.extras) if package.urls: for name, url in package.urls.items(): if name == "Homepage" and meta.home_page == url: continue meta.project_urls += (f"{name}, {url}",) return meta
def handle(self) -> None: version = self.argument("version") if version: version = self.increment_version( self.poetry.package.pretty_version, version ) if self.option("short"): self.line("{}".format(version)) else: self.line( "Bumping version from <b>{}</> to <fg=green>{}</>".format( self.poetry.package.pretty_version, version ) ) content = self.poetry.file.read() poetry_content = content["tool"]["poetry"] poetry_content["version"] = version.text self.poetry.file.write(content) else: if self.option('normalized'): version = normalize_version(self.poetry.package.pretty_version) else: version = self.poetry.package.pretty_version if self.option("short"): self.line("{}".format(version)) else: self.line( "<comment>{}</> <info>{}</>".format( self.poetry.package.name, version ) )
def test_normalize_version(version: str, normalized_version: str) -> None: assert normalize_version(version) == normalized_version