-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update newdoc: Fix the optional formatting and drop Python2 #30
Changes from all commits
90df072
e376360
05b9d45
6cef5c1
e8656b1
3bb6737
e2da106
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.4.3-1 newdoc/ | ||
1.5.1-1 newdoc/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
%global srcname newdoc | ||
|
||
Name: python-%{srcname} | ||
Version: 1.4.3 | ||
Release: 1%{?dist} | ||
Version: 1.5.1 | ||
Release: 1 | ||
Summary: A script to generate assembly and module AsciiDoc files from templates | ||
|
||
License: GPLv3+ | ||
URL: https://pypi.python.org/pypi/%{srcname} | ||
Source0: %pypi_source | ||
|
||
BuildArch: noarch | ||
BuildRequires: python2-devel python3-devel | ||
BuildRequires: python3-devel | ||
|
||
%description | ||
A script to generate assembly and module AsciiDoc files from templates | ||
|
||
%package -n python2-%{srcname} | ||
Summary: %{summary} | ||
%{?python_provide:%python_provide python2-%{srcname}} | ||
|
||
%description -n python2-%{srcname} | ||
A script to generate assembly and module AsciiDoc files from templates | ||
|
||
|
||
%package -n python3-%{srcname} | ||
Summary: %{summary} | ||
%{?python_provide:%python_provide python3-%{srcname}} | ||
|
@@ -35,35 +27,33 @@ A script to generate assembly and module AsciiDoc files from templates | |
%autosetup -n %{srcname}-%{version} | ||
|
||
%build | ||
%py2_build | ||
%py3_build | ||
|
||
%install | ||
# Must do the python2 install first because the scripts in /usr/bin are | ||
# overwritten with every setup.py install, and in general we want the | ||
# python3 version to be the default. | ||
# If, however, we're installing separate executables for python2 and python3, | ||
# the order needs to be reversed so the unversioned executable is the python2 one. | ||
%py2_install | ||
%py3_install | ||
|
||
%check | ||
%{__python2} setup.py test | ||
%{__python3} setup.py test | ||
|
||
# Note that there is no %%files section for the unversioned python module if we are building for several python runtimes | ||
%files -n python2-%{srcname} | ||
%license LICENSE | ||
%doc README.rst | ||
%{python2_sitelib}/* | ||
|
||
%files -n python3-%{srcname} | ||
%license LICENSE | ||
%doc README.rst | ||
%{python3_sitelib}/* | ||
%{_bindir}/newdoc | ||
|
||
%changelog | ||
* Fri Sep 25 2020 Marek Suchánek <[email protected]> 1.5.1-1 | ||
- Announce the deprecation of this version and the migration to the new one | ||
([email protected]) | ||
|
||
* Tue Jun 23 2020 Marek Suchánek <[email protected]> 1.5.0-1 | ||
- Remove the remaining Python 2 code ([email protected]) | ||
- Align the Optional formatting with the IBM Style Guide; #29 | ||
([email protected]) | ||
- Remove Python 2 packaging ([email protected]) | ||
- Update outdated version information ([email protected]) | ||
- Clarify newdoc install instructions ([email protected]) | ||
|
||
* Mon Oct 07 2019 Marek Suchánek <[email protected]> 1.4.3-1 | ||
- Fix a reference to the renamed readme in the RPM spec ([email protected]) | ||
- Updated the changelog ([email protected]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,11 @@ | |
import argparse | ||
from string import Template | ||
|
||
NEWDOC_VERSION = "1.3.2" | ||
|
||
# Record whether we're running under Python 2 or 3 | ||
PYVERSION = sys.version_info.major | ||
NEWDOC_VERSION = "1.5.1" | ||
DEPRECATION = "DEPRECATED:\nThis version of `newdoc` is now deprecated and will no longer receive any significant updates.\nPlease uninstall this version and migrate to the current version:\nhttps://github.com/redhat-documentation/newdoc" | ||
|
||
# The configparser module is called ConfigParser in Python2 | ||
if PYVERSION == 2: | ||
import ConfigParser as cp | ||
else: | ||
import configparser as cp | ||
|
||
# Force Python 2 to use the UTF-8 encoding. Otherwise, loading a template | ||
# containing Unicode characters fails. | ||
if PYVERSION == 2: | ||
reload(sys) | ||
sys.setdefaultencoding('utf8') | ||
import configparser as cp | ||
|
||
# The directory where the script is located | ||
SCRIPT_HOME_DIR = os.path.dirname(__file__) | ||
|
@@ -92,7 +81,7 @@ def get_config(): | |
|
||
for k in options.keys(): | ||
# The configparser library is different in Python 2 and 3. | ||
# This si the only 2/3-compatible way I've found for optional keys. | ||
# This is the only 2/3-compatible way I've found for optional keys. | ||
try: | ||
options[k] = config.get("newdoc", k) | ||
except cp.NoOptionError: | ||
Comment on lines
82
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you want to somehow resolve this too? The comment seems to indicate you could do this "better". But then again, the code already works, so it does not matter much. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right. It could be improved, but there's no reason to do it since the current code works. |
||
|
@@ -204,12 +193,6 @@ def write_file(out_file, module_content): | |
performing necessary checks | ||
""" | ||
|
||
# In Python 2, the `input` function is called `raw_input` | ||
if PYVERSION == 2: | ||
compatible_input = raw_input | ||
else: | ||
compatible_input = input | ||
|
||
# Check if the file exists; abort if so | ||
if os.path.exists(out_file): | ||
print('File already exists: "{}"'.format(out_file)) | ||
|
@@ -218,7 +201,7 @@ def write_file(out_file, module_content): | |
decision = None | ||
|
||
while not decision: | ||
response = compatible_input("Overwrite it? [yes/no] ").lower() | ||
response = input("Overwrite it? [yes/no] ").lower() | ||
|
||
if response in ["yes", "y"]: | ||
print("Overwriting.") | ||
|
@@ -232,13 +215,8 @@ def write_file(out_file, module_content): | |
# Write the file | ||
with open(out_file, "w") as f: | ||
f.write(module_content) | ||
# In Python 2, the UTF-8 encoding has to be specified explicitly | ||
if PYVERSION == 2: | ||
with io.open(out_file, mode="w", encoding="utf-8") as f: | ||
f.write(module_content) | ||
else: | ||
with open(out_file, "w") as f: | ||
f.write(module_content) | ||
with open(out_file, "w") as f: | ||
f.write(module_content) | ||
|
||
print("File successfully generated.") | ||
print("To include this file from an assembly, use:") | ||
|
@@ -271,13 +249,8 @@ def create_module(title, doc_type, options, delete_comments): | |
print("Error: Template file not found: '{}'".format(template_file)) | ||
exit(1) | ||
|
||
# In Python 2, the UTF-8 encoding has to be specified explicitly | ||
if PYVERSION == 2: | ||
with io.open(template_file, mode="r", encoding="utf-8") as f: | ||
template = f.read() | ||
else: | ||
with open(template_file, "r") as f: | ||
template = f.read() | ||
with open(template_file, "r") as f: | ||
template = f.read() | ||
|
||
# Prepare the content of the new module | ||
module_content = Template(template).substitute(module_title=title, | ||
|
@@ -296,6 +269,8 @@ def main(): | |
""" | ||
Main, executable procedure of the script | ||
""" | ||
print(DEPRECATION, "\n") | ||
|
||
# Build a command-line options parser | ||
parser = argparse.ArgumentParser() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
setuptools.setup( | ||
name="newdoc", | ||
version="1.4.3", | ||
version="1.5.1", | ||
license="GPLv3+", | ||
author="Marek Suchánek", | ||
author_email="[email protected]", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of the changes, but you could easily import the three things instead of the module, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean
ConfigParser
,MissingSectionHeaderError
, andNoOptionError
? Sure, importing them directly could somewhat optimize the performance if I called the objects in a loop. But since they aren't in a performance-sensitive place, I prefer to keep the namespace to make it clear where the objects come from.