Skip to content

Commit 7ac1f5d

Browse files
tulinkryVladimir Kotal
authored andcommitted
Packaging python scripts (#2389)
fixes #2251
1 parent ea32765 commit 7ac1f5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+690
-278
lines changed

dev/before_install

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
44
sudo apt-get update -qq
5-
sudo apt-get install -qq cvs git mercurial cssc bzr subversion monotone rcs rcs-blame python3 python3-pip pep8 nodejs;
5+
sudo apt-get install -qq cvs git mercurial cssc bzr subversion monotone rcs rcs-blame python3 python3-venv python3-pip pep8 nodejs;
66
sudo ./dev/install-bitkeeper.sh
77
sudo pip3 install --upgrade pip
88
sudo pip3 install flake8
99
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
1010
brew update
1111
brew install ctags cvs node
1212
brew upgrade python
13-
pip3 install pep8 flake8
13+
pip3 install pep8 flake8 virtualenv
1414
fi
1515

1616
sudo ./dev/install-universal_ctags.sh

distribution/assembly.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<outputDirectory>lib</outputDirectory>
2020
<destName>source.war</destName>
2121
</file>
22+
<file>
23+
<source>${project.basedir}/../opengrok-tools/dist/opengrok-tools-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier}.tar.gz</source>
24+
<outputDirectory>tools</outputDirectory>
25+
<destName>opengrok-tools.tar.gz</destName>
26+
</file>
2227
</files>
2328
<fileSets>
2429
<fileSet>
@@ -39,13 +44,6 @@
3944
<include>opengrok.1</include>
4045
</includes>
4146
</fileSet>
42-
<fileSet>
43-
<directory>${project.basedir}/../tools/src/main/python</directory>
44-
<outputDirectory>bin</outputDirectory>
45-
<includes>
46-
<include>*.py</include>
47-
</includes>
48-
</fileSet>
4947
<fileSet>
5048
<directory>${project.build.directory}/../lib</directory>
5149
<outputDirectory>lib/lib</outputDirectory>

distribution/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
<dependency>
3838
<groupId>org.opengrok</groupId>
39-
<artifactId>tools</artifactId>
39+
<artifactId>opengrok-tools</artifactId>
4040
<version>1.1-rc58</version>
4141
<type>pom</type>
4242
</dependency>
@@ -64,6 +64,19 @@
6464
</execution>
6565
</executions>
6666
</plugin>
67+
<plugin>
68+
<groupId>org.codehaus.mojo</groupId>
69+
<artifactId>build-helper-maven-plugin</artifactId>
70+
<version>3.0.0</version>
71+
<executions>
72+
<execution>
73+
<id>parse-version</id>
74+
<goals>
75+
<goal>parse-version</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
6780
<plugin>
6881
<groupId>org.codehaus.mojo</groupId>
6982
<artifactId>exec-maven-plugin</artifactId>

opengrok-tools/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
env
2+
build
3+
dist
4+
opengrok_tools.egg-info

opengrok-tools/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include src/main/python/README.md

