-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 365a4ba
Showing
5 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Build and Publish | ||
|
||
# Controls when the action will run. | ||
on: | ||
# Triggers the workflow on push to the master branch | ||
# push: | ||
# branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
Build_and_Publish: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
|
||
# Sets up python3 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
# Installs and upgrades pip, installs other dependencies and installs the package from setup.py | ||
- name: "Setup python dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install setuptools wheel twine build | ||
- name: Build package | ||
run: | | ||
python -m build | ||
- name: Get Package version | ||
if: always() | ||
id: app-version | ||
run: echo ::set-output name=current-version::$(python setup.py --version) | ||
|
||
- name: Release to Github | ||
if: always() | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
artifacts: "dist/*" | ||
allowUpdates: true | ||
tag: ${{ steps.app-version.outputs.current-version}} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
replacesArtifacts: true | ||
artifactErrorsFailBuild: true | ||
|
||
# # even if pypi upload fails upload to github release | ||
# - name: Publish to PyPI register | ||
# run: | ||
# python3 -m twine upload dist/* | ||
# continue-on-error: true | ||
# env: | ||
# TWINE_USERNAME: __token__ | ||
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mfig.egg-info | ||
build | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## | ||
|
||
|
||
1. __Installation__ | ||
Download and install the package from the latest [release section](https://github.com/Koushikphy/mfig/releases/latest) or directly install it using | ||
``` | ||
pip install https://github.com/Koushikphy/kfutils/releases/download/0.1.0/kfutils-0.1.0.tar.gz | ||
``` | ||
|
||
1. __Usage__ | ||
Run the installed `mfig` utility to use this tool. Description of different arguments, can also be checked with `mfig -h` option. | ||
|
||
|
||
| Argument | Description| | ||
| ----------- | ----------- | ||
| `-i` | List of input figures | | ||
| `-o` | Output file name | | ||
| `-it` | Position of the subfigure index, possible values are: <br> `b` (bottom), `t` (top-right corner), `n` (no index) | | ||
| `-ir` | Number of figures in one row | | ||
| `-w` | Width of each figures. | | ||
| `-v` | Verticle space between each rows | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env python | ||
|
||
from subprocess import call | ||
import shutil,os,argparse,sys | ||
|
||
|
||
# How it works: | ||
# 1. Create a tex document with necessary configurations | ||
# 2. Compile the tex to create the pdf | ||
# 3. Trim the pdf margins to get only the figure | ||
|
||
class CustomParser(argparse.ArgumentParser): | ||
|
||
def error(self, message): | ||
sys.stderr.write('\033[91mError: %s\n\033[0m' % message) | ||
self.print_help() | ||
sys.exit(2) | ||
|
||
|
||
|
||
def createParser(): | ||
#main parser | ||
parser = CustomParser(prog="onefig",formatter_class=argparse.RawTextHelpFormatter, | ||
description="A tool merging multiple figure in one.") | ||
|
||
#adding options for numerical jobs | ||
parser.add_argument("--ifile",'-i',nargs='+',type=str,help="Input files",metavar="FILE",required=True) | ||
parser.add_argument('--ofile','-o',type=str,required=True,help="Output file name",metavar="FILE") | ||
parser.add_argument('--per_row','-pr',help="Number of figure in one row (default: %(default)s)",metavar='IR',default=2,type=int) | ||
parser.add_argument('--index-type','-it',nargs='?',choices=['b','t','n'],default='b',help="Where to put the caption (default: %(default)s)",metavar='IT') | ||
parser.add_argument('--width','-w',help="Width of each figure (default: %(default)s)",default=0.46,metavar='WIDTH',type=float) | ||
parser.add_argument('--vspace','-v',help="Verticle space between rows in cm (default: %(default)s)",default=0.3,metavar='WIDTH',type=float) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = createParser() | ||
createPdf(args) | ||
|
||
|
||
def createPdf(args): | ||
destDir = 'tmp_pdfmerger' | ||
os.makedirs(destDir,exist_ok=True) | ||
|
||
for file in args.ifile: | ||
shutil.copy(file, destDir) | ||
|
||
os.chdir(destDir) | ||
tex = createTeX(args) | ||
# print(tex) | ||
with open('test.tex','w') as f: | ||
|
||
f.write(tex) | ||
|
||
with open('tmp.log','a') as f: | ||
ret = call(['pdflatex','test.tex'],stdout=f) | ||
|
||
call(['pdfcrop','test.pdf','../{}'.format(args.ofile)],stdout=f) | ||
|
||
os.chdir('../') | ||
shutil.rmtree(destDir) | ||
|
||
|
||
|
||
|
||
def createTeX(args): | ||
figType={ | ||
'b':r'\subfloat[]', | ||
't':r'\sidesubfloat[]', | ||
'n':r'\subfloat' | ||
} | ||
thisFig = figType[args.index_type] | ||
inOneRow=args.per_row | ||
fig = '' | ||
assert (1.0/inOneRow)>args.width, "Width {} is too large to fit {} figure in one row".format(args.width,inOneRow) | ||
|
||
for ind,elem in enumerate(args.ifile,start=1): | ||
fig += thisFig+r'{\includegraphics[width=\imsize]{'+elem+'}}' | ||
fig += r'\\\vspace{'+str(args.vspace)+'cm}' if not ind%inOneRow else r"\hfill" | ||
fig +='\n' | ||
|
||
figWidth = r"\newcommand{\imsize}{"+str(args.width)+r"\textwidth}" | ||
return r''' | ||
\documentclass[a4,12pt]{article} | ||
\usepackage[a4paper,margin=0in]{geometry} | ||
\usepackage{subfig} | ||
\usepackage{graphicx} | ||
\usepackage{multirow} | ||
\usepackage{floatrow} | ||
\thispagestyle{empty} | ||
%\graphicspath{{../}} | ||
\captionsetup[subfigure]{justification=raggedright,farskip=12pt,captionskip=12pt,position=auto,labelfont=bf} | ||
\floatsetup[figure]{style=plain,subcapbesideposition=top} | ||
'''+figWidth+r''' | ||
\begin{document} | ||
\begin{figure}[!htp] | ||
\centering | ||
'''+fig+r'''\end{figure}\end{document}''' | ||
|
||
|
||
if __name__ =="__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from setuptools import setup, find_packages | ||
|
||
with open('Readme.md') as f: | ||
txt = f.read() | ||
|
||
setup(name='mfig', | ||
version='0.1.0', | ||
description='A common file operation utility', | ||
long_description=txt, | ||
author='Koushik Naskar', | ||
author_email='koushik.naskar9@gmail.com', | ||
license="MIT", | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Environment :: Console', 'Intended Audience :: Science/Research', | ||
'Natural Language :: English', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
'Topic :: System :: Shells' | ||
], | ||
keywords='File Operations', | ||
project_urls={'Source Code': 'https://github.com/Koushikphy/kutils'}, | ||
zip_safe=True, | ||
python_requires='>=2.7', | ||
packages=find_packages(), | ||
entry_points={ | ||
'console_scripts': [ | ||
'mfig = mfig.mfig:main', | ||
], | ||
}) |