Skip to content

Commit

Permalink
add sampleproject reference for pure pyproject.toml package
Browse files Browse the repository at this point in the history
  • Loading branch information
bnavigator authored and mcepl committed May 22, 2023
1 parent 1aa9ac9 commit ec88b82
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 12 deletions.
15 changes: 12 additions & 3 deletions py2pack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,15 @@ def _canonicalize_setup_data(data):
console_scripts += list(get_pyproject_table(data, "project.gui-scripts", notfound={}).keys())
console_scripts += list(get_pyproject_table(data, "tool.flit.scripts", notfound={}).keys())
if console_scripts:
data["console_scripts"] = console_scripts

homepage = get_pyproject_table(data, 'project.urls.homepage') or data.get('home_page', None)
# remove duplicates, preserver order
data["console_scripts"] = list(dict.fromkeys(console_scripts))

# Standards says, that keys must be lowercase but not even PyPA adheres to it
homepage = (get_pyproject_table(data, 'project.urls.homepage') or
get_pyproject_table(data, 'project.urls.Homepage') or
get_pyproject_table(data, 'project.urls.Source') or
get_pyproject_table(data, 'project.urls.GitHub') or
data.get('home_page', None))
if homepage:
data['home_page'] = homepage

Expand All @@ -210,6 +216,9 @@ def _augment_data_from_tarball(args, filename, data):
license_re = re.compile(r"{0}-{1}\/((?:COPYING|LICENSE).*)".format(args.name, args.version), re.IGNORECASE)

data_pyproject = parse_pyproject(filename)
if data_pyproject is not None and "license" in data and data["license"] in SDPX_LICENSES:
# Trust the PyPI Metadata and don't try to update with a possible non SPDX identifier
data_pyproject.pop("license", None)
data.update(data_pyproject)

try:
Expand Down
86 changes: 86 additions & 0 deletions test/examples/sampleproject-opensuse-augmented.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# spec file for package python-sampleproject
#
# Copyright (c) __YEAR__ SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name: python-sampleproject
Version: 3.0.0
Release: 0
Summary: A sample Python project
License: Copyright (c) 2016 The Python Packaging Authority (PyPA)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
(FIXME:No SPDX)
URL: https://github.com/pypa/sampleproject
Source: https://files.pythonhosted.org/packages/source/s/sampleproject/sampleproject-%{version}.tar.gz
BuildRequires: python-rpm-macros
BuildRequires: %{python_module pip}
BuildRequires: %{python_module setuptools >= 43.0.0}
BuildRequires: %{python_module wheel}
# SECTION test requirements
BuildRequires: %{python_module peppercorn}
BuildRequires: %{python_module coverage}
# /SECTION
BuildRequires: fdupes
Requires: python-peppercorn
Suggests: python-check-manifest
BuildArch: noarch
%python_subpackages

%description
A sample Python project

%prep
%autosetup -p1 -n sampleproject-%{version}

%build
%pyproject_wheel

%install
%pyproject_install
%python_clone -a %{buildroot}%{_bindir}/sample
%python_expand %fdupes %{buildroot}%{$python_sitelib}

%post
%python_install_alternative sample

%postun
%python_uninstall_alternative sample

%files %{python_files}
%doc README.md
%license LICENSE.txt
%python_alternative %{_bindir}/sample
%{python_sitelib}/sampleproject
%{python_sitelib}/sampleproject-%{version}.dist-info

%changelog
88 changes: 88 additions & 0 deletions test/examples/sampleproject-opensuse.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# spec file for package python-sampleproject
#
# Copyright (c) __YEAR__ SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name: python-sampleproject
Version: 3.0.0
Release: 0
Summary: A sample Python project
License: Copyright (c) 2016 The Python Packaging Authority (PyPA) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (FIXME:No SPDX)
URL:
Source: https://files.pythonhosted.org/packages/source/s/sampleproject/sampleproject-%{version}.tar.gz
BuildRequires: python-rpm-macros
BuildRequires: %{python_module pip}
BuildRequires: fdupes
BuildArch: noarch
%python_subpackages

