Skip to content

Commit

Permalink
Add clean command (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqtg committed Dec 4, 2023
1 parent b25ceb4 commit e9d5b7f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/source/api_ref/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Fmeasure (F1)
.. autoclass:: FMeasure

Hit Ratio (HitRatio)
-------------------
--------------------
.. autoclass:: HitRatio

Mean Average Precision (MAP)
Expand Down
3 changes: 2 additions & 1 deletion docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Clone your forked repository to your local machine using the following command:

.. code-block:: bash
git clone https://github.com/PreferredAI/cornac.git
git clone https://github.com/your-github-id/cornac.git
Create a New Branch
^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -40,6 +40,7 @@ are working as expected.

.. code-block:: bash
python3 setup.py clean
python3 setup.py install
Expand Down
2 changes: 1 addition & 1 deletion docs/source/developer/gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Setting Up Your Development Environment

.. code-block:: bash
git clone https://github.com/PreferredAI/cornac.git
git clone https://github.com/your-github-id/cornac.git
cd cornac
python -m venv venv
source venv/bin/activate # On Windows, use 'venv\Scripts\activate'
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy
scipy
Cython
tqdm
powerlaw
51 changes: 43 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import os
import sys
import glob
from setuptools import Extension, setup, find_packages
import shutil
from setuptools import Extension, Command, setup, find_packages

try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy as np
import scipy
Expand Down Expand Up @@ -95,8 +95,11 @@ def extract_gcc_binaries():
os.environ["CC"] = gcc
os.environ["CXX"] = gcc
else:
if not os.path.exists("/usr/bin/g++"):
print(
"No GCC available. Install gcc from Homebrew using brew install gcc."
)
USE_OPENMP = False
print("No GCC available. Install gcc from Homebrew using brew install gcc.")
# required arguments for default gcc of OSX
compile_args.extend(["-O2", "-stdlib=libc++", "-mmacosx-version-min=10.7"])
link_args.extend(["-O2", "-stdlib=libc++", "-mmacosx-version-min=10.7"])
Expand Down Expand Up @@ -287,11 +290,43 @@ def extract_gcc_binaries():
)
]

cmdclass = {}

# cythonize c++ modules
extensions = cythonize(extensions)
cmdclass.update({"build_ext": build_ext})
class CleanCommand(Command):
description = "Remove build artifacts from the source tree"

user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
# Remove .cpp and .so files for a clean build
if os.path.exists("build"):
shutil.rmtree("build")
for dirpath, dirnames, filenames in os.walk("cornac"):
for filename in filenames:
root, extension = os.path.splitext(filename)

if extension in [".so", ".pyd", ".dll", ".pyc"]:
os.unlink(os.path.join(dirpath, filename))

if extension in [".c", ".cpp"]:
pyx_file = str.replace(filename, extension, ".pyx")
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))

for dirname in dirnames:
if dirname == "__pycache__":
shutil.rmtree(os.path.join(dirpath, dirname))


cmdclass = {
"clean": CleanCommand,
"build_ext": build_ext,
}

setup(
name="cornac",
Expand All @@ -308,7 +343,7 @@ def extract_gcc_binaries():
"recommendation",
],
ext_modules=extensions,
install_requires=["numpy", "scipy", "tqdm>=4.19", "powerlaw"],
install_requires=["numpy", "scipy", "tqdm", "powerlaw"],
extras_require={"tests": ["pytest", "pytest-pep8", "pytest-xdist", "pytest-cov"]},
cmdclass=cmdclass,
packages=find_packages(),
Expand Down

0 comments on commit e9d5b7f

Please sign in to comment.