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 f4aa13fff46ccf0cd5cf594d52f03d8935578556..acacbd1c034bb316c11094fc6580545ad459994c 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 51f9c9c19d3645b1c724685a2fd7b03a7f5299cd..3e9ece4bbad7a94fc898800f0c80e948247ed75e 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 0000000000000000000000000000000000000000..c062ed983f12cf832722dbe5144a5f10b6972d29 --- /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 bd704f9e2078c145d4767e21bd454c744d4da38e..0000000000000000000000000000000000000000 --- 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 a7fc149d8b1d32ae11807fdf61fb99dfa01d4c88..0000000000000000000000000000000000000000 --- 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'], -)