%description
# A sample Python project

![Python Logo](https://www.python.org/static/community_logos/python-logo.png "Sample inline image")

A sample project that exists as an aid to the [Python Packaging User
Guide][packaging guide]'s [Tutorial on Packaging and Distributing
Projects][distribution tutorial].

This project does not aim to cover best practices for Python project
development as a whole. For example, it does not provide guidance or tool
recommendations for version control, documentation, or testing.

[The source for this project is available here][src].

The metadata for a Python project is defined in the `pyproject.toml` file,
an example of which is included in this project. You should edit this file
accordingly to adapt this sample project to your needs.

----

This is the README file for the project.

The file should use UTF-8 encoding and can be written using
[reStructuredText][rst] or [markdown][md use] with the appropriate [key set][md
use]. It will be used to generate the project webpage on PyPI and will be
displayed as the project homepage on common code-hosting services, and should be
written for that purpose.

Typical contents for this file would include an overview of the project, basic
usage examples, etc. Generally, including the project changelog in here is not a
good idea, although a simple “What's New” section for the most recent version
may be appropriate.

[packaging guide]: https://packaging.python.org
[distribution tutorial]: https://packaging.python.org/tutorials/packaging-projects/
[src]: https://github.com/pypa/sampleproject
[rst]: http://docutils.sourceforge.net/rst.html
[md]: https://tools.ietf.org/html/rfc7764#section-3.5 "CommonMark variant"
[md use]: https://packaging.python.org/specifications/core-metadata/#description-content-type-optional


%prep
%autosetup -p1 -n sampleproject-%{version}

%build
%pyproject_wheel

%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}

%files %{python_files}
%{python_sitelib}/sampleproject
%{python_sitelib}/sampleproject-%{version}.dist-info

%changelog
21 changes: 12 additions & 9 deletions test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import os
import os.path
import pwd
import sys
import unittest

import pytest

Expand All @@ -32,8 +30,8 @@ class Args(object):
run = False
template = ''
filename = ''
name = 'py2pack'
version = '0.8.5'
name = ''
version = ''
source_url = None


Expand All @@ -49,16 +47,22 @@ class Args(object):
('opensuse.dsc', False),
('opensuse.spec', False),
('opensuse.spec', True)])
def test_template(tmpdir, template, fetch_tarball):
@pytest.mark.parametrize('project, version',
[('py2pack', '0.8.5'), # legacy setup.py sdist without pyproject.toml
('sampleproject', '3.0.0')]) # PEP517 only sdist without setup.py
def test_template(tmpdir, template, fetch_tarball, project, version):
""" Test if generated specfile equals to stored one. """
if (template, fetch_tarball, sys.version_info[:2]) == ('opensuse.spec', True, (3, 6)):
raise unittest.SkipTest('This combination of tests fails ATM.')
args = Args()
args.template = template
base, ext = template.split(".")
suffix = '-augmented' if fetch_tarball else ''
filename = "{}{}.{}".format(base, suffix, ext)
filename = f"{base}{suffix}.{ext}"
args.filename = filename
args.name = project
args.version = version
reference = os.path.join(compare_dir, f'{args.name}-{filename}')
if not os.path.exists(reference):
pytest.xfail("No reference template available")
with tmpdir.as_cwd():
if fetch_tarball:
py2pack.fetch(args)
Expand All @@ -68,7 +72,6 @@ def test_template(tmpdir, template, fetch_tarball):
py2pack.generate(args)
with open(filename) as filehandle:
written_spec = filehandle.read()
reference = os.path.join(compare_dir, 'py2pack-{}'.format(filename))
with open(reference) as filehandle:
required = filehandle.read()
required = required.replace('__USER__', username, 1)
Expand Down

0 comments on commit ec88b82

Please sign in to comment.