From 13a0b2cfe97d43e0cc4f81bb1751e20e18a975e1 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Mon, 8 Apr 2024 15:04:14 +0100 Subject: [PATCH] Convert structuring_projects packager example to use pyproject.toml --- .../example_project/{README.rst => README.md} | 3 +- .../example_project/mypackage/mymodule.py | 14 ++++++ .../example_project/pyproject.toml | 34 ++++++++++++++ .../example_project/requirements.txt | 1 - .../example_project/setup.py | 44 ------------------- 5 files changed, 49 insertions(+), 47 deletions(-) rename advanced_programming/structuring_projects/example_project/{README.rst => README.md} (75%) create mode 100644 advanced_programming/structuring_projects/example_project/pyproject.toml delete mode 100644 advanced_programming/structuring_projects/example_project/requirements.txt delete mode 100644 advanced_programming/structuring_projects/example_project/setup.py diff --git a/advanced_programming/structuring_projects/example_project/README.rst b/advanced_programming/structuring_projects/example_project/README.md similarity index 75% rename from advanced_programming/structuring_projects/example_project/README.rst rename to advanced_programming/structuring_projects/example_project/README.md index f4aa13f..acacbd1 100644 --- a/advanced_programming/structuring_projects/example_project/README.rst +++ b/advanced_programming/structuring_projects/example_project/README.md @@ -1,5 +1,4 @@ -Example project -=============== +# Example project This is an example project, used to demonstrate the basics of how to structure diff --git a/advanced_programming/structuring_projects/example_project/mypackage/mymodule.py b/advanced_programming/structuring_projects/example_project/mypackage/mymodule.py index 51f9c9c..3e9ece4 100644 --- a/advanced_programming/structuring_projects/example_project/mypackage/mymodule.py +++ b/advanced_programming/structuring_projects/example_project/mypackage/mymodule.py @@ -1,5 +1,19 @@ #!/usr/bin/env python +import sys + + def myfunction(a, b): return a * b + + +def main(): + if len(sys.argv) != 3: + print(f'Usage: myscript a b') + sys.exit(1) + + a = float(sys.argv[1]) + b = float(sys.argv[2]) + + print(myfunction(a, b)) diff --git a/advanced_programming/structuring_projects/example_project/pyproject.toml b/advanced_programming/structuring_projects/example_project/pyproject.toml new file mode 100644 index 0000000..c062ed9 --- /dev/null +++ b/advanced_programming/structuring_projects/example_project/pyproject.toml @@ -0,0 +1,34 @@ +[project] +name = "example-project" +dynamic = ["version"] +description = "Example Python project for PyTreat" +readme = {file = "README.md", content-type="text/markdown"} +license = {text = "Apache License Version 2.0"} +requires-python = ">=3.8" +authors = [{name = "Paul McCarthy", email = "pauldmccarthy@gmail.com"}] +dependencies = [ + "numpy", + "nibabel", + "scipy" +] + +[project.urls] +Repository = "https://git.fmrib.ox.ac.uk/fsl/win-pytreat/" + +# The "mypackage.mymodule.main" function is installed +# as a command-line program called "myscript". +[project.scripts] +myscript = "mypackage.mymodule:main" + +# Use setuptools to build this package +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +# Specify which Python packages to include +[tool.setuptools.packages.find] +include = ["mypackage*"] + +# The version number is inside mypackage/__init__.py +[tool.setuptools.dynamic] +version = {attr = "mypackage.__version__"} \ No newline at end of file diff --git a/advanced_programming/structuring_projects/example_project/requirements.txt b/advanced_programming/structuring_projects/example_project/requirements.txt deleted file mode 100644 index bd704f9..0000000 --- a/advanced_programming/structuring_projects/example_project/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -numpy==1.* diff --git a/advanced_programming/structuring_projects/example_project/setup.py b/advanced_programming/structuring_projects/example_project/setup.py deleted file mode 100644 index a7fc149..0000000 --- a/advanced_programming/structuring_projects/example_project/setup.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python - -from setuptools import setup -from setuptools import find_packages - -# Import version number from -# the project package (see -# the section on versioning). -from mypackage import __version__ - -# Read in requirements from -# the requirements.txt file. -with open('requirements.txt', 'rt') as f: - requirements = [l.strip() for l in f.readlines()] - -# Generate a list of all of the -# packages that are in your project. -packages = find_packages() - -setup( - - name='Example project', - description='Example Python project for PyTreat', - url='https://git.fmrib.ox.ac.uk/fsl/pytreat-practicals-2020/', - author='Paul McCarthy', - author_email='pauldmccarthy@gmail.com', - license='Apache License Version 2.0', - - packages=packages, - - version=__version__, - - install_requires=requirements, - - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Topic :: Software Development :: Libraries :: Python Modules'], -) -- GitLab