opengrok-tools/pom.xml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
CDDL HEADER START
5+
6+
The contents of this file are subject to the terms of the
7+
Common Development and Distribution License (the "License").
8+
You may not use this file except in compliance with the License.
9+
10+
See LICENSE.txt included in this distribution for the specific
11+
language governing permissions and limitations under the License.
12+
13+
When distributing Covered Code, include this CDDL HEADER in each
14+
file and include the License file at LICENSE.txt.
15+
If applicable, add the following below this CDDL HEADER, with the
16+
fields enclosed by brackets "[]" replaced with your own identifying
17+
information: Portions Copyright [yyyy] [name of copyright owner]
18+
19+
CDDL HEADER END
20+
21+
Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
22+
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
23+
24+
-->
25+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<groupId>org.opengrok</groupId>
31+
<artifactId>opengrok-top</artifactId>
32+
<version>1.1-rc58</version>
33+
</parent>
34+
35+
<artifactId>opengrok-tools</artifactId>
36+
<version>1.1-rc58</version>
37+
<packaging>pom</packaging>
38+
39+
<name>OpenGrok tools</name>
40+
41+
<build>
42+
<sourceDirectory>src/main/python</sourceDirectory>
43+
<testSourceDirectory>src/test/python</testSourceDirectory>
44+
45+
<plugins>
46+
<plugin>
47+
<groupId>org.codehaus.mojo</groupId>
48+
<artifactId>exec-maven-plugin</artifactId>
49+
<version>1.6.0</version>
50+
<executions>
51+
<execution>
52+
<configuration>
53+
<executable>flake8</executable>
54+
<arguments>
55+
<argument>-v</argument>
56+
<argument>--exclude=filelock.py,test_command.py,test_commands.py</argument>
57+
<argument>${project.build.sourceDirectory}</argument>
58+
<argument>setup.py</argument>
59+
</arguments>
60+
</configuration>
61+
<phase>verify</phase>
62+
<goals>
63+
<goal>exec</goal>
64+
</goals>
65+
</execution>
66+
<execution>
67+
<id>generate python env</id>
68+
<configuration>
69+
<executable>python3</executable>
70+
<workingDirectory>${project.build.directory}/../</workingDirectory>
71+
<arguments>
72+
<argument>-m</argument>
73+
<argument>venv</argument>
74+
<argument>env</argument>
75+
</arguments>
76+
</configuration>
77+
<phase>test</phase>
78+
<goals>
79+
<goal>exec</goal>
80+
</goals>
81+
</execution>
82+
<execution>
83+
<id>generate-package</id>
84+
<goals>
85+
<goal>exec</goal>
86+
</goals>
87+
<configuration>
88+
<executable>env/bin/python</executable>
89+
<workingDirectory>${project.build.directory}/../</workingDirectory>
90+
<arguments>
91+
<argument>setup.py</argument>
92+
<argument>sdist</argument>
93+
</arguments>
94+
</configuration>
95+
<phase>package</phase>
96+
</execution>
97+
<execution>
98+
<id>pre-python-test</id>
99+
<configuration>
100+
<executable>env/bin/python</executable>
101+
<workingDirectory>${project.build.directory}/../</workingDirectory>
102+
<arguments>
103+
<argument>setup.py</argument>
104+
<argument>install</argument>
105+
</arguments>
106+
</configuration>
107+
<phase>test</phase>
108+
<goals>
109+
<goal>exec</goal>
110+
</goals>
111+
</execution>
112+
<execution>
113+
<id>python-test</id>
114+
<configuration>
115+
<executable>env/bin/python</executable>
116+
<workingDirectory>${project.build.directory}/../</workingDirectory>
117+
<arguments>
118+
<argument>setup.py</argument>
119+
<argument>test</argument>
120+
</arguments>
121+
</configuration>
122+
<phase>test</phase>
123+
<goals>
124+
<goal>exec</goal>
125+
</goals>
126+
</execution>
127+
</executions>
128+
129+
</plugin>
130+
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-checkstyle-plugin</artifactId>
134+
</plugin>
135+
136+
</plugins>
137+
</build>
138+
139+
</project>

