From 7be64b938d7828feadf56ff778cb2fe6ac32b632 Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Wed, 1 Dec 2021 18:07:01 +0100 Subject: [PATCH 1/8] first steps towards build --- pyproject.toml | 6 ++++++ setup.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..374b58cb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 6682137c..d26924cd 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import sys import glob import warnings -from setuptools import setup, Extension +from setuptools import setup, Extension, find_packages file_required = "requirements.txt" @@ -23,6 +23,7 @@ else: dir_files[dir_] = [file_] data_files = [] +dir_files["."] = [file_required] for (key, value) in dir_files.items(): data_files += [(os.path.join('MulensModel', key), value)] @@ -43,15 +44,20 @@ setup( name='MulensModel', version=version, - url='git@github.com:rpoleski/MulensModel.git', + url='https://github.com/rpoleski/MulensModel', + project_urls={ + 'git clone': 'git@github.com:rpoleski/MulensModel.git', + 'documentation': 'https://github.com/rpoleski/MulensModel'}, ext_modules=[ext_AC, ext_VBBL], author='Radek Poleski', author_email='radek.poleski@gmail.com', description='package for modeling gravitational microlensing events', packages=['MulensModel', 'MulensModel.mulensobjects'], +# This also should work: packages=find_packages(where="source"), package_dir={ 'MulensModel': source_MM, 'MulensModel.mulensobjects': source_MMmo}, data_files=data_files, - install_requires=required + install_requires=required, + python_requires=">=3.6", ) From 2cf0fcec8a4556a07e050e47eb9287191c8e5ce0 Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Sun, 5 Dec 2021 14:45:00 +0100 Subject: [PATCH 2/8] tips on Extensions from Keto Zhang --- setup.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index d26924cd..e00982f1 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,9 @@ source_MM = os.path.join('source', 'MulensModel') source_MMmo = os.path.join(source_MM, 'mulensobjects') +source_VBBL_abs = os.path.abspath(source_VBBL) +source_AC_abs = os.path.abspath(source_AC) + # Read all files from data/ in format adequate for data_files option of setup. files = glob.glob(os.path.join("data", "**", "*"), recursive=True) files = [f for f in files if os.path.isfile(f)] @@ -33,10 +36,10 @@ if line_.startswith('__version__'): version = line_.split()[2][1:-1] -ext_AC = Extension('MulensModel.AdaptiveContouring', - sources=glob.glob(os.path.join(source_AC, "*.c"))) -ext_VBBL = Extension('MulensModel.VBBL', - sources=glob.glob(os.path.join(source_VBBL, "*.cpp"))) +ext_AC = Extension('MulensModel.AdaptiveContouring', libraries=["m"], + sources=glob.glob(os.path.join(source_AC_abs, "*.c"))) +ext_VBBL = Extension('MulensModel.VBBL', libraries=["m"], + sources=glob.glob(os.path.join(source_VBBL_abs, "*.cpp"))) with open(file_required) as file_: required = file_.read().splitlines() @@ -53,7 +56,7 @@ author_email='radek.poleski@gmail.com', description='package for modeling gravitational microlensing events', packages=['MulensModel', 'MulensModel.mulensobjects'], -# This also should work: packages=find_packages(where="source"), + # This also should work: packages=find_packages(where="source"), package_dir={ 'MulensModel': source_MM, 'MulensModel.mulensobjects': source_MMmo}, From 104b40b269e8a27f22875c0c1c2ad0b1a77342ed Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Mon, 6 Dec 2021 19:40:48 +0100 Subject: [PATCH 3/8] adding more files and some cleanup in setup.py --- setup.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index e00982f1..4671ea39 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,11 @@ file_required = "requirements.txt" -source_VBBL = os.path.join('source', 'VBBL') -source_AC = os.path.join('source', 'AdaptiveContouring') +source_VBBL_abs = os.path.abspath(os.path.join('source', 'VBBL')) +source_AC_abs = os.path.abspath(os.path.join('source', 'AdaptiveContouring')) source_MM = os.path.join('source', 'MulensModel') source_MMmo = os.path.join(source_MM, 'mulensobjects') -source_VBBL_abs = os.path.abspath(source_VBBL) -source_AC_abs = os.path.abspath(source_AC) - # Read all files from data/ in format adequate for data_files option of setup. files = glob.glob(os.path.join("data", "**", "*"), recursive=True) files = [f for f in files if os.path.isfile(f)] @@ -25,22 +22,30 @@ dir_files[dir_] += [file_] else: dir_files[dir_] = [file_] +dir_files["."] = [file_required, "README.md", "LICENSE"] +files_ = ["Horizons_manual.md", "examples_list.md", "papers_to_cite.md", + "magnification_methods.pdf", "parameter_names.pdf"] +dir_files["documents"] = [os.path.join("documents", f) for f in files_] +dir_files["examples"] = glob.glob(os.path.join("examples", "*.py")) +dir_ex_16 = os.path.join("examples", "example_16") +dir_ex_16_files = ["ulens_model_fit.py", "ulens_model_plot.py"] +dir_files[dir_ex_16] = [os.path.join(dir_ex_16, f) for f in dir_ex_16_files] data_files = [] -dir_files["."] = [file_required] for (key, value) in dir_files.items(): data_files += [(os.path.join('MulensModel', key), value)] +# Read ther version. version = "unknown" with open(os.path.join('source', 'MulensModel', 'version.py')) as in_put: for line_ in in_put.readlines(): if line_.startswith('__version__'): version = line_.split()[2][1:-1] +# Prepare extensions and required modules. ext_AC = Extension('MulensModel.AdaptiveContouring', libraries=["m"], sources=glob.glob(os.path.join(source_AC_abs, "*.c"))) ext_VBBL = Extension('MulensModel.VBBL', libraries=["m"], sources=glob.glob(os.path.join(source_VBBL_abs, "*.cpp"))) - with open(file_required) as file_: required = file_.read().splitlines() @@ -49,10 +54,10 @@ version=version, url='https://github.com/rpoleski/MulensModel', project_urls={ - 'git clone': 'git@github.com:rpoleski/MulensModel.git', +# 'git clone': 'git@github.com:rpoleski/MulensModel.git', 'documentation': 'https://github.com/rpoleski/MulensModel'}, ext_modules=[ext_AC, ext_VBBL], - author='Radek Poleski', + author='Radek Poleski & Jennifer Yee', author_email='radek.poleski@gmail.com', description='package for modeling gravitational microlensing events', packages=['MulensModel', 'MulensModel.mulensobjects'], From 8afa01bcb975ba51730ac6b557cf81b53218e865 Mon Sep 17 00:00:00 2001 From: "Keto D. Zhang" Date: Fri, 3 Dec 2021 17:44:11 -0800 Subject: [PATCH 4/8] Add absolute path to setup.py Add publish CI Add comments to CI --- .github/workflows/publish.yml | 33 ++++++++++++++++++ setup.py | 65 +++++++++++++++-------------------- 2 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..676f32cd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Upload Python Package to PyPI + +on: + release: + types: [published] + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build package + run: python setup.py sdist + + - name: Publish package to PyPI + # All files in dist/ are published + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/setup.py b/setup.py index d26924cd..71752e3a 100644 --- a/setup.py +++ b/setup.py @@ -1,45 +1,39 @@ -import os -import sys -import glob -import warnings -from setuptools import setup, Extension, find_packages +from pathlib import Path +from setuptools import Extension, find_packages, setup -file_required = "requirements.txt" +PROJECT_PATH = Path(__file__).resolve().parent +SOURCE_PATH = PROJECT_PATH / "source" +DATA_PATH = PROJECT_PATH / "data" -source_VBBL = os.path.join('source', 'VBBL') -source_AC = os.path.join('source', 'AdaptiveContouring') -source_MM = os.path.join('source', 'MulensModel') -source_MMmo = os.path.join(source_MM, 'mulensobjects') - -# Read all files from data/ in format adequate for data_files option of setup. -files = glob.glob(os.path.join("data", "**", "*"), recursive=True) -files = [f for f in files if os.path.isfile(f)] -dir_files = dict() -for file_ in files: - dir_ = os.path.dirname(file_) - if dir_ in dir_files: - dir_files[dir_] += [file_] - else: - dir_files[dir_] = [file_] -data_files = [] -dir_files["."] = [file_required] -for (key, value) in dir_files.items(): - data_files += [(os.path.join('MulensModel', key), value)] +file_required = PROJECT_PATH / "requirements.txt" +with file_required.open() as file_: + install_requires = file_.read().splitlines() version = "unknown" -with open(os.path.join('source', 'MulensModel', 'version.py')) as in_put: +with Path(SOURCE_PATH / "MulensModel" / "version.py").open() as in_put: for line_ in in_put.readlines(): if line_.startswith('__version__'): version = line_.split()[2][1:-1] +source_VBBL = SOURCE_PATH / "VBBL" +source_AC = SOURCE_PATH / "AdaptiveContouring" +source_MM = SOURCE_PATH / "MulensModel" +source_MMmo = source_MM / "mulensobjects" + +# Read all files from data/ in format adequate for data_files option of setup. +files = [f.relative_to(PROJECT_PATH) for f in DATA_PATH.rglob("*") if f.is_file()] +data_files = {str(f): str(f) for f in files} + +# C/C++ Extensions ext_AC = Extension('MulensModel.AdaptiveContouring', - sources=glob.glob(os.path.join(source_AC, "*.c"))) + sources=[str(f) for f in source_AC.glob("*.c")], + libraries=["m"] + ) ext_VBBL = Extension('MulensModel.VBBL', - sources=glob.glob(os.path.join(source_VBBL, "*.cpp"))) - -with open(file_required) as file_: - required = file_.read().splitlines() + sources=[str(f) for f in source_AC.glob("*.cpp")], + libraries=["m"] + ) setup( name='MulensModel', @@ -52,12 +46,9 @@ author='Radek Poleski', author_email='radek.poleski@gmail.com', description='package for modeling gravitational microlensing events', - packages=['MulensModel', 'MulensModel.mulensobjects'], -# This also should work: packages=find_packages(where="source"), - package_dir={ - 'MulensModel': source_MM, - 'MulensModel.mulensobjects': source_MMmo}, + packages=find_packages(where="source"), + package_dir={"": "source"}, data_files=data_files, - install_requires=required, python_requires=">=3.6", + install_requires=install_requires, ) From 1b82fed1a213bd5f1546064ff87b736255e2cc1e Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Mon, 3 Jan 2022 18:09:14 +0100 Subject: [PATCH 5/8] updating version for new release --- source/MulensModel/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index 1fde5cdb..9f71d69c 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.1.15" +__version__ = "2.1.15-dev" From 5ae6e322671c72096f6e9d718f3ca67f081bc366 Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Mon, 3 Jan 2022 22:05:10 +0100 Subject: [PATCH 6/8] copying changes by Keto Zhang --- .github/workflows/publish.yml | 33 ++++++++++++++ setup.py | 81 ++++++++++++++--------------------- 2 files changed, 65 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..676f32cd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Upload Python Package to PyPI + +on: + release: + types: [published] + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.9" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Build package + run: python setup.py sdist + + - name: Publish package to PyPI + # All files in dist/ are published + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/setup.py b/setup.py index 4671ea39..71752e3a 100644 --- a/setup.py +++ b/setup.py @@ -1,71 +1,54 @@ -import os -import sys -import glob -import warnings -from setuptools import setup, Extension, find_packages +from pathlib import Path +from setuptools import Extension, find_packages, setup -file_required = "requirements.txt" +PROJECT_PATH = Path(__file__).resolve().parent +SOURCE_PATH = PROJECT_PATH / "source" +DATA_PATH = PROJECT_PATH / "data" -source_VBBL_abs = os.path.abspath(os.path.join('source', 'VBBL')) -source_AC_abs = os.path.abspath(os.path.join('source', 'AdaptiveContouring')) -source_MM = os.path.join('source', 'MulensModel') -source_MMmo = os.path.join(source_MM, 'mulensobjects') +file_required = PROJECT_PATH / "requirements.txt" +with file_required.open() as file_: + install_requires = file_.read().splitlines() -# Read all files from data/ in format adequate for data_files option of setup. -files = glob.glob(os.path.join("data", "**", "*"), recursive=True) -files = [f for f in files if os.path.isfile(f)] -dir_files = dict() -for file_ in files: - dir_ = os.path.dirname(file_) - if dir_ in dir_files: - dir_files[dir_] += [file_] - else: - dir_files[dir_] = [file_] -dir_files["."] = [file_required, "README.md", "LICENSE"] -files_ = ["Horizons_manual.md", "examples_list.md", "papers_to_cite.md", - "magnification_methods.pdf", "parameter_names.pdf"] -dir_files["documents"] = [os.path.join("documents", f) for f in files_] -dir_files["examples"] = glob.glob(os.path.join("examples", "*.py")) -dir_ex_16 = os.path.join("examples", "example_16") -dir_ex_16_files = ["ulens_model_fit.py", "ulens_model_plot.py"] -dir_files[dir_ex_16] = [os.path.join(dir_ex_16, f) for f in dir_ex_16_files] -data_files = [] -for (key, value) in dir_files.items(): - data_files += [(os.path.join('MulensModel', key), value)] - -# Read ther version. version = "unknown" -with open(os.path.join('source', 'MulensModel', 'version.py')) as in_put: +with Path(SOURCE_PATH / "MulensModel" / "version.py").open() as in_put: for line_ in in_put.readlines(): if line_.startswith('__version__'): version = line_.split()[2][1:-1] -# Prepare extensions and required modules. -ext_AC = Extension('MulensModel.AdaptiveContouring', libraries=["m"], - sources=glob.glob(os.path.join(source_AC_abs, "*.c"))) -ext_VBBL = Extension('MulensModel.VBBL', libraries=["m"], - sources=glob.glob(os.path.join(source_VBBL_abs, "*.cpp"))) -with open(file_required) as file_: - required = file_.read().splitlines() +source_VBBL = SOURCE_PATH / "VBBL" +source_AC = SOURCE_PATH / "AdaptiveContouring" +source_MM = SOURCE_PATH / "MulensModel" +source_MMmo = source_MM / "mulensobjects" + +# Read all files from data/ in format adequate for data_files option of setup. +files = [f.relative_to(PROJECT_PATH) for f in DATA_PATH.rglob("*") if f.is_file()] +data_files = {str(f): str(f) for f in files} + +# C/C++ Extensions +ext_AC = Extension('MulensModel.AdaptiveContouring', + sources=[str(f) for f in source_AC.glob("*.c")], + libraries=["m"] + ) +ext_VBBL = Extension('MulensModel.VBBL', + sources=[str(f) for f in source_AC.glob("*.cpp")], + libraries=["m"] + ) setup( name='MulensModel', version=version, url='https://github.com/rpoleski/MulensModel', project_urls={ -# 'git clone': 'git@github.com:rpoleski/MulensModel.git', + 'git clone': 'git@github.com:rpoleski/MulensModel.git', 'documentation': 'https://github.com/rpoleski/MulensModel'}, ext_modules=[ext_AC, ext_VBBL], - author='Radek Poleski & Jennifer Yee', + author='Radek Poleski', author_email='radek.poleski@gmail.com', description='package for modeling gravitational microlensing events', - packages=['MulensModel', 'MulensModel.mulensobjects'], - # This also should work: packages=find_packages(where="source"), - package_dir={ - 'MulensModel': source_MM, - 'MulensModel.mulensobjects': source_MMmo}, + packages=find_packages(where="source"), + package_dir={"": "source"}, data_files=data_files, - install_requires=required, python_requires=">=3.6", + install_requires=install_requires, ) From 5a47a19b6fac2dacfb4296ee4f934658acca79dc Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Mon, 3 Jan 2022 22:05:51 +0100 Subject: [PATCH 7/8] version update --- source/MulensModel/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index 9f71d69c..3fe52ac1 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.1.15-dev" +__version__ = "2.1.15-dev2" From 6575d5ee28d4921edca2a26a8a9bc11f2e884cf0 Mon Sep 17 00:00:00 2001 From: Radek Poleski Date: Sun, 9 Jan 2022 21:52:07 +0100 Subject: [PATCH 8/8] correcting setup.py --- setup.py | 1 - source/MulensModel/version.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 71752e3a..cbc69280 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,6 @@ version=version, url='https://github.com/rpoleski/MulensModel', project_urls={ - 'git clone': 'git@github.com:rpoleski/MulensModel.git', 'documentation': 'https://github.com/rpoleski/MulensModel'}, ext_modules=[ext_AC, ext_VBBL], author='Radek Poleski', diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index 3fe52ac1..24a34899 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.1.15-dev2" +__version__ = "2.1.15-dev3"