Skip to content

Commit

Permalink
Merge pull request #160 from yan12125/add_setup
Browse files Browse the repository at this point in the history
Allow lilac to be installed as a system package
  • Loading branch information
lilydjwg authored Jul 23, 2020
2 parents a82caea + d30cc38 commit 107835f
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ __pycache__/
*.sw*
.pytest_cache/
config.ini

# Distribution / packaging
build/
dist/
.eggs/
sdist/
*.egg-info/
19 changes: 16 additions & 3 deletions lilac
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ from toposort import toposort_flatten
import structlog

topdir = Path(__file__).resolve().parent
sys.path.append(str(topdir))
sys.path.append(str(topdir / 'vendor'))
if (topdir / 'lilac2').exists():
# In-tree
sys.path.append(str(topdir))
sys.path.append(str(topdir / 'lilac2' / 'vendor'))
else:
# Installed as a system package
import lilac2
sys.path.append(str(Path(lilac2.__file__).parent / 'vendor'))

from myutils import at_dir, execution_timeout, lock_file
from serializer import PickledData
Expand Down Expand Up @@ -53,7 +59,14 @@ BIND_MOUNTS = [

config = configparser.ConfigParser()
config.optionxform = lambda option: option # type: ignore
config.read(topdir / 'config.ini')
config_file_candidates = [mydir / 'config.ini', topdir / 'config.ini']
for config_file in config_file_candidates:
# ConfigParser.read does not raise an exception is the file is missing
if config_file.exists():
config.read(config_file)
break
else:
raise Exception('No config files found!')

# Setting up enviroment variables
os.environ.update(config.items('enviroment variables'))
Expand Down
1 change: 1 addition & 0 deletions lilac2/vendor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# dummy file to make setuptools recognize lilac2.vendor
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
from setuptools import find_packages, setup

setup(
name = 'archlinuxcn-lilac',
use_scm_version = True,
description = 'The build bot for archlinuxcn',
author = 'lilydjwg',
author_email = 'lilydjwg@gmail.com',
python_requires = '>=3.7.0',
url = 'https://github.com/archlinuxcn/lilac',
packages = find_packages(exclude=('tests',)),
py_modules = ['lilaclib'],
scripts = ['lilac', 'recv_gpg_keys'],
setup_requires = ['setuptools_scm'],
# See README.md
install_requires = [
'requests', 'lxml', 'toposort', 'PyYAML', 'pyalpm', 'structlog', 'python_prctl',
],
include_package_data = True,
package_data = {
'lilac2': ['aliases.yaml'],
},
classifiers = [
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# sys.path does not support `Path`s yet
this_dir = pathlib.Path(__file__).resolve()
sys.path.insert(0, str(this_dir.parents[1]))
sys.path.insert(0, str(this_dir.parents[1] / 'pylib'))
sys.path.insert(0, str(this_dir.parents[1] / 'lilac2' / 'vendor'))

0 comments on commit 107835f

Please sign in to comment.