opengrok-tools/setup.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import unittest
3+
from setuptools import setup
4+
5+
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
6+
7+
8+
def readme():
9+
with open(os.path.join(SCRIPT_DIR, 'src', 'main', 'python', 'README.md'),
10+
'r') as readme:
11+
return readme.read()
12+
13+
14+
def my_test_suite():
15+
test_loader = unittest.TestLoader()
16+
test_suite = test_loader.discover(
17+
os.path.join(SCRIPT_DIR, 'src', 'test', 'python'), pattern='test_*.py')
18+
return test_suite
19+
20+
21+
setup(
22+
name='opengrok-tools',
23+
version='1.1rc58',
24+
packages=[
25+
'opengrok_tools',
26+
'all',
27+
'all.utils',
28+
'all.scm',
29+
],
30+
package_dir={
31+
'opengrok_tools': 'src/main/python/opengrok_tools',
32+
'all': 'src/main/python/opengrok_tools/all',
33+
'all.scm': 'src/main/python/opengrok_tools/all/scm',
34+
'all.utils': 'src/main/python/opengrok_tools/all/utils',
35+
},
36+
url='https://github.com/OpenGrok/OpenGrok',
37+
license='CDDL',
38+
author='Oracle',
39+
author_email='[email protected]',
40+
description='Tools for managing OpenGrok instance',
41+
long_description=readme(),
42+
test_suite='setup.my_test_suite',
43+
install_requires=[
44+
'jsonschema==2.6.0',
45+
'pyyaml',
46+
'requests',
47+
'resource'
48+
],
49+
entry_points={
50+
'console_scripts': [
51+
'opengrok-config-merge=opengrok_tools.config_merge:main',
52+
'opengrok-deploy=opengrok_tools.deploy:main',
53+
'opengrok-groups=opengrok_tools.groups:main',
54+
'opengrok=opengrok_tools.indexer:main',
55+
'opengrok-indexer=opengrok_tools.indexer:main',
56+
'opengrok-java=opengrok_tools.java:main',
57+
'opengrok-mirror=opengrok_tools.mirror:main',
58+
'opengrok-projadm=opengrok_tools.projadm:main',
59+
'opengrok-reindex-project=opengrok_tools.reindex_project:main',
60+
'opengrok-sync=opengrok_tools.sync:main',
61+
]
62+
},
63+
)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
# OpenGrok tools
3+
4+
Set of scripts to facilitate project synchronization and mirroring
5+
6+
The scripts require Python 3 and they rely on a binary/symlink `python3` to be
7+
present that points to the latest Python 3.x version present on the system.
8+
9+
See https://github.com/oracle/opengrok/wiki/Repository-synchronization
10+
for more details.
11+
12+
# Content
13+
14+
This is a list of the binaries in this package.
15+
16+
```text
17+
opengrok-config-merge
18+
opengrok-deploy
19+
opengrok-groups
20+
opengrok
21+
opengrok-indexer
22+
opengrok-java
23+
opengrok-mirror
24+
opengrok-projadm
25+
opengrok-reindex-project
26+
opengrok-sync
27+
```
28+
29+
# Development
30+
31+
## Environment
32+
33+
Prepare a virtual environment
34+
35+
```bash
36+
python3 -m venv env
37+
. env/bin/activate
38+
```
39+
40+
Install development dependencies
41+
42+
```bash
43+
python -m pip install -r requirements.txt
44+
```
45+
46+
## Developing
47+
48+
Start developing, making changes in files. Test your changes with usual python commands.
49+
50+
```bash
51+
python src/main/python/opengrok_tools/groups.py
52+
python src/main/python/opengrok_tools/sync.py
53+
```
54+
55+
## Installation
56+
57+
Test installing your package into the local environment
58+
59+
```bash
60+
python setup.py install
61+
# now you can try console scripts
62+
opengrok-groups
63+
opengrok-sync
64+
```
65+
66+
or make a distribution tarball.
67+
68+
```bash
69+
python setup.py sdist
70+
ls -l dist/
71+
```
72+
73+
### Installation on the target system
74+
75+
Use the distribution tarball and run `pip`.
76+
77+
```bash
78+
python3 -m pip install opengrok_tools-{version}.tar.gz
79+
```
80+
81+
This will download all dependencies and install the package to your local python3 modules.
82+
You can use console scripts to run the package binaries.
83+
84+
#### Uninstalling
85+
86+
```bash
87+
python3 -m pip uninstall opengrok_tools
88+
```
89+
90+
## Testing
91+
92+
```bash
93+
python setup.py install test
94+
mvn test
95+
```
96+
97+
## Cleanup
98+
99+
Deactivate the virtual environment
100+
```bash
101+
deactivate
102+
# optionally
103+
# rm -r env
104+
```
105+

opengrok-tools/src/main/python/opengrok_tools/__init__.py

Whitespace-only changes.

opengrok-tools/src/main/python/opengrok_tools/all/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)