setup.py 2.68 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
2
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
Yanghan Wang's avatar
Yanghan Wang committed
3
import glob
facebook-github-bot's avatar
facebook-github-bot committed
4
5
6
import io
import os
import shutil
Yanghan Wang's avatar
Yanghan Wang committed
7
import subprocess
facebook-github-bot's avatar
facebook-github-bot committed
8
9
10
11
12
13
14
from os import path
from typing import List

from setuptools import setup, find_packages

cwd = os.path.dirname(os.path.abspath(__file__))

Yanghan Wang's avatar
Yanghan Wang committed
15
version = "0.0.1"
facebook-github-bot's avatar
facebook-github-bot committed
16
try:
Yanghan Wang's avatar
Yanghan Wang committed
17
    if not os.getenv("RELEASE"):
facebook-github-bot's avatar
facebook-github-bot committed
18
        from datetime import date
Yanghan Wang's avatar
Yanghan Wang committed
19

facebook-github-bot's avatar
facebook-github-bot committed
20
21
22
23
24
25
26
        today = date.today()
        day = today.strftime("b%Y%m%d")
        version += day
except Exception:
    pass

requirements = [
Yanghan Wang's avatar
Yanghan Wang committed
27
28
29
30
31
32
33
34
    "importlib",
    "numpy",
    "Pillow",
    "mock",
    "torch",
    "pytorch_lightning",
    "opencv-python",
    "parameterized",
facebook-github-bot's avatar
facebook-github-bot committed
35
36
]

Yanghan Wang's avatar
Yanghan Wang committed
37

facebook-github-bot's avatar
facebook-github-bot committed
38
39
40
41
42
43
def d2go_gather_files(dst_module, file_path, extension="*") -> List[str]:
    """
    Return a list of files to include in d2go submodule. Copy over the corresponding files.
    """
    # Use absolute paths while symlinking.
    source_configs_dir = path.join(path.dirname(path.realpath(__file__)), file_path)
Yanghan Wang's avatar
Yanghan Wang committed
44
    destination = path.join(path.dirname(path.realpath(__file__)), "d2go", dst_module)
facebook-github-bot's avatar
facebook-github-bot committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    # Symlink the config directory inside package to have a cleaner pip install.

    # Remove stale symlink/directory from a previous build.
    if path.exists(source_configs_dir):
        if path.islink(destination):
            os.unlink(destination)
        elif path.isdir(destination):
            shutil.rmtree(destination)

    if not path.exists(destination):
        try:
            os.symlink(source_configs_dir, destination)
        except OSError:
            # Fall back to copying if symlink fails: ex. on Windows.
            shutil.copytree(source_configs_dir, destination)

    config_paths = glob.glob(os.path.join(file_path + extension), recursive=True)
    return config_paths

Yanghan Wang's avatar
Yanghan Wang committed
64
65

if __name__ == "__main__":
facebook-github-bot's avatar
facebook-github-bot committed
66
67
68
69
70
71
    setup(
        name="d2go",
        version=version,
        author="Mobile Vision",
        url="https://github.com/facebookresearch/d2go",
        description="D2Go",
Yanghan Wang's avatar
Yanghan Wang committed
72
73
74
        long_description=open("README.md").read(),
        long_description_content_type="text/markdown",
        license="Apache-2.0",
facebook-github-bot's avatar
facebook-github-bot committed
75
76
        install_requires=requirements,
        packages=find_packages(exclude=["tools", "tests"]),
Yanghan Wang's avatar
Yanghan Wang committed
77
78
79
        package_data={
            "d2go": [
                "LICENSE",
facebook-github-bot's avatar
facebook-github-bot committed
80
            ],
81
            "d2go.configs": d2go_gather_files("configs", "configs", "**/*.yaml"),
facebook-github-bot's avatar
facebook-github-bot committed
82
            "d2go.tools": d2go_gather_files("tools", "tools", "**/*.py"),
83
            "d2go.tests": d2go_gather_files("tests", "tests", "**/*helper.py"),
facebook-github-bot's avatar
facebook-github-bot committed
84
85
        },
        entry_points={
Yanghan Wang's avatar
Yanghan Wang committed
86
87
88
            "console_scripts": [
                "d2go.exporter = d2go.tools.exporter:cli",
                "d2go.train_net = d2go.tools.train_net:cli",
facebook-github-bot's avatar
facebook-github-bot committed
89
90
91
            ]
        },
    )